diff --git a/activitystream/serializers.py b/activitystream/serializers.py index aa4a1092..8d4f7130 100644 --- a/activitystream/serializers.py +++ b/activitystream/serializers.py @@ -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')}", + }, } diff --git a/activitystream/views.py b/activitystream/views.py index d42c4379..40020b14 100644 --- a/activitystream/views.py +++ b/activitystream/views.py @@ -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 diff --git a/tests/activitystream/test_serializers.py b/tests/activitystream/test_serializers.py index 5b9a494f..9f16b65a 100644 --- a/tests/activitystream/test_serializers.py +++ b/tests/activitystream/test_serializers.py @@ -1,5 +1,4 @@ import pytest -from wagtail.models import Page from django.conf import settings from activitystream.serializers import WagtailPageSerializer @@ -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'] diff --git a/tests/activitystream/test_views.py b/tests/activitystream/test_views.py index d2451689..030ee98d 100644 --- a/tests/activitystream/test_views.py +++ b/tests/activitystream/test_views.py @@ -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') @@ -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,