Skip to content

Commit

Permalink
tests to expect measures in results for different measure versions
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gleeson committed Mar 14, 2024
1 parent 298b1b8 commit 7a44e58
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ webpack-stats.json
# PyCharm
.idea/

# VS Code
.vscode/

*.gz

Expand All @@ -166,4 +164,5 @@ _dumped_cache.pkl
# Vim
.swp

tamato_*.sql
# Database dumps
*.sql
50 changes: 50 additions & 0 deletions certificates/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,56 @@ def test_certificate_detail_measures_view_lists_measures(valid_user_client):
assert page.find("nav", class_="pagination").find_next("a", href="?page=2")


def test_certificate_detail_measures_view_lists_measures_latest_version(
valid_user_client,
user_workbasket,
):
"""Test that `CertificateDetailMeasures` view displays a paginated list of
the latest measures for a certificate when the condition is related to the
."""
certificate = factories.CertificateFactory.create()
tnx = certificate.transaction
workbasket = certificate.transaction.workbasket
measures = []
new_measures = []
for measure_with_condition in range(10):
measure = factories.MeasureFactory.create(
transaction=tnx,
)
factories.MeasureConditionFactory.create(
dependent_measure=measure,
required_certificate=certificate,
transaction=tnx,
)
new_measure = measure.new_version(
workbasket=workbasket,
update_type=UpdateType.UPDATE,
)
measures.append(measure)
new_measures.append(new_measure)

url = reverse(
"certificate-ui-detail-measures",
kwargs={
"sid": certificate.sid,
"certificate_type__sid": certificate.certificate_type.sid,
},
)
response = valid_user_client.get(url)
page = BeautifulSoup(
response.content.decode(response.charset),
"html.parser",
)

table_rows = page.select(".govuk-table tbody tr")
assert len(table_rows) == 10

table_measure_sids = {
int(sid.text) for sid in page.select(".govuk-table tbody tr td:first-child")
}
assert table_measure_sids == {m.sid for m in new_measures}


def test_certificate_detail_measures_view_sorting_commodity(valid_user_client):
"""Test that measures listed on `CertificateDetailMeasures` view can be
sorted by commodity code in ascending or descending order."""
Expand Down
13 changes: 7 additions & 6 deletions measures/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,14 @@ def test_filter_by_certificates(

# update a measure, both updated and original measure_with_certificate should show in result
new_transaction = factories.TransactionFactory.create()
# only update the measure and as queryset should find the latest version of the measure irrespective of the measure condition version
updated_measure = measure_with_certificate.new_version(
workbasket=new_transaction.workbasket,
transaction=new_transaction,
update_type=UpdateType.UPDATE,
valid_between=new_date_range,
stopped=False,
)
factories.MeasureConditionFactory.create(
dependent_measure=updated_measure,
required_certificate=certificate,
)
qs = Measure.objects.all()

measure_filter = MeasureFilter(
Expand All @@ -91,7 +88,11 @@ def test_filter_by_certificates(
value=certificate,
)

assert measure_with_certificate in filtered_measures
sids = [measure.sid for measure in filtered_measures]

# check sid as measure_with_certificate is an older version which wouldn't be returned
assert measure_with_certificate.sid in sids
# newest version of measure so it will be in the filtered measures
assert updated_measure in filtered_measures
assert measure_no_certificate not in filtered_measures
assert measure_with_different_certificate not in filtered_measures
assert updated_measure in filtered_measures

0 comments on commit 7a44e58

Please sign in to comment.