def test_multiple(self): obj = MultiCountry(countries="AU,NZ") self.assertEqual(len(obj.countries), 2) for country in obj.countries: self.assertTrue(isinstance(country, fields.Country)) self.assertEqual(obj.countries[0], "AU") self.assertEqual(obj.countries[1], "NZ")
def test_validate_multiple_invalid(self): person = MultiCountry(countries=[":(", "AU"]) self.assertRaises(validators.ValidationError, person.full_clean)
def test_validate_multiple_empty(self): person = MultiCountry() self.assertRaises(validators.ValidationError, person.full_clean)
def test_validate_multiple_uneditable(self): person = MultiCountry(countries="NZ", uneditable_countries="xx") person.full_clean()
def test_multi_serialize(self): mc = MultiCountry(countries="NZ,AU") serializer = MultiCountrySerializer(mc) self.assertEqual(serializer.data, {"countries": ["NZ", "AU"]})
def test_set_country(self): obj = MultiCountry() obj.countries = fields.Country("NZ") self.assertEqual(obj.countries, ["NZ"])
def test_set_text(self): obj = MultiCountry() obj.countries = "NZ,AU" self.assertEqual(obj.countries, ["NZ", "AU"])
def test_single(self): obj = MultiCountry(countries="NZ") self.assertEqual(len(obj.countries), 1) self.assertTrue(isinstance(obj.countries[0], fields.Country)) self.assertEqual(obj.countries[0], "NZ")
def test_validate_multiple_uneditable(self): person = MultiCountry(countries='NZ', uneditable_countries='xx') person.full_clean()
def test_validate_multiple(self): person = MultiCountry(countries=['NZ', 'AU']) person.full_clean()
def test_multi_serialize(self): mc = MultiCountry(countries='NZ,AU') serializer = MultiCountrySerializer(mc) self.assertEqual(serializer.data, {'countries': ['NZ', 'AU']})
def test_set_countries(self): obj = MultiCountry() obj.countries = [fields.Country("NZ"), fields.Country("AU")] self.assertEqual(obj.countries, ["NZ", "AU"])
def test_set_list(self): obj = MultiCountry() obj.countries = ["NZ", "AU"] self.assertEqual(obj.countries, ["NZ", "AU"])
def test_empty(self): obj = MultiCountry() self.assertEqual(obj.countries, [])
def test_set_text(self): obj = MultiCountry() obj.countries = 'NZ,AU' self.assertEqual(obj.countries, ['NZ', 'AU'])
def test_set_list(self): obj = MultiCountry() obj.countries = ['NZ', 'AU'] self.assertEqual(obj.countries, ['NZ', 'AU'])
def test_set_country(self): obj = MultiCountry() obj.countries = fields.Country('NZ') self.assertEqual(obj.countries, ['NZ'])
def test_set_countries(self): obj = MultiCountry() obj.countries = [fields.Country('NZ'), fields.Country('AU')] self.assertEqual(obj.countries, ['NZ', 'AU'])
def test_validate_multiple(self): person = MultiCountry(countries=["NZ", "AU"]) person.full_clean()
def test_multi_serialize_empty(self): mc = MultiCountry(countries="") serializer = MultiCountrySerializer(mc) self.assertEqual(serializer.data, {"countries": []})