Skip to content

Commit

Permalink
Merge pull request #1019 from uktrade/release
Browse files Browse the repository at this point in the history
Prod Release 2.3.2
  • Loading branch information
froddd authored Apr 27, 2022
2 parents 77fee42 + 72e2f0d commit d7e84e4
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 23 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

### Implemented enhancements



### Fixed bugs

- GLS-193 - prevent invalid latitude/longitude in linked location coordinates


## [2.3.0](https://github.com/uktrade/directory-cms/releases/tag/2.3.0)
Expand Down
3 changes: 2 additions & 1 deletion great_international/blocks/investment_atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
MarkdownBlock,
InternationalInvestmentPageCopyBlockBase,
)
from great_international.validators import validate_lat_long


class InlineOpportunityImageBlock(BaseAltTextImageBlock):
Expand Down Expand Up @@ -216,12 +217,12 @@ class OpportunityLocationBlock(blocks.StructBlock):
required=False,
label='Linked Region',
page_type='great_international.AboutUkRegionPage'

)
map_coordinate = blocks.CharBlock(
max_length=200,
label='Linked Location Coordinates',
help_text='Latitude and longitude Coordinates, e.g. 176.0944492, -38.50245621',
validators=[validate_lat_long],
) # deliberately not a pointfield yet

def get_api_representation(self, value, context=None):
Expand Down
8 changes: 8 additions & 0 deletions great_international/validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import re

from django.core.exceptions import ValidationError


def validate_lat_long(value):
if re.match(r'^(-|\+)?\d{1,3}(\.\d+)?\s*,\s*(-|\+)?\d{1,3}(\.\d+)?$', value.strip()) is None:
raise ValidationError('Invalid latitude/longitude.')
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
django==2.2.26
django==2.2.28
djangorestframework==3.12.*
django-environ==0.4.5
gunicorn==20.1.0
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ directory-healthcheck==1.1.2
# via -r requirements.in
dj-database-url==0.5.0
# via -r requirements.in
django==2.2.26
django==2.2.28
# via
# -r requirements.in
# directory-components
Expand Down Expand Up @@ -108,7 +108,7 @@ django-redis==4.10.0
# via -r requirements.in
django-staff-sso-client==1.0.1
# via -r requirements.in
django_storages==1.7.1
django-storages==1.7.1
# via -r requirements.in
django-taggit==1.5.1
# via wagtail
Expand Down Expand Up @@ -173,9 +173,9 @@ openpyxl==3.0.9
# via tablib
packaging==21.3
# via bleach
pillow==9.0.0
pillow==9.0.1
# via wagtail
prompt-toolkit==3.0.26
prompt-toolkit==3.0.27
# via click-repl
psycogreen==1.0.2
# via -r requirements.in
Expand Down Expand Up @@ -283,9 +283,9 @@ xlsxwriter==1.4.5
# via wagtail
xlwt==1.3.0
# via tablib
zope.event==4.5.0
zope-event==4.5.0
# via gevent
zope.interface==5.4.0
zope-interface==5.4.0
# via gevent

# The following packages are considered to be unsafe in a requirements file:
Expand Down
25 changes: 12 additions & 13 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ click-repl==0.2.0
# via celery
codecov==2.1.12
# via -r requirements_test.in
coverage[toml]==6.3
coverage[toml]==6.3.1
# via
# codecov
# coveralls
Expand All @@ -77,7 +77,7 @@ directory-healthcheck==1.1.2
# via -r requirements.in
dj-database-url==0.5.0
# via -r requirements.in
django==2.2.26
django==2.2.28
# via
# -r requirements.in
# directory-components
Expand Down Expand Up @@ -123,7 +123,7 @@ django-redis==4.10.0
# via -r requirements.in
django-staff-sso-client==1.0.1
# via -r requirements.in
django_storages==1.7.1
django-storages==1.7.1
# via -r requirements.in
django-taggit==1.5.1
# via wagtail
Expand Down Expand Up @@ -151,7 +151,7 @@ factory-boy==2.12.0
# via
# -r requirements_test.in
# wagtail-factories
faker==12.0.0
faker==12.2.0
# via factory-boy
flake8==4.0.1
# via -r requirements_test.in
Expand Down Expand Up @@ -208,13 +208,13 @@ packaging==21.3
# pytest-sugar
pep517==0.12.0
# via pip-tools
pillow==9.0.0
pillow==9.0.1
# via wagtail
pip-tools==6.4.0
pip-tools==6.5.1
# via -r requirements_test.in
pluggy==1.0.0
# via pytest
prompt-toolkit==3.0.26
prompt-toolkit==3.0.27
# via click-repl
psycogreen==1.0.2
# via -r requirements.in
Expand All @@ -236,7 +236,7 @@ pyparsing==3.0.7
# via packaging
pyrsistent==0.18.1
# via jsonschema
pytest==6.2.5
pytest==7.0.0
# via
# -r requirements_test.in
# pytest-cov
Expand Down Expand Up @@ -312,12 +312,11 @@ tablib[xls,xlsx]==3.2.0
# via wagtail
termcolor==1.1.0
# via pytest-sugar
toml==0.10.2
# via pytest
tomli==2.0.0
tomli==2.0.1
# via
# coverage
# pep517
# pytest
unidecode==1.3.2
# via wagtail
urllib3==1.26.8
Expand Down Expand Up @@ -364,9 +363,9 @@ xlsxwriter==1.4.5
# via wagtail
xlwt==1.3.0
# via tablib
zope.event==4.5.0
zope-event==4.5.0
# via gevent
zope.interface==5.4.0
zope-interface==5.4.0
# via gevent

# The following packages are considered to be unsafe in a requirements file:
Expand Down
31 changes: 31 additions & 0 deletions tests/great_international/test_validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest
from django.core.exceptions import ValidationError

from great_international.validators import validate_lat_long


@pytest.mark.django_db
@pytest.mark.parametrize(
'value, raise_expected',
(
('51.123456, -2.345678', False),
(' 51.123456 , -2.345678 ', False),
('+51.123456, +1.1', False),
(' 51.123456, -2.345678 ', False),
('31.123456,2.345678', False),
('50, 2', False),
('50., 2.', True),
('50', True),
('50º N, 2º W', True),
('Not even trying', True),
)
)
def test_validate_lat_long(value, raise_expected):
try:
validate_lat_long(value)
except ValidationError:
if not raise_expected:
pytest.fail(f'Expected {value} to pass validation, but it failed')
else:
if raise_expected:
pytest.fail(f'Expected {value} to fail validation, but it passed')

0 comments on commit d7e84e4

Please sign in to comment.