Esempio n. 1
0
    def test_create(self, country_nested_filter, country_get):
        exists = MagicMock()
        exists.exists.return_value = True
        country_nested_filter.return_value = exists
        country_get.return_value = Country_model(iso="ttt")

        address = Address_factory.build()
        address.country = Country_model(iso="ttt")

        serializer = Address_serializer(address)
        serializer = Address_serializer(data=serializer.data)
        is_valid = serializer.is_valid()
        self.assertTrue(is_valid, serializer.errors)
        address_result = serializer.save()
        self.assertEqual(address.pk, address_result.pk)
        self.assertEqual(address.description, address_result.description)
        self.assertEqual(address.street, address_result.street)
        self.assertEqual(address.external_number, address_result.external_number)
        self.assertEqual(address.internal_number, address_result.internal_number)
        self.assertEqual(address.neighbour, address_result.neighbour)
        self.assertEqual(address.city, address_result.city)
        self.assertEqual(address.state, address_result.state)
        self.assertEqual(address.zipcode, address_result.zipcode)
        self.assertEqual(address.address_type, address_result.address_type)

        self.assertEqual(address_result.country.iso, country_get.return_value.iso)
Esempio n. 2
0
    def test_create_country_not_exists(self, country_nested_filter, country_get):
        exists = MagicMock()
        exists.exists.return_value = False
        country_nested_filter.return_value = exists
        country_get.return_value = Country_model(iso="ttt")

        address = Address_factory.build()
        address.country = Country_model(iso="ttt")

        serializer = Address_serializer(address)
        serializer = Address_serializer(data=serializer.data)
        is_valid = serializer.is_valid()
        self.assertFalse(is_valid, serializer.errors)
        self.assertEqual(serializer.errors["country"]["iso"], ["No se encontro el pais con el iso 'ttt'"])
Esempio n. 3
0
    def test_update_country(self, country_nested_filter, country_get):
        exists = MagicMock()
        exists.exists.return_value = True
        country_nested_filter.return_value = exists
        country_get.return_value = Country_model(iso="tex")

        address = Address_factory.build()
        address.country = Country_model(iso="ttt")

        serializer = Address_serializer(address)
        data = serializer.data
        data["country"] = {"iso": "tex"}
        serializer = Address_serializer(address, data=data)
        is_valid = serializer.is_valid()
        self.assertTrue(is_valid, serializer.errors)
        address_result = serializer.save()
        self.assertEqual(address_result.country.iso, country_get.return_value.iso)