Example #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)
Example #2
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)
Example #3
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)
Example #4
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])
Example #5
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)
Example #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])
Example #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])
Example #8
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])
Example #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)
Example #10
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)
Example #11
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])
Example #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])