Skip to content

Commit

Permalink
Allow updating survey answer
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Apr 8, 2024
1 parent 9536c7a commit 945d0f5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
44 changes: 32 additions & 12 deletions lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,12 +1884,11 @@ def test_update_tender_stats_on_tender_survey_transactioned_answer_true(self):
self.assertIsNone(t.siae_transactioned)
self.assertIsNone(t.siae_transactioned_source)
self.assertIsNone(t.siae_transactioned_last_updated)
# load with answer 'True': partial form
# load with answer True: partial form
url = f"{self.url}{self.user_buyer_1_sesame_query_string}&answer={constants.YES}"
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)
t = Tender.objects.get(id=self.tender.id)
# self.assertTrue(t.survey_transactioned_answer)
self.assertEqual(t.survey_transactioned_answer, constants.YES)
self.assertTrue(t.siae_transactioned)
self.assertEqual(
Expand All @@ -1905,27 +1904,24 @@ def test_update_tender_stats_on_tender_survey_transactioned_answer_true(self):
t = Tender.objects.get(id=self.tender.id)
self.assertRedirects(response, reverse("tenders:detail", kwargs={"slug": self.tender.slug}))
self.assertContains(response, "Merci pour votre réponse")
# self.assertTrue(t.survey_transactioned_answer)
self.assertEqual(t.survey_transactioned_answer, constants.YES)
self.assertEqual(t.survey_transactioned_amount, 1000)
# reload with answer, ignore changes and redirect
url = self.url + self.user_buyer_1_sesame_query_string + "&answer=False"
# reload with new answer, ignore changes and redirect
url = f"{self.url}{self.user_buyer_1_sesame_query_string}&answer={constants.NO}"
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200) # redirect
t = Tender.objects.get(id=self.tender.id)
self.assertRedirects(response, reverse("tenders:detail", kwargs={"slug": self.tender.slug}))
self.assertContains(response, "Votre réponse a déjà été prise en compte")
# self.assertTrue(t.survey_transactioned_answer)
self.assertEqual(t.survey_transactioned_answer, constants.YES)
self.assertTrue(t.siae_transactioned)

def test_update_tender_stats_on_tender_survey_transactioned_answer_false(self):
# load with answer 'False': partial form
# load with answer False: partial form
url = f"{self.url}{self.user_buyer_1_sesame_query_string}&answer={constants.NO}"
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)
t = Tender.objects.get(id=self.tender.id)
# self.assertFalse(t.survey_transactioned_answer)
self.assertEqual(t.survey_transactioned_answer, constants.NO)
self.assertFalse(t.siae_transactioned)
# fill in form
Expand All @@ -1934,20 +1930,44 @@ def test_update_tender_stats_on_tender_survey_transactioned_answer_false(self):
t = Tender.objects.get(id=self.tender.id)
self.assertRedirects(response, reverse("tenders:detail", kwargs={"slug": self.tender.slug}))
self.assertContains(response, "Merci pour votre réponse")
self.assertFalse(t.survey_transactioned_answer)
self.assertEqual(t.survey_transactioned_answer, constants.NO)
self.assertIsNone(t.survey_transactioned_amount)
# reload with answer, ignore changes
url = self.url + self.user_buyer_1_sesame_query_string + "&answer=True"
# reload with new answer, ignore changes
url = f"{self.url}{self.user_buyer_1_sesame_query_string}&answer={constants.YES}"
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200) # redirect
t = Tender.objects.get(id=self.tender.id)
self.assertRedirects(response, reverse("tenders:detail", kwargs={"slug": self.tender.slug}))
self.assertContains(response, "Votre réponse a déjà été prise en compte")
# self.assertFalse(t.survey_transactioned_answer)
self.assertEqual(t.survey_transactioned_answer, constants.NO)
self.assertFalse(t.siae_transactioned)

def test_update_tender_stats_on_tender_survey_transactioned_answer_dont_know(self):
# load with answer ?: partial form
url = f"{self.url}{self.user_buyer_1_sesame_query_string}&answer={constants.DONT_KNOW}"
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)
t = Tender.objects.get(id=self.tender.id)
self.assertEqual(t.survey_transactioned_answer, constants.DONT_KNOW)
self.assertIsNone(t.siae_transactioned)
# fill in form
response = self.client.post(url, data={"survey_transactioned_feedback": "Feedback"}, follow=True)
self.assertEqual(response.status_code, 200) # redirect
t = Tender.objects.get(id=self.tender.id)
self.assertRedirects(response, reverse("tenders:detail", kwargs={"slug": self.tender.slug}))
self.assertContains(response, "Merci pour votre réponse")
self.assertEqual(t.survey_transactioned_answer, constants.DONT_KNOW)
self.assertIsNone(t.survey_transactioned_amount)
# reload with new answer, update
url = f"{self.url}{self.user_buyer_1_sesame_query_string}&answer={constants.YES}"
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)
t = Tender.objects.get(id=self.tender.id)
self.assertRedirects(response, reverse("tenders:detail", kwargs={"slug": self.tender.slug}))
self.assertNotContains(response, "Votre réponse a déjà été prise en compte")
self.assertEqual(t.survey_transactioned_answer, constants.YES)
self.assertTrue(t.siae_transactioned)


class TenderDetailSiaeSurveyTransactionedViewTest(TestCase):
@classmethod
Expand Down
2 changes: 1 addition & 1 deletion lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def get(self, request, *args, **kwargs):
self.object = self.get_object()
survey_transactioned_answer = request.GET.get("answer", None)
# first time answering
if self.object.survey_transactioned_answer is None:
if self.object.survey_transactioned_answer in [None, constants.DONT_KNOW]:
if survey_transactioned_answer in tender_constants.SURVEY_TRANSACTIONED_ANSWER_CHOICE_LIST:
# update tender
self.object.survey_transactioned_answer = survey_transactioned_answer
Expand Down

0 comments on commit 945d0f5

Please sign in to comment.