From e2fa98026a14fd4cebae0f7de82673d15b405921 Mon Sep 17 00:00:00 2001 From: richtier Date: Fri, 31 Jan 2020 16:50:05 +0000 Subject: [PATCH 01/10] Post deployment changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bed32c7c..45f85a8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ ### Implemented enhancements +### Fixed bugs + +## [2020.01.31](https://github.com/uktrade/directory-cms/releases/tag/2020.01.31) +[Full Changelog](https://github.com/uktrade/directory-cms/compare/2020.01.29...2020.01.31) + +### Implemented enhancements + - XOT-1285 madb content markdown field ## [2020.01.29](https://github.com/uktrade/directory-cms/releases/tag/2020.01.29) From 623da2aa87e0df114c3a23c3d8eda1b10e059c3c Mon Sep 17 00:00:00 2001 From: richtier Date: Mon, 3 Feb 2020 14:00:47 +0000 Subject: [PATCH 02/10] Add MADB link field to country guide --- CHANGELOG.md | 1 + .../migrations/0073_auto_20200203_1333.py | 50 +++++++++++++++++++ export_readiness/models.py | 5 +- export_readiness/panels.py | 2 +- export_readiness/serializers.py | 2 +- requirements.in | 1 + requirements.txt | 3 +- requirements_test.txt | 3 +- tests/export_readiness/factories.py | 2 +- 9 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 export_readiness/migrations/0073_auto_20200203_1333.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 45f85a8f..686c4398 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Pre-release ### Implemented enhancements +- XOT-1275 - Add MADB link field to country guide ### Fixed bugs diff --git a/export_readiness/migrations/0073_auto_20200203_1333.py b/export_readiness/migrations/0073_auto_20200203_1333.py new file mode 100644 index 00000000..a8d8d6c2 --- /dev/null +++ b/export_readiness/migrations/0073_auto_20200203_1333.py @@ -0,0 +1,50 @@ +# Generated by Django 2.2.6 on 2020-02-03 13:33 + +import logging + + +import core.model_fields +from django.db import migrations, models + +import pycountry + + +logger = logging.getLogger(__name__) + + +def set_duties_and_custom_procedures_cta_link(apps, schema_editor): + url = 'https://www.check-duties-customs-exporting-goods.service.gov.uk/searchproduct?d=' + CountryGuidePage = apps.get_model('export_readiness', 'CountryGuidePage') + for guide in CountryGuidePage.objects.all(): + try: + matches = pycountry.countries.search_fuzzy(guide.country.name) + except LookupError: + logger.warn(f'no country match for {guide.country.name}') + else: + guide.duties_and_custom_procedures_cta_link = f'{url}{matches[0].alpha_2}' + guide.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('export_readiness', '0072_auto_20191212_1403'), + ] + + operations = [ + migrations.RemoveField( + model_name='countryguidepage', + name='help_market_guide_cta_link', + ), + migrations.AddField( + model_name='countryguidepage', + name='duties_and_custom_procedures_cta_link', + field=models.URLField(blank=True, null=True, verbose_name='Check duties and customs procedures for exporting goods'), + ), + migrations.AlterField( + model_name='homepage', + name='madb_content', + field=core.model_fields.MarkdownField(blank=True, null=True, verbose_name='Content'), + ), + migrations.RunPython(set_duties_and_custom_procedures_cta_link, reverse_code=migrations.RunPython.noop) + ] diff --git a/export_readiness/models.py b/export_readiness/models.py index 13ac2da9..202a387e 100644 --- a/export_readiness/models.py +++ b/export_readiness/models.py @@ -1020,8 +1020,9 @@ class Meta: ) # need help - help_market_guide_cta_link = models.CharField( - max_length=255, blank=True, verbose_name='GOV.UK country guide URL') + duties_and_custom_procedures_cta_link = models.URLField( + blank=True, null=True, verbose_name='Check duties and customs procedures for exporting goods' + ) # related pages related_page_one = models.ForeignKey( diff --git a/export_readiness/panels.py b/export_readiness/panels.py index 15bc0267..aa9dc0e6 100644 --- a/export_readiness/panels.py +++ b/export_readiness/panels.py @@ -889,7 +889,7 @@ class CountryGuidePagePanels: heading='Need help', classname='collapsible', children=[ - FieldPanel('help_market_guide_cta_link') + FieldPanel('duties_and_custom_procedures_cta_link') ] ), MultiFieldPanel( diff --git a/export_readiness/serializers.py b/export_readiness/serializers.py index 860d1454..0fafd55f 100644 --- a/export_readiness/serializers.py +++ b/export_readiness/serializers.py @@ -419,7 +419,7 @@ class CountryGuidePageSerializer(PageWithRelatedPagesSerializer, HeroSerializer) accordions = serializers.SerializerMethodField() fact_sheet = serializers.SerializerMethodField() - help_market_guide_cta_link = serializers.CharField(max_length=255) + duties_and_custom_procedures_cta_link = serializers.CharField(max_length=255) tags = core_fields.TagsListField() region = serializers.CharField(allow_null=True, source='country.region.name') diff --git a/requirements.in b/requirements.in index 17d69b98..e9c30bb1 100644 --- a/requirements.in +++ b/requirements.in @@ -33,3 +33,4 @@ w3lib>=1.19.0<2.0.0 django-admin-ip-restrictor==2.1.0 notifications-python-client==5.3.* pillow>=6.2.0 # for security fix. check compatibility on next wagtail upgrade +pycountry==19.8.18 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 4a901804..52652b90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -56,6 +56,7 @@ notifications-python-client==5.3.0 oauthlib==3.1.0 # via requests-oauthlib pillow==6.2.1 psycopg2==2.7.3.2 +pycountry==19.8.18 pyjwt==1.7.1 # via notifications-python-client pyrsistent==0.15.6 # via jsonschema python-dateutil==2.6.1 # via botocore @@ -68,7 +69,7 @@ requests==2.21.0 s3transfer==0.1.13 # via boto3 sentry-sdk==0.13.4 sigauth==4.1.0 -six==1.13.0 # via bleach, html5lib, jsonschema, mohawk, pyrsistent, w3lib, wagtail +six==1.13.0 # via bleach, html5lib, jsonschema, mohawk, pyrsistent, python-dateutil, w3lib, wagtail sqlparse==0.3.0 # via django unidecode==1.1.1 # via wagtail urllib3==1.24.3 diff --git a/requirements_test.txt b/requirements_test.txt index 49745644..847acd9c 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -71,6 +71,7 @@ pluggy==0.12.0 # via pytest psycopg2==2.7.3.2 py==1.7.0 # via pytest pycodestyle==2.4.0 # via flake8 +pycountry==19.8.18 pyflakes==2.0.0 # via flake8 pyjwt==1.7.1 # via notifications-python-client pyparsing==2.3.0 # via packaging @@ -90,7 +91,7 @@ requests==2.21.0 s3transfer==0.1.13 # via boto3 sentry-sdk==0.13.4 sigauth==4.1.0 -six==1.12.0 # via bleach, faker, freezegun, html5lib, jsonschema, mohawk, more-itertools, packaging, pip-tools, pyrsistent, requests-mock, w3lib, wagtail +six==1.12.0 # via bleach, faker, freezegun, html5lib, jsonschema, mohawk, more-itertools, packaging, pip-tools, pyrsistent, python-dateutil, requests-mock, w3lib, wagtail sqlparse==0.2.4 # via django, django-debug-toolbar termcolor==1.1.0 # via pytest-sugar text-unidecode==1.2 # via faker diff --git a/tests/export_readiness/factories.py b/tests/export_readiness/factories.py index 1d4cfdd8..68902149 100644 --- a/tests/export_readiness/factories.py +++ b/tests/export_readiness/factories.py @@ -326,7 +326,7 @@ class Meta: fact_sheet_column_2_teaser = factory.fuzzy.FuzzyText(length=10) fact_sheet_column_2_body = factory.fuzzy.FuzzyText(length=10) - help_market_guide_cta_link = factory.fuzzy.FuzzyText(length=10) + duties_and_custom_procedures_cta_link = 'http://www.example.com' related_page_one = factory.SubFactory(ArticlePageFactory) related_page_two = factory.SubFactory(CampaignPageFactory) From eac5d76ee6aef249b790ed058d2eca160f1a4439 Mon Sep 17 00:00:00 2001 From: richtier Date: Mon, 3 Feb 2020 15:56:49 +0000 Subject: [PATCH 03/10] Upgrade django --- requirements.txt | 2 +- requirements_test.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 52652b90..922209dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,7 +31,7 @@ django-redis==4.10.0 django-staff-sso-client==1.0.0 django-taggit==0.24.0 # via wagtail django-treebeard==4.3 # via wagtail -django==2.2.8 +django==2.2.10 django_storages==1.7.1 djangorestframework==3.9.4 docopt==0.6.2 # via notifications-python-client diff --git a/requirements_test.txt b/requirements_test.txt index 847acd9c..0f29550f 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -36,7 +36,7 @@ django-redis==4.10.0 django-staff-sso-client==1.0.0 django-taggit==0.23.0 # via wagtail django-treebeard==4.3 # via wagtail -django==2.2.8 +django==2.2.10 django_storages==1.7.1 djangorestframework==3.9.4 docopt==0.6.2 # via coveralls, notifications-python-client From 2b6458641047b7ce9e903461357904e19aacd7c9 Mon Sep 17 00:00:00 2001 From: richtier Date: Tue, 4 Feb 2020 12:28:06 +0000 Subject: [PATCH 04/10] Upgrade Django to fix security vulnerability --- CHANGELOG.md | 7 +++++++ requirements.txt | 4 ++-- requirements_test.txt | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bed32c7c..8ce7374a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ - XOT-1285 madb content markdown field +## [2020.02.04](https://github.com/uktrade/directory-cms/releases/tag/2020.02.04) +[Full Changelog](https://github.com/uktrade/directory-cms/compare/2020.01.29...2020.02.04) + +### Hotfix + +- No ticket - Upgrade Django to fix security vulnerability + ## [2020.01.29](https://github.com/uktrade/directory-cms/releases/tag/2020.01.29) [Full Changelog](https://github.com/uktrade/directory-cms/compare/2020.01.20...2020.01.29) diff --git a/requirements.txt b/requirements.txt index 4a901804..1837b9f9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,7 +31,7 @@ django-redis==4.10.0 django-staff-sso-client==1.0.0 django-taggit==0.24.0 # via wagtail django-treebeard==4.3 # via wagtail -django==2.2.8 +django==2.2.10 django_storages==1.7.1 djangorestframework==3.9.4 docopt==0.6.2 # via notifications-python-client @@ -68,7 +68,7 @@ requests==2.21.0 s3transfer==0.1.13 # via boto3 sentry-sdk==0.13.4 sigauth==4.1.0 -six==1.13.0 # via bleach, html5lib, jsonschema, mohawk, pyrsistent, w3lib, wagtail +six==1.13.0 # via bleach, html5lib, jsonschema, mohawk, pyrsistent, python-dateutil, w3lib, wagtail sqlparse==0.3.0 # via django unidecode==1.1.1 # via wagtail urllib3==1.24.3 diff --git a/requirements_test.txt b/requirements_test.txt index 49745644..ac1c7cb2 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -36,7 +36,7 @@ django-redis==4.10.0 django-staff-sso-client==1.0.0 django-taggit==0.23.0 # via wagtail django-treebeard==4.3 # via wagtail -django==2.2.8 +django==2.2.10 django_storages==1.7.1 djangorestframework==3.9.4 docopt==0.6.2 # via coveralls, notifications-python-client @@ -90,7 +90,7 @@ requests==2.21.0 s3transfer==0.1.13 # via boto3 sentry-sdk==0.13.4 sigauth==4.1.0 -six==1.12.0 # via bleach, faker, freezegun, html5lib, jsonschema, mohawk, more-itertools, packaging, pip-tools, pyrsistent, requests-mock, w3lib, wagtail +six==1.12.0 # via bleach, faker, freezegun, html5lib, jsonschema, mohawk, more-itertools, packaging, pip-tools, pyrsistent, python-dateutil, requests-mock, w3lib, wagtail sqlparse==0.2.4 # via django, django-debug-toolbar termcolor==1.1.0 # via pytest-sugar text-unidecode==1.2 # via faker From 3eac767caef69526f0002a0a1abfe4e643141edc Mon Sep 17 00:00:00 2001 From: Edie Pearce Date: Tue, 4 Feb 2020 17:00:36 +0000 Subject: [PATCH 05/10] Fix error on opportunity page --- great_international/serializers.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/great_international/serializers.py b/great_international/serializers.py index c4c03505..d2c631fd 100644 --- a/great_international/serializers.py +++ b/great_international/serializers.py @@ -1,3 +1,5 @@ +import random + from directory_constants import cms from rest_framework import serializers from wagtail.images.api import fields as wagtail_fields @@ -1637,16 +1639,24 @@ def get_sub_sectors(self, instance): related_opportunities = serializers.SerializerMethodField() def get_related_opportunities(self, instance): - random_sector = instance.related_sectors.order_by('?').first() + random_sector_id = random.choice( + instance.related_sectors.values_list('related_sector_id', flat=True)) + + if random_sector_id: + + related_opps_ids = CapitalInvestOpportunityPage.objects.filter( + related_sectors__related_sector_id=random_sector_id + ).exclude(id=instance.id).values_list('pk', flat=True) + + random_ids = random.sample(list(related_opps_ids), 3) - if random_sector: + related_opps = [] - three_random_opps = CapitalInvestOpportunityPage.objects.filter( - related_sectors__related_sector_id=random_sector.related_sector_id - ).order_by('?').exclude(id=instance.id)[:3] + for id in random_ids: + related_opps.append(CapitalInvestOpportunityPage.objects.get(pk=id)) serializer = RelatedCapitalInvestOpportunityPageSerializer( - three_random_opps, + related_opps, many=True, allow_null=True, context=self.context From 6fce8642b644663247de486e76cf7505a1cfff92 Mon Sep 17 00:00:00 2001 From: Edie Pearce Date: Tue, 4 Feb 2020 17:00:59 +0000 Subject: [PATCH 06/10] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7d19dde..47130e02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - XOT-1275 - Add MADB link field to country guide ### Fixed bugs +No ticket - Fix error on opportunity page ## [2020.01.31](https://github.com/uktrade/directory-cms/releases/tag/2020.01.31) [Full Changelog](https://github.com/uktrade/directory-cms/compare/2020.01.29...2020.01.31) From e15791beab220bcb94137cc3d8773a5f0e4d915c Mon Sep 17 00:00:00 2001 From: Edie Pearce Date: Wed, 5 Feb 2020 10:56:11 +0000 Subject: [PATCH 07/10] Fix tests --- great_international/serializers.py | 41 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/great_international/serializers.py b/great_international/serializers.py index d2c631fd..cf941cab 100644 --- a/great_international/serializers.py +++ b/great_international/serializers.py @@ -1639,31 +1639,38 @@ def get_sub_sectors(self, instance): related_opportunities = serializers.SerializerMethodField() def get_related_opportunities(self, instance): - random_sector_id = random.choice( - instance.related_sectors.values_list('related_sector_id', flat=True)) + related_sectors_ids = instance.related_sectors.values_list('related_sector_id', flat=True) - if random_sector_id: + if not related_sectors_ids: + return [] + + random_sector_id = random.choice(related_sectors_ids) + + related_opps_ids = CapitalInvestOpportunityPage.objects.filter( + related_sectors__related_sector_id=random_sector_id + ).exclude(id=instance.id).values_list('pk', flat=True) - related_opps_ids = CapitalInvestOpportunityPage.objects.filter( - related_sectors__related_sector_id=random_sector_id - ).exclude(id=instance.id).values_list('pk', flat=True) + if not related_opps_ids: + return [] + elif len(related_opps_ids) > 3: random_ids = random.sample(list(related_opps_ids), 3) - related_opps = [] + else: + random_ids = related_opps_ids - for id in random_ids: - related_opps.append(CapitalInvestOpportunityPage.objects.get(pk=id)) + related_opps = [] - serializer = RelatedCapitalInvestOpportunityPageSerializer( - related_opps, - many=True, - allow_null=True, - context=self.context - ) - return serializer.data + for id in random_ids: + related_opps.append(CapitalInvestOpportunityPage.objects.get(pk=id)) - return [] + serializer = RelatedCapitalInvestOpportunityPageSerializer( + related_opps, + many=True, + allow_null=True, + context=self.context + ) + return serializer.data class MinimalPageSerializer(BasePageSerializer): From f4c873896482e4bf686e569e3f3391b3f6326506 Mon Sep 17 00:00:00 2001 From: Edie Pearce Date: Wed, 5 Feb 2020 12:15:37 +0000 Subject: [PATCH 08/10] Fix tests --- great_international/models/capital_invest.py | 4 +- tests/great_international/factories.py | 8 ++ tests/great_international/test_serializers.py | 107 +++++++++++------- 3 files changed, 77 insertions(+), 42 deletions(-) diff --git a/great_international/models/capital_invest.py b/great_international/models/capital_invest.py index b04f4309..e8821253 100644 --- a/great_international/models/capital_invest.py +++ b/great_international/models/capital_invest.py @@ -544,9 +544,7 @@ class CapitalInvestRelatedSubSectors(Orderable, RelatedSubSector): ) -class CapitalInvestOpportunityPage( - panels.CapitalInvestOpportunityPagePanels, BaseInternationalPage -): +class CapitalInvestOpportunityPage(panels.CapitalInvestOpportunityPagePanels, BaseInternationalPage): parent_page_types = [ 'great_international.CapitalInvestOpportunityListingPage' diff --git a/tests/great_international/factories.py b/tests/great_international/factories.py index 6318ed58..c717d7ca 100644 --- a/tests/great_international/factories.py +++ b/tests/great_international/factories.py @@ -412,6 +412,14 @@ class Meta: parent = None +class CapitalInvestRelatedSectorsFactory(factory.django.DjangoModelFactory): + class Meta: + model = models.capital_invest.CapitalInvestRelatedSectors + + page = None + related_sector = None + + class CapitalInvestOpportunityListingPageFactory( wagtail_factories.PageFactory ): diff --git a/tests/great_international/test_serializers.py b/tests/great_international/test_serializers.py index 91e227f9..a16fa222 100644 --- a/tests/great_international/test_serializers.py +++ b/tests/great_international/test_serializers.py @@ -34,7 +34,8 @@ AboutUkLandingPageFactory, InvestInternationalHomePageFactory, CapitalInvestRegionPageFactory, AboutUkRegionListingPageFactory, InvestRegionPageFactory, - InternationalTradeHomePageFactory) + InternationalTradeHomePageFactory, CapitalInvestRelatedSectorsFactory +) from great_international.models.capital_invest import ( CapitalInvestRelatedRegions, @@ -511,8 +512,7 @@ def test_capital_invest_landing_page_has_how_we_help( @pytest.mark.django_db -def test_opportunity_page_can_add_sector_as_related(rf, - international_root_page): +def test_opportunity_page_can_add_sector_as_related(rf, international_root_page): guide_landing_page = InternationalGuideLandingPageFactory( parent=international_root_page, @@ -524,15 +524,13 @@ def test_opportunity_page_can_add_sector_as_related(rf, slug='sector' ) - related_sector = CapitalInvestRelatedSectors( - related_sector=sector - ) - opportunity = CapitalInvestOpportunityPageFactory( parent=international_root_page, slug='opp', - related_sectors=[related_sector] + related_sectors=[] ) + related_sector = CapitalInvestRelatedSectorsFactory(related_sector=sector, page=opportunity) + opportunity.related_sector = related_sector opportunity_serializer = CapitalInvestOpportunityPageSerializer( instance=opportunity, @@ -558,15 +556,13 @@ def test_international_sector_page_gets_opps_with_sector_as_related( slug='sector' ) - related_sector = CapitalInvestRelatedSectors( - related_sector=sector - ) - opportunity = CapitalInvestOpportunityPageFactory( parent=international_root_page, slug='opp', - related_sectors=[related_sector] + related_sectors=[] ) + related_sector = CapitalInvestRelatedSectorsFactory(related_sector=sector, page=opportunity) + opportunity.related_sector = related_sector opportunity_serializer = CapitalInvestOpportunityPageSerializer( instance=opportunity, @@ -588,13 +584,13 @@ def test_international_sector_page_gets_opps_with_sector_as_related( @pytest.mark.django_db def test_opp_page_null_case_related_sector(rf, international_root_page): - related_sector = CapitalInvestRelatedSectors() - opportunity = CapitalInvestOpportunityPageFactory( parent=international_root_page, slug='opp', - related_sectors=[related_sector] + related_sectors=[] ) + related_sector = CapitalInvestRelatedSectorsFactory(page=opportunity) + opportunity.related_sector = related_sector opportunity_serializer = CapitalInvestOpportunityPageSerializer( instance=opportunity, @@ -606,9 +602,46 @@ def test_opp_page_null_case_related_sector(rf, international_root_page): @pytest.mark.django_db -def test_opp_page_null_case_related_sector2( - rf, international_root_page -): +def test_opp_page_related_random_opps(rf, international_root_page): + + guide_landing_page = InternationalGuideLandingPageFactory( + parent=international_root_page, + slug='page-slug', + ) + + sector = InternationalSectorPageFactory( + parent=guide_landing_page, + slug='sector' + ) + + opportunity = CapitalInvestOpportunityPageFactory( + parent=international_root_page, + slug='opp', + related_sectors=[] + ) + + related_sector = CapitalInvestRelatedSectorsFactory(related_sector=sector, page=opportunity) + opportunity.related_sectors = [related_sector] + + for i in range(3): + opp = CapitalInvestOpportunityPageFactory( + parent=international_root_page, + slug=f'opp{i}', + related_sectors=[related_sector] + ) + related_sector = CapitalInvestRelatedSectorsFactory(related_sector=sector, page=opp) + opp.related_sectors = [related_sector] + + serializer = CapitalInvestOpportunityPageSerializer( + instance=opportunity, + context={'request': rf.get('/')} + ) + + assert len(serializer.data['related_opportunities']) == 3 + + +@pytest.mark.django_db +def test_opp_page_null_case_related_sector2(rf, international_root_page): opportunity = CapitalInvestOpportunityPageFactory( parent=international_root_page, @@ -644,15 +677,13 @@ def test_international_sector_opportunity_null_case( slug='sectorB' ) - related_sector = CapitalInvestRelatedSectors( - related_sector=sector_a - ) - opportunity = CapitalInvestOpportunityPageFactory( parent=international_root_page, slug='opp', - related_sectors=[related_sector] + related_sectors=[] ) + related_sector = CapitalInvestRelatedSectorsFactory(related_sector=sector_a, page=opportunity) + opportunity.related_sector = related_sector opportunity_serializer = CapitalInvestOpportunityPageSerializer( instance=opportunity, @@ -685,12 +716,10 @@ def test_international_sector_opportunity_null_case2( slug='sector' ) - related_sector = CapitalInvestRelatedSectors() - opportunity = CapitalInvestOpportunityPageFactory( parent=international_root_page, slug='opp', - related_sectors=[related_sector] + related_sectors=[] ) opportunity_serializer = CapitalInvestOpportunityPageSerializer( @@ -953,30 +982,30 @@ def test_opportunity_page_gets_opportunities_with_same_sector(rf, international_ title='sector_title' ) - CapitalInvestOpportunityPageFactory( + ashton_green = CapitalInvestOpportunityPageFactory( parent=international_root_page, slug='ashton-green', title_en_gb='Ashton Green', - related_sectors=[ - CapitalInvestRelatedSectors(related_sector=sector) - ] + related_sectors=[] ) + related_sector = CapitalInvestRelatedSectorsFactory(related_sector=sector, page=ashton_green) + ashton_green.related_sector = related_sector - birmingham_opportuntiy = CapitalInvestOpportunityPageFactory( + birmingham = CapitalInvestOpportunityPageFactory( parent=international_root_page, slug='birimingham-curzon', title_en_gb='Birmingham Curzon', - related_sectors=[ - CapitalInvestRelatedSectors(related_sector=sector) - ] + related_sectors=[] ) + related_sector = CapitalInvestRelatedSectorsFactory(related_sector=sector, page=birmingham) + ashton_green.related_sector = related_sector - birmingham_serializer = CapitalInvestOpportunityPageSerializer( - instance=birmingham_opportuntiy, + serializer = CapitalInvestOpportunityPageSerializer( + instance=birmingham, context={'request': rf.get('/')} ) - related_opps = birmingham_serializer.data['related_opportunities'] + related_opps = serializer.data['related_opportunities'] assert len(related_opps) == 1 @@ -996,7 +1025,7 @@ def test_opportunity_page_null_case_gets_opportunities_with_same_sector(rf, inte title='sector_title' ) - related_sector = CapitalInvestRelatedSectors(related_sector=sector) + related_sector = CapitalInvestRelatedSectorsFactory(related_sector=sector) opportunity = CapitalInvestOpportunityPageFactory( parent=international_root_page, From 7e3e278e9252133ecfcd347eeb628e75bec60bfb Mon Sep 17 00:00:00 2001 From: Edie Pearce Date: Wed, 5 Feb 2020 13:15:35 +0000 Subject: [PATCH 09/10] Fix flake8 --- tests/great_international/test_serializers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/great_international/test_serializers.py b/tests/great_international/test_serializers.py index a16fa222..fe9cf38c 100644 --- a/tests/great_international/test_serializers.py +++ b/tests/great_international/test_serializers.py @@ -41,7 +41,6 @@ CapitalInvestRelatedRegions, CapitalInvestHomesInEnglandCardFieldsSummary, CapitalInvestRegionCardFieldsSummary, - CapitalInvestRelatedSectors, CapitalInvestRelatedSubSectors ) from great_international.models.great_international import ( From c523bdf1311efecf9ac9f3f4440435a947cc46d3 Mon Sep 17 00:00:00 2001 From: Edie Pearce Date: Wed, 5 Feb 2020 13:48:19 +0000 Subject: [PATCH 10/10] Fix country guide cta link migration --- export_readiness/migrations/0073_auto_20200203_1333.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/export_readiness/migrations/0073_auto_20200203_1333.py b/export_readiness/migrations/0073_auto_20200203_1333.py index a8d8d6c2..1ef8bd0c 100644 --- a/export_readiness/migrations/0073_auto_20200203_1333.py +++ b/export_readiness/migrations/0073_auto_20200203_1333.py @@ -20,6 +20,8 @@ def set_duties_and_custom_procedures_cta_link(apps, schema_editor): matches = pycountry.countries.search_fuzzy(guide.country.name) except LookupError: logger.warn(f'no country match for {guide.country.name}') + except AttributeError: + logger.warn(f'skipping {guide.title}') else: guide.duties_and_custom_procedures_cta_link = f'{url}{matches[0].alpha_2}' guide.save()