Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge to Master #1215

Merged
merged 10 commits into from
Nov 30, 2023
22 changes: 22 additions & 0 deletions exporting/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,25 @@ def test_lookup_by_postcode_unsuppported_error(mock_postcode_to_region_id, api_c
total_offices = Office.objects.all().count()

assert len(other_offices) == total_offices


@pytest.mark.django_db
@mock.patch('exporting.helpers.postcode_to_region_id')
def test_lookup_by_postcode_attribute_error(mock_postcode_to_region_id, api_client):
mock_postcode_to_region_id.side_effect = AttributeError()

url = reverse('offices-by-postcode', kwargs={'postcode': 'ABC 123'})

response = api_client.get(url)

assert response.status_code == 200

matched_office = list(filter(lambda x: x['is_match'] is True, response.json()))

assert len(matched_office) == 0

other_offices = list(filter(lambda x: x['is_match'] is False, response.json()))

total_offices = Office.objects.all().count()

assert len(other_offices) == total_offices
2 changes: 1 addition & 1 deletion exporting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RetrieveOfficesByPostCode(ListAPIView):
def get_queryset(self):
try:
region_id = helpers.postcode_to_region_id(self.kwargs['postcode'])
except requests.exceptions.RequestException:
except (AttributeError, requests.exceptions.RequestException):
region_id = None

return models.Office.objects.annotate(
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ directory-constants==23.1.1
directory-sso-api-client==7.2.3
directory-healthcheck==3.1.2
directory-forms-api-client>=7.2.2
cryptography==41.0.4
cryptography==41.0.6
directory-components==39.1.3
urllib3==1.26.18
factory-boy==2.12.0
Expand Down
14 changes: 11 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ botocore==1.27.96
celery[redis]==5.2.7
# via
# -r requirements.in
# celery
# django-celery-beat
certifi==2023.7.22
# via
Expand All @@ -58,7 +59,7 @@ click-repl==0.2.0
# via celery
cron-descriptor==1.4.0
# via django-celery-beat
cryptography==41.0.4
cryptography==41.0.6
# via
# -r requirements.in
# pyhanko
Expand Down Expand Up @@ -163,6 +164,8 @@ faker==15.3.4
# via factory-boy
future==0.18.3
# via django-json-widget
greenlet==3.0.1
# via sqlalchemy
html5lib==1.1
# via xhtml2pdf
idna==3.4
Expand Down Expand Up @@ -285,6 +288,7 @@ requests[security]==2.31.0
# notifications-python-client
# pyhanko
# pyhanko-certvalidator
# requests
# requests-oauthlib
requests-oauthlib==1.3.1
# via django-staff-sso-client
Expand Down Expand Up @@ -317,15 +321,19 @@ sqlparse==0.4.4
svglib==1.4.1
# via xhtml2pdf
tablib[html,ods,xls,xlsx,yaml]==3.4.0
# via django-import-export
# via
# django-import-export
# tablib
tinycss2==1.2.1
# via
# cssselect2
# svglib
typing-extensions==4.7.1
# via pypdf
tzdata==2022.7
# via django-celery-beat
# via
# django-celery-beat
# pytz-deprecation-shim
tzlocal==4.2
# via pyhanko
uritemplate==4.1.1
Expand Down
17 changes: 13 additions & 4 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ botocore==1.27.96
celery[redis]==5.2.3
# via
# -r requirements.in
# celery
# django-celery-beat
certifi==2023.7.22
# via
Expand Down Expand Up @@ -67,18 +68,19 @@ click-repl==0.2.0
# via celery
coverage[toml]==6.3
# via
# coverage
# pytest-codecov
# pytest-cov
cron-descriptor==1.4.0
# via django-celery-beat
cryptography==41.0.4
cryptography==41.0.6
# via
# -r requirements.in
# pyhanko
# pyhanko-certvalidator
cssselect2==0.5.0
# via svglib
dataclasses==0.06
dataclasses==0.6
# via -r requirements_test.in
defusedxml==0.7.1
# via odfpy
Expand Down Expand Up @@ -186,6 +188,8 @@ gitdb==4.0.10
# via gitpython
gitpython==3.1.37
# via -r requirements_test.in
greenlet==3.0.1
# via sqlalchemy
html5lib==1.1
# via xhtml2pdf
idna==2.10
Expand Down Expand Up @@ -354,6 +358,7 @@ requests[security]==2.31.0
# pyhanko
# pyhanko-certvalidator
# pytest-codecov
# requests
# requests-mock
# requests-oauthlib
requests-mock==1.6.0
Expand Down Expand Up @@ -397,7 +402,9 @@ sqlparse==0.4.4
svglib==1.2.1
# via xhtml2pdf
tablib[html,ods,xls,xlsx,yaml]==3.4.0
# via django-import-export
# via
# django-import-export
# tablib
termcolor==1.1.0
# via pytest-sugar
text-unidecode==1.3
Expand All @@ -418,7 +425,9 @@ typing-extensions==4.0.1
# black
# pypdf
tzdata==2022.1
# via django-celery-beat
# via
# django-celery-beat
# pytz-deprecation-shim
tzlocal==4.2
# via pyhanko
uritemplate==4.1.1
Expand Down