Skip to content

Commit

Permalink
Merge pull request #1136 from uktrade/develop
Browse files Browse the repository at this point in the history
Release to UAT/Prod
  • Loading branch information
timothyPatterson authored Oct 6, 2023
2 parents 3bcf244 + 00122bf commit 5f3d8db
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 35 deletions.
32 changes: 12 additions & 20 deletions activitystream/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,21 @@ class WagtailPageSerializer(serializers.Serializer):
subtype = 'international'
operation = 'Update'

def get_cms_content_for_obj(self, obj):
try:
result = dict(
id=f'{self.prefix}:{self.subtype}:{obj.id}',
type=self.prefix,
title=obj.title,
url=settings.APP_URL_GREAT_INTERNATIONAL+'content'+obj.url,
seoTitle=obj.seo_title,
searchDescription=obj.search_description,
firstPublishedAt=obj.first_published_at.isoformat(),
lastPublishedAt=obj.last_published_at.isoformat(),
contentTypeId=obj.content_type_id,
content=f"{PageCache.get(obj.id, lang='en-gb')}",
)
except Exception as e:
result = {"error": f"Could not parse content for class {obj.specific_class}. Error: {e}"}

return result

def to_representation(self, obj):
return {
'id': f'{self.prefix}:{self.subtype}:{obj.id}:{self.operation}',
'type': self.operation,
'published': obj.last_published_at.isoformat(),
'object': self.get_cms_content_for_obj(obj),
'object': {
'id': f'{self.prefix}:{self.subtype}:{obj.id}',
'type': self.prefix,
'title': obj.title,
'seoTitle': obj.seo_title,
'url': f"{settings.APP_URL_GREAT_INTERNATIONAL}content{obj.url}",
'searchDescription': obj.search_description,
'firstPublishedAt': obj.first_published_at.isoformat(),
'lastPublishedAt': obj.last_published_at.isoformat(),
'contentTypeId': obj.content_type_id,
'content': f"{PageCache.get(obj.id, lang='en-gb')}",
},
}
2 changes: 1 addition & 1 deletion activitystream/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def list(self, request, *args, **kwargs):


class CMSContentActivityStreamView(ActivityStreamBaseView):
queryset = Page.objects.exclude(Q(live=False) | Q(first_published_at__isnull=True) | Q(last_published_at__isnull=True)) # noqa:E501
queryset = Page.objects.exclude(Q(live=False) | Q(first_published_at__isnull=True) | Q(last_published_at__isnull=True)).filter(Q(url_path__contains="/great-international-home/")) # noqa:E501
serializer_class = WagtailPageSerializer
pagination_class = ActivityStreamCMSContentPagination
filterset_class = ActivityStreamCMSContentFilter
Expand Down
14 changes: 0 additions & 14 deletions tests/activitystream/test_serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
from wagtail.models import Page
from django.conf import settings

from activitystream.serializers import WagtailPageSerializer
Expand Down Expand Up @@ -32,16 +31,3 @@ def test_wagtail_page_serializer(international_site):
'content': "None",
},
}


@pytest.mark.django_db
def test_error_thrown_for_invalid_page(international_site):
page = Page.objects.get(id=3)
invalid_page = page.copy()
invalid_page.id = None
invalid_page.title = None
invalid_page.first_published_at = None

serialized_article = WagtailPageSerializer().to_representation(invalid_page)

assert 'Could not parse content for class' in serialized_article['object']['error']
3 changes: 3 additions & 0 deletions tests/activitystream/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from rest_framework.reverse import reverse
from rest_framework.test import APIClient
from activitystream.authentication import NO_CREDENTIALS_MESSAGE
from wagtail.models import Page

URL = 'http://testserver' + reverse('activitystream:cms-content')
URL_INCORRECT_DOMAIN = 'http://incorrect' + reverse('activitystream:cms-content')
Expand Down Expand Up @@ -56,6 +57,8 @@ def test_site_pages_returned_with_authentication(api_client, en_locale):
"""If the Authorization and X-Forwarded-For headers are correct, then
the correct, and authentic, data is returned
"""
Page.objects.all().update(url_path='/great-international-home/')

sender = auth_sender()
response = api_client.get(
URL,
Expand Down

0 comments on commit 5f3d8db

Please sign in to comment.