Skip to content

Commit

Permalink
Set this value automatically in the views
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Mar 11, 2024
1 parent 2d3252f commit e16506a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
16 changes: 15 additions & 1 deletion lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1789,13 +1789,18 @@ def test_only_tender_author_with_sesame_token_can_call_tender_survey_transaction
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)
# 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)
self.assertEqual(
Tender.objects.get(id=self.tender.id).siae_transactioned_source,
tender_constants.TENDER_SIAE_TRANSACTIONED_SOURCE_AUTHOR,
)
self.assertIsNotNone(Tender.objects.get(id=self.tender.id).siae_transactioned_last_updated)
# fill in form
response = self.client.post(
Expand Down Expand Up @@ -1883,11 +1888,20 @@ def test_only_tender_author_with_sesame_token_can_call_tender_siae_survey_transa
# full form displayed (but should never happen)

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.tender.siae_transactioned)
self.assertIsNone(ts.tender.siae_transactioned_source)
self.assertIsNone(ts.tender.siae_transactioned_last_updated)
# load with answer 'True': partial form
url = self.url + self.user_siae_1_sesame_query_string + "&answer=True"
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)
self.assertTrue(TenderSiae.objects.get(tender=self.tender, siae=self.siae).survey_transactioned_answer)
ts = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertTrue(ts.survey_transactioned_answer)
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)
# fill in form
response = self.client.post(
url, data={"survey_transactioned_amount": 1000, "survey_transactioned_feedback": "Feedback"}, follow=True
Expand Down
13 changes: 11 additions & 2 deletions lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,9 @@ def get(self, request, *args, **kwargs):
# update tender
self.object.survey_transactioned_answer = survey_transactioned_answer
self.object.survey_transactioned_answer_date = timezone.now()
self.object.siae_transactioned = survey_transactioned_answer
if self.object.siae_transactioned is None:
self.object.siae_transactioned = survey_transactioned_answer
self.object.siae_transactioned_source = tender_constants.TENDER_SIAE_TRANSACTIONED_SOURCE_AUTHOR
self.object.save()
else:
pass
Expand Down Expand Up @@ -685,10 +687,17 @@ def get(self, request, *args, **kwargs):
if survey_transactioned_answer in ["True", "False"]:
# transform survey_transactioned_answer into bool
survey_transactioned_answer = survey_transactioned_answer == "True"
# update tender
# update tendersiae
self.object.survey_transactioned_answer = survey_transactioned_answer
self.object.survey_transactioned_answer_date = timezone.now()
self.object.save()
# update tender
if self.object.tender.siae_transactioned is None:
self.object.tender.siae_transactioned = survey_transactioned_answer
self.object.tender.siae_transactioned_source = (
tender_constants.TENDER_SIAE_TRANSACTIONED_SOURCE_SIAE
)
self.object.tender.save()
else:
pass
# TODO or not? "answer" should always be passed
Expand Down

0 comments on commit e16506a

Please sign in to comment.