Skip to content

Commit

Permalink
Move test
Browse files Browse the repository at this point in the history
  • Loading branch information
eadpearce committed Oct 25, 2024
1 parent 1d40a9e commit dec1438
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 108 deletions.
108 changes: 108 additions & 0 deletions quotas/tests/test_real_edits.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,111 @@ def test_quotas_workbasket_edit_create(client_with_current_workbasket, date_rang
.update_type
== UpdateType.CREATE
)


def test_quota_update_existing_origin_and_exclusions_remove(
client_with_current_workbasket,
date_ranges,
):
country1 = factories.CountryFactory.create()
country2 = factories.CountryFactory.create()
country3 = factories.CountryFactory.create()
geo_group = factories.GeoGroupFactory.create()
membership1 = factories.GeographicalMembershipFactory.create(
member=country1,
geo_group=geo_group,
)
membership2 = factories.GeographicalMembershipFactory.create(
member=country2,
geo_group=geo_group,
)

origin1 = factories.QuotaOrderNumberOriginFactory.create(geographical_area=country3)
quota = origin1.order_number

origin2 = factories.QuotaOrderNumberOriginFactory.create(
geographical_area=geo_group,
order_number=quota,
)
exclusion1 = factories.QuotaOrderNumberOriginExclusionFactory.create(
excluded_geographical_area=membership1.member,
origin=origin2,
)
exclusion2 = factories.QuotaOrderNumberOriginExclusionFactory.create(
excluded_geographical_area=membership2.member,
origin=origin2,
)

# sanity check
tx = Transaction.objects.last()
assert quota.quotaordernumberorigin_set.approved_up_to_transaction(tx).count() == 2
assert (
origin1.quotaordernumberoriginexclusion_set.approved_up_to_transaction(
tx,
).count()
== 0
)
assert (
origin2.quotaordernumberoriginexclusion_set.approved_up_to_transaction(
tx,
).count()
== 2
)

data = {
"start_date_0": quota.valid_between.lower.day,
"start_date_1": quota.valid_between.lower.month,
"start_date_2": quota.valid_between.lower.year,
"end_date_0": "",
"end_date_1": "",
"end_date_2": "",
"category": quota.category,
"origins-0-pk": origin1.pk,
"origins-0-start_date_0": origin1.valid_between.lower.day,
"origins-0-start_date_1": origin1.valid_between.lower.month,
"origins-0-start_date_2": origin1.valid_between.lower.year,
"origins-0-end_date_0": "",
"origins-0-end_date_1": "",
"origins-0-end_date_2": "",
"origins-0-geographical_area": origin1.geographical_area.pk,
# remove the second origin and its exclusion
"submit": "Save",
}

url = reverse("quota-ui-edit", kwargs={"sid": quota.sid})
response = client_with_current_workbasket.post(url, data)

assert response.status_code == 302
assert response.url == reverse("quota-ui-confirm-update", kwargs={"sid": quota.sid})

last_tx = Transaction.objects.last()

updated_quota = (
models.QuotaOrderNumber.objects.approved_up_to_transaction(last_tx)
.filter(sid=quota.sid)
.first()
)

assert updated_quota.origins.approved_up_to_transaction(last_tx).count() == 1
updated_origin = (
updated_quota.quotaordernumberorigin_set.approved_up_to_transaction(
last_tx,
).first()
)
assert (
updated_origin.quotaordernumberoriginexclusion_set.approved_up_to_transaction(
last_tx,
).count()
== 0
)
# update quota
# update origin 1 to link to updated quota
# delete quota origin 2
# delete both quota origin 2 exclusions
assert updated_origin.transaction.workbasket.tracked_models.count() == 5
assert sorted(
[
item.get_update_type_display()
for item in updated_origin.transaction.workbasket.tracked_models.all()
],
) == ["Delete", "Delete", "Delete", "Update", "Update"]
108 changes: 0 additions & 108 deletions quotas/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1905,114 +1905,6 @@ def test_quota_update_existing_origin_exclusion_remove(
) == ["Delete", "Delete", "Update", "Update"]


def test_quota_update_existing_origin_and_exclusions_remove(
client_with_current_workbasket,
date_ranges,
):
country1 = factories.CountryFactory.create()
country2 = factories.CountryFactory.create()
country3 = factories.CountryFactory.create()
geo_group = factories.GeoGroupFactory.create()
membership1 = factories.GeographicalMembershipFactory.create(
member=country1,
geo_group=geo_group,
)
membership2 = factories.GeographicalMembershipFactory.create(
member=country2,
geo_group=geo_group,
)

origin1 = factories.QuotaOrderNumberOriginFactory.create(geographical_area=country3)
quota = origin1.order_number

origin2 = factories.QuotaOrderNumberOriginFactory.create(
geographical_area=geo_group,
order_number=quota,
)
exclusion1 = factories.QuotaOrderNumberOriginExclusionFactory.create(
excluded_geographical_area=membership1.member,
origin=origin2,
)
exclusion2 = factories.QuotaOrderNumberOriginExclusionFactory.create(
excluded_geographical_area=membership2.member,
origin=origin2,
)

# sanity check
tx = Transaction.objects.last()
assert quota.quotaordernumberorigin_set.approved_up_to_transaction(tx).count() == 2
assert (
origin1.quotaordernumberoriginexclusion_set.approved_up_to_transaction(
tx,
).count()
== 0
)
assert (
origin2.quotaordernumberoriginexclusion_set.approved_up_to_transaction(
tx,
).count()
== 2
)

data = {
"start_date_0": quota.valid_between.lower.day,
"start_date_1": quota.valid_between.lower.month,
"start_date_2": quota.valid_between.lower.year,
"end_date_0": "",
"end_date_1": "",
"end_date_2": "",
"category": quota.category,
"origins-0-pk": origin1.pk,
"origins-0-start_date_0": origin1.valid_between.lower.day,
"origins-0-start_date_1": origin1.valid_between.lower.month,
"origins-0-start_date_2": origin1.valid_between.lower.year,
"origins-0-end_date_0": "",
"origins-0-end_date_1": "",
"origins-0-end_date_2": "",
"origins-0-geographical_area": origin1.geographical_area.pk,
# remove the second origin and its exclusion
"submit": "Save",
}

url = reverse("quota-ui-edit", kwargs={"sid": quota.sid})
response = client_with_current_workbasket.post(url, data)

assert response.status_code == 302
assert response.url == reverse("quota-ui-confirm-update", kwargs={"sid": quota.sid})

last_tx = Transaction.objects.last()

updated_quota = (
models.QuotaOrderNumber.objects.approved_up_to_transaction(last_tx)
.filter(sid=quota.sid)
.first()
)

assert updated_quota.origins.approved_up_to_transaction(last_tx).count() == 1
updated_origin = (
updated_quota.quotaordernumberorigin_set.approved_up_to_transaction(
last_tx,
).first()
)
assert (
updated_origin.quotaordernumberoriginexclusion_set.approved_up_to_transaction(
last_tx,
).count()
== 0
)
# update quota
# update origin 1 to link to updated quota
# delete quota origin 2
# delete both quota origin 2 exclusions
assert updated_origin.transaction.workbasket.tracked_models.count() == 5
assert sorted(
[
item.get_update_type_display()
for item in updated_origin.transaction.workbasket.tracked_models.all()
],
) == ["Delete", "Delete", "Delete", "Update", "Update"]


@pytest.mark.parametrize(
"data, expected_model",
[
Expand Down

0 comments on commit dec1438

Please sign in to comment.