Skip to content

Commit

Permalink
Add tests for Sort by
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenMullally committed Sep 28, 2023
1 parent 0ae4730 commit 17adf12
Showing 1 changed file with 88 additions and 7 deletions.
95 changes: 88 additions & 7 deletions measures/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from common.validators import UpdateType
from common.views import TamatoListView
from common.views import TrackedModelDetailMixin
from geo_areas.validators import AreaCode
from measures.business_rules import ME70
from measures.constants import START
from measures.constants import MeasureEditSteps
Expand Down Expand Up @@ -1307,10 +1308,9 @@ def test_measure_form_wizard_create_measures(
# Create measures returns a list of created measures
measure_data = wizard.create_measures(form_data)
measures = Measure.objects.filter(goods_nomenclature__in=[commodity1, commodity2])

"""
In this implementation goods_nomenclature is a FK of Measure, so there is one measure
for each commodity specified in formset-commodities.
In this implementation goods_nomenclature is a FK of Measure, so there is
one measure for each commodity specified in formset-commodities.
Verify that the expected measures were created.
"""
Expand Down Expand Up @@ -1535,10 +1535,7 @@ def test_measure_form_wizard_create_measures_with_tariff_suspension_action(
# Create measures returns a list of created measures
measure_data = wizard.create_measures(form_data)
measures = Measure.objects.filter(goods_nomenclature=commodity1)

"""
Verify that the expected measures were created.
"""
"""Verify that the expected measures were created."""
assert len(measure_data) == 1

# Each created measure contains the supplied condition codes where DELETE=False
Expand Down Expand Up @@ -2385,3 +2382,87 @@ def test_measure_list_redirects_to_search_with_no_params(valid_user_client):
def test_measure_search_200(valid_user_client):
response = valid_user_client.get(reverse("measure-ui-search"))
assert response.status_code == 200


def test_measures_list_sorting(valid_user_client, date_ranges):
# make measure types
type1 = factories.MeasureTypeFactory.create(sid="111")
type2 = factories.MeasureTypeFactory.create(sid="222")
type3 = factories.MeasureTypeFactory.create(sid="333")

# Make geo_groups
# Erga Omnes
area_1 = factories.GeographicalAreaFactory.create(
area_code=AreaCode.GROUP,
area_id="1011",
)
# North America
area_2 = factories.GeographicalAreaFactory.create(
area_code=AreaCode.GROUP,
area_id="2200",
)
# European Union
area_3 = factories.GeographicalAreaFactory.create(
area_code=AreaCode.GROUP,
area_id="1013",
)

# make measures
measure1 = factories.MeasureFactory.create(
measure_type=type1,
geographical_area=area_2,
valid_between=date_ranges.no_end,
)
measure2 = factories.MeasureFactory.create(
measure_type=type2,
geographical_area=area_3,
valid_between=date_ranges.earlier,
)
measure3 = factories.MeasureFactory.create(
measure_type=type3,
geographical_area=area_1,
valid_between=date_ranges.later,
)

sort_by_list = [
"?sort_by=sid&ordered=desc",
"?sort_by=sid&ordered=asc",
"?sort_by=measure_type&ordered=desc",
"?sort_by=measure_type&ordered=asc",
"?sort_by=start_date&ordered=desc",
"?sort_by=start_date&ordered=asc",
"?sort_by=end_date&ordered=desc",
"?sort_by=end_date&ordered=asc",
"?sort_by=geo_area&ordered=desc",
"?sort_by=geo_area&ordered=asc",
]

expected_order_list = [
# sid desc, asc
[measure3.sid, measure2.sid, measure1.sid],
[measure1.sid, measure2.sid, measure3.sid],
# type desc, asc
[measure3.sid, measure2.sid, measure1.sid],
[measure1.sid, measure2.sid, measure3.sid],
# start date desc, asc
[measure3.sid, measure1.sid, measure2.sid],
[measure2.sid, measure1.sid, measure3.sid],
# end date desc, asc
[measure1.sid, measure3.sid, measure2.sid],
[measure2.sid, measure3.sid, measure1.sid],
# geo area desc, asc
[measure1.sid, measure2.sid, measure3.sid],
[measure3.sid, measure2.sid, measure1.sid],
]

for index, item in enumerate(sort_by_list):
url = reverse("measure-ui-list") + item
response = valid_user_client.get(url)

assert response.status_code == 200

soup = BeautifulSoup(response.content.decode(response.charset), "html.parser")
measure_sids = [
int(el.text) for el in soup.select(".govuk-table tbody tr td:nth-child(2)")
]
assert measure_sids == expected_order_list[index]

0 comments on commit 17adf12

Please sign in to comment.