Skip to content

Commit

Permalink
Merge pull request #1071 from uktrade/feature/freeportMap
Browse files Browse the repository at this point in the history
Added freeport data into article page serialiser
  • Loading branch information
LuptonM authored Mar 10, 2023
2 parents cffa0bd + b037c26 commit b893ba9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
3 changes: 1 addition & 2 deletions great_international/panels/great_international.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -312,7 +312,6 @@ class InternationalArticlePagePanels:
]

settings_panels = [
FieldPanel('type_of_article', widget=Select),
FieldPanel('slug'),
FieldPanel('tags', widget=CheckboxSelectMultiple)
]
Expand Down
16 changes: 16 additions & 0 deletions great_international/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,22 @@ class InternationalArticlePageSerializer(BasePageSerializer):

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')
if not queryset:
return []

serializer = InvestmentOpportunityForListPageSerializer(
queryset,
many=True,
allow_null=True,
context=self.context
)
return serializer.data


class GreatMediaSerializer(serializers.Serializer):
title = serializers.CharField()
Expand Down
53 changes: 53 additions & 0 deletions tests/great_international/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
InvestmentOpportunityForListPageSerializer,
InternationalInvestmentSectorPageSerializer,
InternationalInvestmentSubSectorPageSerializer,
InternationalArticlePageSerializer
)
from tests.core.helpers import make_test_video
from tests.great_international.factories import (
Expand Down Expand Up @@ -66,6 +67,13 @@ def fdi_investment_type():
)


@pytest.fixture
def freeport_investment_type():
return InvestmentTypeFactory(
name='Freeport'
)


@pytest.fixture
def non_fdi_investment_type():
InvestmentTypeFactory(
Expand Down Expand Up @@ -1613,3 +1621,48 @@ 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(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
)

freeport_landing_page = InternationalArticlePageFactory(
type_of_article='Freeport landing'
)

freeport_data = InternationalArticlePageSerializer(
instance=freeport_landing_page,
).get_freeport_data(instance=freeport_landing_page)

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(
2,
parent=international_root_page,
investment_type=non_fdi_investment_type
)

freeport_landing_page = InternationalArticlePageFactory(
type_of_article='Freeport landing'
)

freeport_data = InternationalArticlePageSerializer(
instance=freeport_landing_page,
).get_freeport_data(instance=freeport_landing_page)

assert freeport_data == []

0 comments on commit b893ba9

Please sign in to comment.