Skip to content

Commit

Permalink
add tests on tender admin submission
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Jan 24, 2024
1 parent bbb8aa0 commit e8c90f1
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion lemarche/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,9 @@ def setUp(cls):
perimeters=[cls.perimeter_paris],
status=tender_constants.STATUS_PUBLISHED,
published_at=timezone.now(),
validated_at=None,
)
cls.form_data = model_to_dict(cls.tender) | {
"_continue": "Enregistrer et continuer les modifications",
"amount": "",
"why_amount_is_blank": "DONT_WANT_TO_SHARE",
"location": cls.perimeter_paris.pk,
Expand All @@ -847,6 +847,25 @@ def setUp(cls):
if value is None:
cls.form_data[key] = ""

def test_edit_form_no_matching_on_simple_submission(self):
self.client.force_login(self.user)
tender_update_post_url = get_admin_change_view_url(self.tender)
self.assertEqual(self.tender.tendersiae_set.count(), 0)
# create post request to update the model
response = self.client.post(
tender_update_post_url,
self.form_data
| {
"title": "New title",
"_continue": "Enregistrer et continuer les modifications",
},
follow=True,
)
tender_response = response.context_data["adminform"].form.instance
self.assertEqual(tender_response.id, self.tender.id)
self.assertTrue(hasattr(tender_response, "siae_count_annotated"))
self.assertEqual(tender_response.siae_count_annotated, 0)

def test_edit_form_matching_on_submission(self):
self.client.force_login(self.user)
tender_update_post_url = get_admin_change_view_url(self.tender)
Expand All @@ -857,6 +876,7 @@ def test_edit_form_matching_on_submission(self):
self.form_data
| {
"title": "New title",
"_calculate_tender": "Sauvegarder et chercher les structures correspondantes",
},
follow=True,
)
Expand All @@ -872,6 +892,7 @@ def test_edit_form_matching_on_submission(self):
| {
"title": "New title",
"sectors": [sector.id for sector in self.sectors[1:3]],
"_calculate_tender": "Sauvegarder et chercher les structures correspondantes",
},
follow=True,
)
Expand All @@ -884,10 +905,53 @@ def test_edit_form_matching_on_submission(self):
self.form_data
| {
"sectors": [sector.id for sector in self.sectors[7:8]],
"_calculate_tender": "Sauvegarder et chercher les structures correspondantes",
},
follow=True,
)
tender_response = response.context_data["adminform"].form.instance
self.assertEqual(tender_response.siae_count_annotated, 1)
tender_siae_matched_2 = tender_response.tendersiae_set.first() # only one siae
self.assertNotEqual(tender_siae_matched.pk, tender_siae_matched_2.pk)

def test_edit_form_no_matching_on_validate_submission(self):
self.client.force_login(self.user)
tender_update_post_url = get_admin_change_view_url(self.tender)
self.assertEqual(self.tender.tendersiae_set.count(), 0)
# create post request to update the model
response = self.client.post(
tender_update_post_url,
self.form_data
| {
"title": "New title",
"_calculate_tender": "Sauvegarder et chercher les structures correspondantes",
},
follow=True,
)
tender_response = response.context_data["adminform"].form.instance
self.assertEqual(tender_response.id, self.tender.id)
self.assertNotContains(response, "Validé le ")
self.assertTrue(hasattr(tender_response, "siae_count_annotated"))
self.assertEqual(tender_response.siae_count_annotated, 2)
self.assertEqual(tender_response.siae_count_annotated, self.tender.tendersiae_set.count())

# delete for moderation per example
TenderSiae.objects.first().delete()
self.assertEqual(self.tender.tendersiae_set.count(), 1)

# validation does not match again and keep moderation
response = self.client.post(
tender_update_post_url,
self.form_data
| {
"title": "New title",
"_validate_tender": "Valider (sauvegarder) et envoyer aux structures",
},
follow=True,
)
tender_response = response.context_data["adminform"].form.instance
self.assertEqual(tender_response.id, self.tender.id)
self.assertContains(response, "Validé le ")
self.assertTrue(hasattr(tender_response, "siae_count_annotated"))
self.assertEqual(tender_response.siae_count_annotated, 1)
self.assertEqual(tender_response.siae_count_annotated, self.tender.tendersiae_set.count())

0 comments on commit e8c90f1

Please sign in to comment.