def test_related_page_field_deserializer_invalid_slug(rf):
    missing_slug = 'some-missing-slug'

    serialized_data = {'(page)related_page_one': missing_slug}

    request = RequestWithMessages()

    UpstreamModelSerilaizer.deserialize(serialized_data, request)

    message_string = (
        f"Related page with the slug {missing_slug} could not be "
        "found in this environment. Please create it then "
        "add it as one of this page's related pages.")

    assert request.get_message_strings()[0] == message_string
def test_upstream_model_deserializer(page):
    serialized_data = {
        '(list)search_filter_sector': page.search_filter_sector[0],
    }
    actual = UpstreamModelSerilaizer.deserialize(serialized_data)

    assert actual['search_filter_sector'] == page.search_filter_sector
def test_upstream_model_deserializer(mock_get_form_kwargs, rf, page):
    serialized_data = {
        '(list)search_filter_sector': page.search_filter_sector[0],
    }

    actual = UpstreamModelSerilaizer.deserialize(serialized_data, rf)

    assert actual['search_filter_sector'] == page.search_filter_sector
def test_document_field_deserializer(high_potential_opportunity_page):
    serialized_data = {
        '(document)pdf_document':
        (high_potential_opportunity_page.pdf_document.file.name)
    }
    actual = UpstreamModelSerilaizer.deserialize(serialized_data)

    assert actual['pdf_document'] == (
        high_potential_opportunity_page.pdf_document.pk)
def test_related_page_field_deserializer_invalid_slug(article_page):
    serialized_data = {'(page)related_page_one': 'some-missing-slug'}

    with pytest.raises(ValidationError):
        UpstreamModelSerilaizer.deserialize(serialized_data)
def test_related_page_field_deserializer(article_page):
    serialized_data = {'(page)related_page_one': article_page.slug}
    actual = UpstreamModelSerilaizer.deserialize(serialized_data)

    assert actual['related_page_one'] == article_page
def test_related_page_field_serialize(country_guide_page):

    data = UpstreamModelSerilaizer.serialize(country_guide_page)

    assert data['(page)related_page_one'] == (
        country_guide_page.related_page_one.slug)
def test_document_field_serialize(high_potential_opportunity_page):

    data = UpstreamModelSerilaizer.serialize(high_potential_opportunity_page)

    assert data['(document)pdf_document'] == (
        high_potential_opportunity_page.pdf_document.file.name)
def test_upstream_model_serializer(page):
    data = UpstreamModelSerilaizer.serialize(page)
    assert data['(image)introduction_column_one_icon'] == (
        page.introduction_column_one_icon.file.name)
    assert data['(list)search_filter_sector'] == page.search_filter_sector[0]
Example #10
0
 def get_form_kwargs(self):
     kwargs = super().get_form_kwargs()
     data = UpstreamModelSerilaizer.deserialize(kwargs['data'],
                                                request=self.request)
     kwargs['data'] = data
     return kwargs
Example #11
0
 def serialize_object(self):
     instance = self.get_object()
     return UpstreamModelSerilaizer.serialize(instance).items()