Пример #1
0
 def test_no_type(self):
     with pytest.raises(SwaggerValidationError):
         fuzz_parameters([(
             'no_type_parameter',
             {
                 'name': 'no_type_parameter',
             },
         )])
Пример #2
0
    def test_basic(self, mock_client):
        factory = fuzz_parameters(
            [(
                'key',
                {
                    'name': 'key',
                    'type': 'object',
                    'required': [
                        'b',
                    ],
                    'properties': {
                        'a': {
                            'type': 'boolean',
                        },
                        'b': {
                            'type': 'boolean',
                        },
                    },
                },
            )],
            'get_public_listing',
        )

        for _ in range(10):
            obj = factory.example()['key']
            assert obj['a'] in [None, True, False]
            assert obj['b'] in [True, False]
Пример #3
0
    def test_nested(self, mock_client):
        factory = fuzz_parameters(
            [(
                'key',
                {
                    'name': 'key',
                    'type': 'array',
                    'required': True,
                    'items': {
                        # This is the `parent_list`
                        'type': 'array',
                        'items': {
                            'type': 'boolean',
                            'required': False,
                        },
                    },
                },
            )],
            'get_public_listing',
        )

        for _ in range(10):
            for parent_list in factory.example()['key']:
                if parent_list is None:
                    # This is possible, because it's not required.
                    continue

                for item in parent_list:
                    assert item in [None, True, False]
Пример #4
0
    def test(self):
        factory = fuzz_parameters([(
            'key',
            {
                'type': 'string',
                'enum': ['foo', 'bar'],
            },
        )])

        assert_randomness(factory, ['foo', 'bar'])
Пример #5
0
    def test_fixture(self):
        def factory():
            return 'qux'

        fuzz_lightyear.register_factory('enumerated_field')(factory)

        factory = fuzz_parameters([(
            'enumerated_field',
            {
                'name': 'enumerated_field',
                'type': 'string',
                'enum': ['foo', 'bar'],
                'required': True,
            },
        )])

        assert factory.example()['enumerated_field'] == 'qux'
Пример #6
0
def test_booleans(mock_client, is_required):
    schema = {
        'name': 'key',
        'type': 'boolean',
    }
    if is_required:
        schema['required'] = True
    elif is_required is False:
        schema['required'] = False

    factory = fuzz_parameters([(
        'key',
        schema,
    )], 'get_public_listing')
    if is_required:
        assert_randomness(factory, [True, False])
    else:
        assert_randomness(factory, [None, True, False])
Пример #7
0
    def test_basic(self, mock_client):
        factory = fuzz_parameters([(
            'key',
            {
                'name': 'key',
                'type': 'array',
                'items': {
                    'type': 'boolean',
                },
            },
        )])

        for _ in range(10):
            item_list = factory.example()['key']
            if item_list is None:
                continue

            for item in item_list:
                assert item in [None, True, False]
Пример #8
0
def test_integers(mock_client):
    schema = {
        'name': 'key',
        'type': 'integer',
        'minimum': 0,
        'maximum': 3,
        'exclusiveMaximum': True,
    }

    factory = fuzz_parameters([(
        'key',
        schema,
    )], 'get_public_listing')

    assert_randomness(factory, [
        None,
        0,
        1,
        2,
    ])