<commit_before>from django.contrib.gis.geos import Point
from django.test import RequestFactory, TestCase
from unittest import skip

from api.country import serializers
from geodata.factory import geodata_factory


class TestCountrySerializers(TestCase):
    request_dummy = RequestFactory().get('/')

    @skip
    def test_CountrySerializer(self):
        country = geodata_factory.CountryFactory.build(
            code='NL',
            name='Netherlands',
            alt_name='Nederland',
            language='en',
            dac_country_code=1,
            iso3='NLD',
            alpha3='NLD',
            fips10='FIPS',
            center_longlat=Point(5.45, 52.3),
        )
        serializer = serializers.CountrySerializer(
            country,
            context={'request': self.request_dummy}
        )

        assert serializer.data['code'] == country.code,\
            """
            'country.code' should be serialized to a field called 'code'
            """
        assert serializer.data['name'] == country.name,\
            """
            'country.name' should be serialized to a field called 'name'
            """
        assert serializer.data[
                'numerical_code_un'
            ] == country.numerical_code_un,\
            """
            'country.numerical_code_un' should be serialized to a field called
            'numerical_code_un'
            """
        assert serializer.data['name'] == country.name,\
            """
            'country.name' should be serialized to a field called 'name'
            """
        assert serializer.data['alt_name'] == country.alt_name,\
            """
            'country.alt_name' should be serialized to a field called
            'alt_name'
            """
        assert serializer.data['language'] == country.language,\
            """
            'country.language' should be serialized to a field called
            'language'
            """
        assert serializer.data[
                'dac_country_code'
            ] == country.dac_country_code,\
            """
            'country.dac_country_code' should be serialized to a field called
            'dac_country_code'
            """
        assert serializer.data['iso3'] == country.iso3,\
            """
            'country.iso3' should be serialized to a field called 'iso3'
            """
        assert serializer.data['alpha3'] == country.alpha3,\
            """
            'country.alpha3' should be serialized to a field called 'alpha3'
            """
        assert serializer.data['fips10'] == country.fips10,\
            """
            'country.fips10' should be serialized to a field called 'fips10'
            """

        required_fields = (
            'url',
            'code',
            'pk',
            'numerical_code_un',
            'name',
            'alt_name',
            'language',
            'region',
            'un_region',
            'unesco_region',
            'dac_country_code',
            'iso3',
            'alpha3',
            'fips10',
            'data_source',
            'activities',
            'location',
            'polygon',
        )
        assertion_msg = "the field '{0}' should be in the serialized country"
        for field in required_fields:
            assert field in serializer.data, assertion_msg.format(field)
<commit_msg>fix: flake8 error<commit_after>from unittest import skip

from django.contrib.gis.geos import Point
from django.test import RequestFactory, TestCase

from api.country import serializers
from geodata.factory import geodata_factory


class TestCountrySerializers(TestCase):
    request_dummy = RequestFactory().get('/')

    @skip
    def test_CountrySerializer(self):
        country = geodata_factory.CountryFactory.build(
            code='NL',
            name='Netherlands',
            alt_name='Nederland',
            language='en',
            dac_country_code=1,
            iso3='NLD',
            alpha3='NLD',
            fips10='FIPS',
            center_longlat=Point(5.45, 52.3),
        )
        serializer = serializers.CountrySerializer(
            country,
            context={'request': self.request_dummy}
        )

        assert serializer.data['code'] == country.code,\
            """
            'country.code' should be serialized to a field called 'code'
            """
        assert serializer.data['name'] == country.name,\
            """
            'country.name' should be serialized to a field called 'name'
            """
        assert serializer.data[
                'numerical_code_un'
            ] == country.numerical_code_un,\
            """
            'country.numerical_code_un' should be serialized to a field called
            'numerical_code_un'
            """
        assert serializer.data['name'] == country.name,\
            """
            'country.name' should be serialized to a field called 'name'
            """
        assert serializer.data['alt_name'] == country.alt_name,\
            """
            'country.alt_name' should be serialized to a field called
            'alt_name'
            """
        assert serializer.data['language'] == country.language,\
            """
            'country.language' should be serialized to a field called
            'language'
            """
        assert serializer.data[
                'dac_country_code'
            ] == country.dac_country_code,\
            """
            'country.dac_country_code' should be serialized to a field called
            'dac_country_code'
            """
        assert serializer.data['iso3'] == country.iso3,\
            """
            'country.iso3' should be serialized to a field called 'iso3'
            """
        assert serializer.data['alpha3'] == country.alpha3,\
            """
            'country.alpha3' should be serialized to a field called 'alpha3'
            """
        assert serializer.data['fips10'] == country.fips10,\
            """
            'country.fips10' should be serialized to a field called 'fips10'
            """

        required_fields = (
            'url',
            'code',
            'pk',
            'numerical_code_un',
            'name',
            'alt_name',
            'language',
            'region',
            'un_region',
            'unesco_region',
            'dac_country_code',
            'iso3',
            'alpha3',
            'fips10',
            'data_source',
            'activities',
            'location',
            'polygon',
        )
        assertion_msg = "the field '{0}' should be in the serialized country"
        for field in required_fields:
            assert field in serializer.data, assertion_msg.format(field)

{'fraction_non_alphanumeric': 0.10692570072667952, 'fraction_numerical': 0.009639626279104255, 'mean_word_length': 1.613953488372093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2884584', 'n_tokens_mistral': 1767, 'n_tokens_neox': 1730, 'n_words': 412}