Esempio n. 1
0
    def test_validate_raises(self):
        field = ListField(EmailField, required=True)
        field.set_value(value=['no_email'])
        self.assertRaises(SerializerFieldValueError, field.validate)

        field = ListField(EmailField, required=True)
        self.assertRaises(SerializerFieldValueError, field.validate)
Esempio n. 2
0
    def test_validate_raises(self):
        field = ListField(EmailField, required=True)
        field.set_value(value=['no_email'])
        self.assertRaises(SerializerFieldValueError, field.validate)

        field = ListField(EmailField, required=True)
        self.assertRaises(SerializerFieldValueError, field.validate)
Esempio n. 3
0
 def test_set_value(self):
     uuids = [
         '0203a23f-032c-46be-a1fa-c85fd0284b4c',
         'd2e6a469-a4fd-415e-8c22-b8d73856a714',
         '8832f5cd-c024-49ce-b27a-8d6e388f3b08'
     ]
     field = ListField(UUIDField, required=True)
     field.set_value(value=uuids)
     field.validate()
     self.assertIn('0203a23f-032c-46be-a1fa-c85fd0284b4c'.upper(),
                   field.to_native())
     self.assertIn('d2e6a469-a4fd-415e-8c22-b8d73856a714'.upper(),
                   field.to_native())
     self.assertIn('8832f5cd-c024-49ce-b27a-8d6e388f3b08'.upper(),
                   field.to_native())
     self.assertIn(uuid.UUID('0203a23f-032c-46be-a1fa-c85fd0284b4c'),
                   field.to_python())
     self.assertIn(uuid.UUID('d2e6a469-a4fd-415e-8c22-b8d73856a714'),
                   field.to_python())
     self.assertIn(uuid.UUID('8832f5cd-c024-49ce-b27a-8d6e388f3b08'),
                   field.to_python())
     self.assertEqual(len(field), 3)
     self.assertEqual(uuid.UUID('0203a23f-032c-46be-a1fa-c85fd0284b4c'),
                      field[0])
     self.assertEqual(uuid.UUID('d2e6a469-a4fd-415e-8c22-b8d73856a714'),
                      field[1])
     self.assertEqual(uuid.UUID('8832f5cd-c024-49ce-b27a-8d6e388f3b08'),
                      field[2])
Esempio n. 4
0
 def test_validate_raises(self):
     uuids = [
         '1203a23f-032c-46be-a1fa-c85fd0284b4c',
         '22e6a469-a4fd-415e-8c22-b8d73856a714', 'no_uuid_value'
     ]
     field = ListField(UUIDField, required=True)
     field.set_value(value=uuids)
     self.assertRaises(SerializerFieldValueError, field.validate)
Esempio n. 5
0
 def test_validate_raises(self):
     uuids = [
         '1203a23f-032c-46be-a1fa-c85fd0284b4c',
         '22e6a469-a4fd-415e-8c22-b8d73856a714',
         'no_uuid_value'
     ]
     field = ListField(UUIDField, required=True)
     field.set_value(value=uuids)
     self.assertRaises(SerializerFieldValueError, field.validate)
Esempio n. 6
0
 def test_append(self):
     uuids = [
         '1203a23f-032c-46be-a1fa-c85fd0284b4c',
     ]
     field = ListField(UUIDField, required=True)
     field.set_value(value=uuids)
     self.assertEqual(len(field), 1)
     field.append(uuid.UUID('4832f5cd-c024-49ce-b27a-8d6e388f3b08'))
     self.assertEqual(len(field), 2)
     field.validate()
     self.assertEqual(uuid.UUID('1203a23f-032c-46be-a1fa-c85fd0284b4c'), field[0])
     self.assertEqual(uuid.UUID('4832f5cd-c024-49ce-b27a-8d6e388f3b08'), field[1])
Esempio n. 7
0
 def test_append(self):
     uuids = [
         '1203a23f-032c-46be-a1fa-c85fd0284b4c',
     ]
     field = ListField(UUIDField, required=True)
     field.set_value(value=uuids)
     self.assertEqual(len(field), 1)
     field.append(uuid.UUID('4832f5cd-c024-49ce-b27a-8d6e388f3b08'))
     self.assertEqual(len(field), 2)
     field.validate()
     self.assertEqual(uuid.UUID('1203a23f-032c-46be-a1fa-c85fd0284b4c'),
                      field[0])
     self.assertEqual(uuid.UUID('4832f5cd-c024-49ce-b27a-8d6e388f3b08'),
                      field[1])
Esempio n. 8
0
 def test_set_list_index(self):
     uuids = [
         '1203a23f-032c-46be-a1fa-c85fd0284b4c',
         '22e6a469-a4fd-415e-8c22-b8d73856a714',
         'no_uuid_value'
     ]
     field = ListField(UUIDField, required=True)
     field.set_value(value=uuids)
     self.assertRaises(SerializerFieldValueError, field.validate)
     field[2] = '3832f5cd-c024-49ce-b27a-8d6e388f3b08'
     field.validate()
     self.assertEqual(len(field), 3)
     self.assertEqual(uuid.UUID('1203a23f-032c-46be-a1fa-c85fd0284b4c'), field[0])
     self.assertEqual(uuid.UUID('22e6a469-a4fd-415e-8c22-b8d73856a714'), field[1])
     self.assertEqual(uuid.UUID('3832f5cd-c024-49ce-b27a-8d6e388f3b08'), field[2])
Esempio n. 9
0
 def test_set_value(self):
     emails = [
         '*****@*****.**', '*****@*****.**', '*****@*****.**',
         '*****@*****.**'
     ]
     field = ListField(EmailField, required=True)
     field.set_value(value=emails)
     field.validate()
     self.assertIn('*****@*****.**', field.to_native())
     self.assertIn('*****@*****.**', field.to_python())
     self.assertEqual(len(field), 4)
     self.assertEqual('*****@*****.**', field[0])
     self.assertEqual('*****@*****.**', field[1])
     self.assertEqual('*****@*****.**', field[2])
     self.assertEqual('*****@*****.**', field[3])
     for email in field:
         self.assertIn(email, emails)
Esempio n. 10
0
 def test_set_list_index(self):
     uuids = [
         '1203a23f-032c-46be-a1fa-c85fd0284b4c',
         '22e6a469-a4fd-415e-8c22-b8d73856a714', 'no_uuid_value'
     ]
     field = ListField(UUIDField, required=True)
     field.set_value(value=uuids)
     self.assertRaises(SerializerFieldValueError, field.validate)
     field[2] = '3832f5cd-c024-49ce-b27a-8d6e388f3b08'
     field.validate()
     self.assertEqual(len(field), 3)
     self.assertEqual(uuid.UUID('1203a23f-032c-46be-a1fa-c85fd0284b4c'),
                      field[0])
     self.assertEqual(uuid.UUID('22e6a469-a4fd-415e-8c22-b8d73856a714'),
                      field[1])
     self.assertEqual(uuid.UUID('3832f5cd-c024-49ce-b27a-8d6e388f3b08'),
                      field[2])
Esempio n. 11
0
 def test_set_value(self):
     emails = [
         '*****@*****.**',
         '*****@*****.**',
         '*****@*****.**',
         '*****@*****.**'
     ]
     field = ListField(EmailField, required=True)
     field.set_value(value=emails)
     field.validate()
     self.assertIn('*****@*****.**', field.to_native())
     self.assertIn('*****@*****.**', field.to_python())
     self.assertEqual(len(field), 4)
     self.assertEqual('*****@*****.**', field[0])
     self.assertEqual('*****@*****.**', field[1])
     self.assertEqual('*****@*****.**', field[2])
     self.assertEqual('*****@*****.**', field[3])
     for email in field:
         self.assertIn(email, emails)
Esempio n. 12
0
 def test_set_value(self):
     uuids = [
         '0203a23f-032c-46be-a1fa-c85fd0284b4c',
         'd2e6a469-a4fd-415e-8c22-b8d73856a714',
         '8832f5cd-c024-49ce-b27a-8d6e388f3b08'
     ]
     field = ListField(UUIDField, required=True)
     field.set_value(value=uuids)
     field.validate()
     self.assertIn('0203a23f-032c-46be-a1fa-c85fd0284b4c'.upper(), field.to_native())
     self.assertIn('d2e6a469-a4fd-415e-8c22-b8d73856a714'.upper(), field.to_native())
     self.assertIn('8832f5cd-c024-49ce-b27a-8d6e388f3b08'.upper(), field.to_native())
     self.assertIn(uuid.UUID('0203a23f-032c-46be-a1fa-c85fd0284b4c'), field.to_python())
     self.assertIn(uuid.UUID('d2e6a469-a4fd-415e-8c22-b8d73856a714'), field.to_python())
     self.assertIn(uuid.UUID('8832f5cd-c024-49ce-b27a-8d6e388f3b08'), field.to_python())
     self.assertEqual(len(field), 3)
     self.assertEqual(uuid.UUID('0203a23f-032c-46be-a1fa-c85fd0284b4c'), field[0])
     self.assertEqual(uuid.UUID('d2e6a469-a4fd-415e-8c22-b8d73856a714'), field[1])
     self.assertEqual(uuid.UUID('8832f5cd-c024-49ce-b27a-8d6e388f3b08'), field[2])