From a4d4364ab3995147a216d46ecbd65a4bf478be20 Mon Sep 17 00:00:00 2001 From: LuptonM Date: Thu, 2 Mar 2023 18:35:41 +0000 Subject: [PATCH 1/8] added serializer for map data for freeport map --- great_international/serializers.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/great_international/serializers.py b/great_international/serializers.py index 561d4a68..48c174e6 100644 --- a/great_international/serializers.py +++ b/great_international/serializers.py @@ -311,6 +311,25 @@ class InternationalArticlePageSerializer(BasePageSerializer): cta_link = serializers.CharField() tags = core_fields.TagsListField() + + freeport_data = serializers.SerializerMethodField() + # import pdb + # pdb.set_trace() + def get_freeport_data(self, instance): + # if instance.type_of_article == 'Freeport landing': + queryset = InvestmentOpportunityPage.objects.live().public().filter(investment_type__name = 'Freeport') + import pdb + # pdb.set_trace() + if not queryset: + return [] + + serializer = InvestmentOpportunityForListPageSerializer( + queryset, + many=True, + allow_null=True, + context=self.context + ) + return serializer.data class GreatMediaSerializer(serializers.Serializer): From 20c8444e06e1da0698b2a66cc3aa005be6db20c2 Mon Sep 17 00:00:00 2001 From: LuptonM Date: Wed, 8 Mar 2023 15:33:53 +0000 Subject: [PATCH 2/8] edit type of article panel --- great_international/panels/great_international.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/great_international/panels/great_international.py b/great_international/panels/great_international.py index 4566420c..fd82ddf1 100644 --- a/great_international/panels/great_international.py +++ b/great_international/panels/great_international.py @@ -283,7 +283,7 @@ class InternationalArticlePagePanels: content_panels = [ FieldPanel('title'), FieldPanel('article_title'), - FieldPanel('type_of_article'), + FieldPanel('type_of_article', widget=Select), ImageChooserPanel('hero_image'), MediaChooserPanel('hero_video'), MultiFieldPanel( @@ -312,7 +312,6 @@ class InternationalArticlePagePanels: ] settings_panels = [ - FieldPanel('type_of_article', widget=Select), FieldPanel('slug'), FieldPanel('tags', widget=CheckboxSelectMultiple) ] From 5e532533b13140ad4248cf3469aec7a1a2eeec86 Mon Sep 17 00:00:00 2001 From: LuptonM Date: Wed, 8 Mar 2023 15:36:18 +0000 Subject: [PATCH 3/8] remove stacktrace --- great_international/serializers.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/great_international/serializers.py b/great_international/serializers.py index 48c174e6..fdd59422 100644 --- a/great_international/serializers.py +++ b/great_international/serializers.py @@ -313,13 +313,10 @@ class InternationalArticlePageSerializer(BasePageSerializer): tags = core_fields.TagsListField() freeport_data = serializers.SerializerMethodField() - # import pdb - # pdb.set_trace() + def get_freeport_data(self, instance): - # if instance.type_of_article == 'Freeport landing': + if instance.type_of_article == 'Freeport landing': queryset = InvestmentOpportunityPage.objects.live().public().filter(investment_type__name = 'Freeport') - import pdb - # pdb.set_trace() if not queryset: return [] From 0b71f8d8f26e4e2ceff997e9e1f00a657bb7da73 Mon Sep 17 00:00:00 2001 From: LuptonM Date: Wed, 8 Mar 2023 15:56:41 +0000 Subject: [PATCH 4/8] flake8 issues fixed --- great_international/serializers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/great_international/serializers.py b/great_international/serializers.py index fdd59422..7a64ca4a 100644 --- a/great_international/serializers.py +++ b/great_international/serializers.py @@ -311,12 +311,12 @@ class InternationalArticlePageSerializer(BasePageSerializer): cta_link = serializers.CharField() tags = core_fields.TagsListField() - + freeport_data = serializers.SerializerMethodField() - + def get_freeport_data(self, instance): if instance.type_of_article == 'Freeport landing': - queryset = InvestmentOpportunityPage.objects.live().public().filter(investment_type__name = 'Freeport') + queryset = InvestmentOpportunityPage.objects.live().public().filter(investment_type__name='Freeport') if not queryset: return [] From 30ef43ac6d6294ec97f613e98246d38d1aee998f Mon Sep 17 00:00:00 2001 From: LuptonM Date: Fri, 10 Mar 2023 10:11:21 +0000 Subject: [PATCH 5/8] added freeport data tests --- tests/great_international/test_serializers.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/great_international/test_serializers.py b/tests/great_international/test_serializers.py index df67d3b6..62494773 100644 --- a/tests/great_international/test_serializers.py +++ b/tests/great_international/test_serializers.py @@ -18,6 +18,7 @@ InvestmentOpportunityForListPageSerializer, InternationalInvestmentSectorPageSerializer, InternationalInvestmentSubSectorPageSerializer, + InternationalArticlePageSerializer ) from tests.core.helpers import make_test_video from tests.great_international.factories import ( @@ -64,6 +65,12 @@ def fdi_investment_type(): return InvestmentTypeFactory( name=settings.FOREIGN_DIRECT_INVESTMENT_SNIPPET_LABEL_DEFAULT ) + +@pytest.fixture +def freeport_investment_type(): + return InvestmentTypeFactory( + name='Freeport' + ) @pytest.fixture @@ -1613,3 +1620,53 @@ def test_foreign_direct_investment_form_sucess_page_serializer( assert len(serializer.data['opportunity_list']) == 2 assert serializer.data['opportunity_list'][0]['meta']['slug'] == 'opp_1__fdi' assert serializer.data['opportunity_list'][1]['meta']['slug'] == 'opp_3__fdi' + + +@pytest.mark.django_db +def test_freeport_data( + rf, international_root_page, freeport_investment_type, non_fdi_investment_type +): + + + InvestmentOpportunityPageFactory.create_batch( + 2, + parent=international_root_page, + investment_type= freeport_investment_type + ) + + InvestmentOpportunityPageFactory.create_batch( + 2, + parent=international_root_page, + investment_type=non_fdi_investment_type + ) + + + opportunity = InternationalArticlePageFactory( + type_of_article ='Freeport landing' + ) + + freeport_data = InternationalArticlePageSerializer( + instance=opportunity, + ).get_freeport_data(instance=opportunity) + + assert len(freeport_data) == 2 + +@pytest.mark.django_db +def test_freeport_data_has_no_results( + rf, international_root_page, non_fdi_investment_type +): + InvestmentOpportunityPageFactory.create_batch( + 2, + parent=international_root_page, + investment_type=non_fdi_investment_type + ) + + opportunity = InternationalArticlePageFactory( + type_of_article ='Freeport landing' + ) + + freeport_data = InternationalArticlePageSerializer( + instance=opportunity, + ).get_freeport_data(instance=opportunity) + + assert freeport_data == [] \ No newline at end of file From 95e041de854d2418b708d98758e67093395fc136 Mon Sep 17 00:00:00 2001 From: LuptonM Date: Fri, 10 Mar 2023 10:13:42 +0000 Subject: [PATCH 6/8] removed redundant arg from test --- tests/great_international/test_serializers.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/great_international/test_serializers.py b/tests/great_international/test_serializers.py index 62494773..ef83078b 100644 --- a/tests/great_international/test_serializers.py +++ b/tests/great_international/test_serializers.py @@ -1623,9 +1623,7 @@ def test_foreign_direct_investment_form_sucess_page_serializer( @pytest.mark.django_db -def test_freeport_data( - rf, international_root_page, freeport_investment_type, non_fdi_investment_type -): +def test_freeport_data(international_root_page, freeport_investment_type, non_fdi_investment_type): InvestmentOpportunityPageFactory.create_batch( @@ -1652,9 +1650,7 @@ def test_freeport_data( assert len(freeport_data) == 2 @pytest.mark.django_db -def test_freeport_data_has_no_results( - rf, international_root_page, non_fdi_investment_type -): +def test_freeport_data_has_no_results(international_root_page, non_fdi_investment_type): InvestmentOpportunityPageFactory.create_batch( 2, parent=international_root_page, From 93727086f01c7b9c2dc02acee30b542c0de740be Mon Sep 17 00:00:00 2001 From: LuptonM Date: Fri, 10 Mar 2023 10:20:42 +0000 Subject: [PATCH 7/8] fixed flake8 issues --- tests/great_international/test_serializers.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/great_international/test_serializers.py b/tests/great_international/test_serializers.py index ef83078b..918d62ae 100644 --- a/tests/great_international/test_serializers.py +++ b/tests/great_international/test_serializers.py @@ -65,7 +65,8 @@ def fdi_investment_type(): return InvestmentTypeFactory( name=settings.FOREIGN_DIRECT_INVESTMENT_SNIPPET_LABEL_DEFAULT ) - + + @pytest.fixture def freeport_investment_type(): return InvestmentTypeFactory( @@ -1625,22 +1626,20 @@ def test_foreign_direct_investment_form_sucess_page_serializer( @pytest.mark.django_db def test_freeport_data(international_root_page, freeport_investment_type, non_fdi_investment_type): - InvestmentOpportunityPageFactory.create_batch( 2, parent=international_root_page, - investment_type= freeport_investment_type + investment_type=freeport_investment_type ) - + InvestmentOpportunityPageFactory.create_batch( 2, parent=international_root_page, investment_type=non_fdi_investment_type ) - opportunity = InternationalArticlePageFactory( - type_of_article ='Freeport landing' + type_of_article='Freeport landing' ) freeport_data = InternationalArticlePageSerializer( @@ -1649,6 +1648,7 @@ def test_freeport_data(international_root_page, freeport_investment_type, non_fd assert len(freeport_data) == 2 + @pytest.mark.django_db def test_freeport_data_has_no_results(international_root_page, non_fdi_investment_type): InvestmentOpportunityPageFactory.create_batch( @@ -1658,11 +1658,11 @@ def test_freeport_data_has_no_results(international_root_page, non_fdi_investmen ) opportunity = InternationalArticlePageFactory( - type_of_article ='Freeport landing' + type_of_article='Freeport landing' ) freeport_data = InternationalArticlePageSerializer( instance=opportunity, ).get_freeport_data(instance=opportunity) - assert freeport_data == [] \ No newline at end of file + assert freeport_data == [] From b037c268e7fadbbf377f080ee322ac4984a8f253 Mon Sep 17 00:00:00 2001 From: LuptonM Date: Fri, 10 Mar 2023 11:10:27 +0000 Subject: [PATCH 8/8] renamed page variable --- tests/great_international/test_serializers.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/great_international/test_serializers.py b/tests/great_international/test_serializers.py index 918d62ae..698d821b 100644 --- a/tests/great_international/test_serializers.py +++ b/tests/great_international/test_serializers.py @@ -1638,13 +1638,13 @@ def test_freeport_data(international_root_page, freeport_investment_type, non_fd investment_type=non_fdi_investment_type ) - opportunity = InternationalArticlePageFactory( + freeport_landing_page = InternationalArticlePageFactory( type_of_article='Freeport landing' ) freeport_data = InternationalArticlePageSerializer( - instance=opportunity, - ).get_freeport_data(instance=opportunity) + instance=freeport_landing_page, + ).get_freeport_data(instance=freeport_landing_page) assert len(freeport_data) == 2 @@ -1657,12 +1657,12 @@ def test_freeport_data_has_no_results(international_root_page, non_fdi_investmen investment_type=non_fdi_investment_type ) - opportunity = InternationalArticlePageFactory( + freeport_landing_page = InternationalArticlePageFactory( type_of_article='Freeport landing' ) freeport_data = InternationalArticlePageSerializer( - instance=opportunity, - ).get_freeport_data(instance=opportunity) + instance=freeport_landing_page, + ).get_freeport_data(instance=freeport_landing_page) assert freeport_data == []