def test_serializer_with_max_integer_values_should_work(self):
        # mock schema instance
        schema_reader = SchemaReader()

        with nested(
                patch.object(schema_reader,
                             'validate_object'),  # @UndefinedVariable
                patch.object(
                    schema_reader,
                    'get_schema_fields',
                )) as (validate_mock,
                       mock_schema_instance):  # @UndefinedVariable
            mock_schema_instance.return_value = [
                SchemaField(name='key1',
                            field_type='integer',
                            required=True,
                            min_value=1,
                            max_value=500),
                SchemaField(name='keycustom',
                            field_type='custom_obj',
                            required=True)
            ]

            class IntegersSerializers(SchemaSerializer):
                class Meta():
                    schema = 'schemaMock'

            serializer = IntegersSerializers(data={
                'key1': 12,
                'keycustom': 'test'
            })
            self.assertTrue(serializer.is_valid())
Beispiel #2
0
 def test_get_several_fields_from_object_should_return_different_SchemaField(
         self):
     schemaReader = SchemaReader()
     schema_fields = schemaReader.get_schema_fields('SeveralFieldsModel')
     self.assertEquals(4, len(schema_fields),
                       "Not all fields were recovered")
     for expected_field in [
             SchemaField(name='mytext',
                         field_type='string',
                         required=True,
                         min_length=1,
                         max_length=10),
             SchemaField(name='mynum',
                         field_type='integer',
                         required=True,
                         min_value=0,
                         max_value=100),
             SchemaField(name='mybool', field_type='boolean',
                         required=True),
             SchemaField(name='mydefault',
                         field_type='string',
                         required=True,
                         default='default_value')
     ]:
         for returned_field in schema_fields:
             if expected_field.name == returned_field.name:
                 self.assertEquals(
                     expected_field.required, returned_field.required,
                     "Invalid required recovered for {0}".format(
                         returned_field.name))
    def setUp(self):
        super(ClassesSerializerTests, self).setUp()
        mock_schema_instance = MagicMock(name='mock_schema_instance')
        mock_schema_instance.return_value = [
            SchemaField(name='_id', field_type='string', required=True, min_length=1, max_length=512),
            SchemaField(name='description', field_type='string', required=False),
            SchemaField(name='default_version', field_type='string', required=True, min_length=1, max_length=256)
        ]

        mock_get_schema_fields = MagicMock(name='mock_get_schema')
        mock_get_schema_fields.return_value = mock_schema_instance
        # mock schema instance
        schema_reader = SchemaReader()
        self.patcher_validate = patch.object(schema_reader, 'validate_object')  # @UndefinedVariable
        self.patcher_schema = patch.object(schema_reader,  # @UndefinedVariable
                                        'get_schema_fields', mock_schema_instance)
        self.patcher_schema.start()
        self.patcher_validate.start()
    def setUp(self):
        super(InstancesSerializerTests, self).setUp()
        mock_schema_instance = MagicMock(name='mock_schema_instance')
        mock_schema_instance.return_value = [
        SchemaField(name='uri', field_type='string', required=True, min_length=1, max_length=2048),
        SchemaField(name='version', field_type='string', required=True, min_length=1, max_length=256),
        SchemaField(name='environment', field_type='string', required=False, min_length=1, max_length=512,
                    default='production'),
        SchemaField(name='class_name', field_type='string', required=True, min_length=1, max_length=512)
        ]

        # mock schema instance
        schema_reader = SchemaReader()
        self.patcher_validate = patch.object(schema_reader, 'validate_object')  # @UndefinedVariable
        self.patcher_schema = patch.object(schema_reader,  # @UndefinedVariable
                                        'get_schema_fields', mock_schema_instance)
        self.patcher_schema.start()
        self.patcher_validate.start()
Beispiel #5
0
 def test_get_fields_from_object_should_return_valid_list_SchemaField(self):
     schemaReader = SchemaReader()
     schema_fields = schemaReader.get_schema_fields('OptionalProperties')
     self.assertEquals(4, len(schema_fields),
                       "Not all fields were recovered")
     for expected_field in [
             SchemaField(name='obi', field_type='string', required=False),
             SchemaField(name='oba', field_type='string', required=False),
             SchemaField(name='user', field_type='string', required=True),
             SchemaField(name='password',
                         field_type='string',
                         required=True)
     ]:
         for returned_field in schema_fields:
             if expected_field.name == returned_field.name:
                 self.assertEquals(
                     expected_field.required, returned_field.required,
                     "Invalid required recovered for {0}".format(
                         returned_field))
Beispiel #6
0
 def setUp(self):
     mock_schema_instance = MagicMock(name='mock_schema_instance')
     mock_schema_instance.return_value = [
         SchemaField(name='origin',
                     field_type='string',
                     required=True,
                     min_length=1),
         SchemaField(name='class_name',
                     field_type='string',
                     required=True,
                     min_length=1)
     ]
     # mock singleton schema
     schema_reader = SchemaReader()
     self.patcher_validate = patch.object(
         schema_reader, 'validate_object')  # @UndefinedVariable
     self.patcher_schema = patch.object(
         schema_reader,  # @UndefinedVariable
         'get_schema_fields',
         mock_schema_instance)
     self.patcher_schema.start()
     self.patcher_validate.start()
Beispiel #7
0
    def setUp(self):
        super(UserSerializerTests, self).setUp()
        mock_schema_instance = MagicMock(name='mock_schema_instance')
        mock_schema_instance.return_value = [
            SchemaField(name='username', field_type='string', required=True),
            SchemaField(name='password', field_type='string', required=True),
            SchemaField(name='is_admin',
                        field_type='boolean',
                        required=True,
                        default=False)
        ]

        mock_get_schema_fields = MagicMock(name='mock_get_schema')
        mock_get_schema_fields.return_value = mock_schema_instance
        # mock schema instance
        schema_reader = SchemaReader()
        self.patcher_validate = patch.object(
            schema_reader, 'validate_object')  # @UndefinedVariable
        self.patcher_schema = patch.object(
            schema_reader,  # @UndefinedVariable
            'get_schema_fields',
            mock_schema_instance)
        self.patcher_schema.start()
        self.patcher_validate.start()