Skip to content

Commit

Permalink
Survey transaction: update TenderSiae.transactioned field
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Mar 21, 2024
1 parent 666513f commit 362d08a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
58 changes: 37 additions & 21 deletions lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1845,61 +1845,68 @@ def test_only_tender_author_with_sesame_token_can_call_tender_survey_transaction
# full form displayed (but should never happen)

def test_update_tender_stats_on_tender_survey_transactioned_answer_true(self):
self.assertIsNone(Tender.objects.get(id=self.tender.id).survey_transactioned_answer)
self.assertIsNone(Tender.objects.get(id=self.tender.id).siae_transactioned)
self.assertIsNone(Tender.objects.get(id=self.tender.id).siae_transactioned_source)
self.assertIsNone(Tender.objects.get(id=self.tender.id).siae_transactioned_last_updated)
t = Tender.objects.get(id=self.tender.id)
self.assertIsNone(t.survey_transactioned_answer)
self.assertIsNone(t.siae_transactioned)
self.assertIsNone(t.siae_transactioned_source)
self.assertIsNone(t.siae_transactioned_last_updated)
# load with answer 'True': partial form
url = self.url + self.user_buyer_1_sesame_query_string + "&answer=True"
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)
self.assertTrue(Tender.objects.get(id=self.tender.id).survey_transactioned_answer)
self.assertTrue(Tender.objects.get(id=self.tender.id).siae_transactioned)
t = Tender.objects.get(id=self.tender.id)
self.assertTrue(t.survey_transactioned_answer)
self.assertTrue(t.siae_transactioned)
self.assertEqual(
Tender.objects.get(id=self.tender.id).siae_transactioned_source,
t.siae_transactioned_source,
tender_constants.TENDER_SIAE_TRANSACTIONED_SOURCE_AUTHOR,
)
self.assertIsNotNone(Tender.objects.get(id=self.tender.id).siae_transactioned_last_updated)
self.assertIsNotNone(t.siae_transactioned_last_updated)
# fill in form
response = self.client.post(
url, data={"survey_transactioned_amount": 1000, "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.assertTrue(Tender.objects.get(id=self.tender.id).survey_transactioned_answer)
self.assertEqual(Tender.objects.get(id=self.tender.id).survey_transactioned_amount, 1000)
self.assertTrue(t.survey_transactioned_answer)
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"
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(Tender.objects.get(id=self.tender.id).survey_transactioned_answer)
self.assertTrue(Tender.objects.get(id=self.tender.id).siae_transactioned)
self.assertTrue(t.survey_transactioned_answer)
self.assertTrue(t.siae_transactioned)

def test_update_tender_stats_on_tender_survey_transactioned_answer_false(self):
# load with answer 'False': partial form
url = self.url + self.user_buyer_1_sesame_query_string + "&answer=False"
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)
self.assertFalse(Tender.objects.get(id=self.tender.id).survey_transactioned_answer)
self.assertFalse(Tender.objects.get(id=self.tender.id).siae_transactioned)
t = Tender.objects.get(id=self.tender.id)
self.assertFalse(t.survey_transactioned_answer)
self.assertFalse(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.assertFalse(Tender.objects.get(id=self.tender.id).survey_transactioned_answer)
self.assertIsNone(Tender.objects.get(id=self.tender.id).survey_transactioned_amount)
self.assertFalse(t.survey_transactioned_answer)
self.assertIsNone(t.survey_transactioned_amount)
# reload with answer, ignore changes
url = self.url + self.user_buyer_1_sesame_query_string + "&answer=True"
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(Tender.objects.get(id=self.tender.id).survey_transactioned_answer)
self.assertFalse(Tender.objects.get(id=self.tender.id).siae_transactioned)
self.assertFalse(t.survey_transactioned_answer)
self.assertFalse(t.siae_transactioned)


class TenderDetailSiaeSurveyTransactionedViewTest(TestCase):
Expand Down Expand Up @@ -1948,6 +1955,8 @@ def test_only_tender_author_with_sesame_token_can_call_tender_siae_survey_transa
def test_update_tender_stats_on_tender_siae_survey_transactioned_answer_true(self):
ts = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertIsNone(ts.survey_transactioned_answer)
self.assertIsNone(ts.transactioned)
self.assertIsNone(ts.transactioned_source)
self.assertIsNone(ts.tender.siae_transactioned)
self.assertIsNone(ts.tender.siae_transactioned_source)
self.assertIsNone(ts.tender.siae_transactioned_last_updated)
Expand All @@ -1957,6 +1966,11 @@ def test_update_tender_stats_on_tender_siae_survey_transactioned_answer_true(sel
self.assertEqual(response.status_code, 200)
ts = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertTrue(ts.survey_transactioned_answer)
self.assertTrue(ts.transactioned)
self.assertEqual(
ts.transactioned_source,
tender_constants.TENDER_SIAE_TRANSACTIONED_SOURCE_SIAE,
)
self.assertTrue(ts.tender.siae_transactioned)
self.assertEqual(ts.tender.siae_transactioned_source, tender_constants.TENDER_SIAE_TRANSACTIONED_SOURCE_SIAE)
self.assertIsNotNone(ts.tender.siae_transactioned_last_updated)
Expand All @@ -1965,17 +1979,19 @@ def test_update_tender_stats_on_tender_siae_survey_transactioned_answer_true(sel
url, data={"survey_transactioned_amount": 1000, "survey_transactioned_feedback": "Feedback"}, follow=True
)
self.assertEqual(response.status_code, 200) # redirect
ts = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertRedirects(response, reverse("tenders:detail", kwargs={"slug": self.tender.slug}))
self.assertContains(response, "Merci pour votre réponse")
self.assertTrue(TenderSiae.objects.get(tender=self.tender, siae=self.siae).survey_transactioned_answer)
self.assertEqual(TenderSiae.objects.get(tender=self.tender, siae=self.siae).survey_transactioned_amount, 1000)
self.assertTrue(ts.survey_transactioned_answer)
self.assertEqual(ts.survey_transactioned_amount, 1000)
# reload with answer, ignore changes and redirect
url = self.url + self.user_siae_1_sesame_query_string + "&answer=False"
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200) # redirect
ts = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
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(TenderSiae.objects.get(tender=self.tender, siae=self.siae).survey_transactioned_answer)
self.assertTrue(ts.survey_transactioned_answer)

def test_update_tender_stats_on_tender_siae_survey_transactioned_answer_false(self):
# load with answer 'False': partial form
Expand Down
4 changes: 4 additions & 0 deletions lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,10 @@ def get(self, request, *args, **kwargs):
# update tendersiae
self.object.survey_transactioned_answer = survey_transactioned_answer
self.object.survey_transactioned_answer_date = timezone.now()
if self.object.survey_transactioned_answer:
if self.object.tender.siae_transactioned is None:
self.object.transactioned = survey_transactioned_answer
self.object.transactioned_source = tender_constants.TENDER_SIAE_TRANSACTIONED_SOURCE_SIAE
self.object.save()
# update tender if True
if self.object.survey_transactioned_answer:
Expand Down

0 comments on commit 362d08a

Please sign in to comment.