Пример #1
0
 def test_nested_can_raise_nested_invalid(self):
     data = {'a': {'a': 'b'}}
     data = {'a': [{'a': [1, 2]}, {'a': {}}]}
     nested_schema = ('a', iterables.AllItems(types.integer))
     schema = ('a', iterables.AllItems(nested_schema))
     with raises(Invalid) as exc:
         validate(data, schema)
     error = exc.value.args[0]
     assert 'did not pass validation against callable: integer'
     assert exc.value.reason == 'expected a list but got dict'
Пример #2
0
 def test_nested_raises_nested_invalid(self):
     data = {'a': [{'a': ['a']}, {'b': 'c'}]}
     nested_schema = iterables.MultiIterable(('a', ['b']), ('b', 'c'))
     schema = ('a', iterables.AllItems(nested_schema))
     with raises(Invalid) as exc:
         validate(data, schema)
     assert exc.value.reason == 'expected a list but got dict'
Пример #3
0
 def test_expecting_list_error(self):
     data = 4
     schema = 1
     all_items = iterables.AllItems(schema)
     with raises(Invalid) as exc:
         all_items(data, [])
     assert 'expected a list but got int' == exc.value.reason
Пример #4
0
 def test_all_items_fail(self):
     data = [1, 1, 3, 1]
     schema = 1
     all_items = iterables.AllItems(schema)
     with raises(Invalid) as exc:
         all_items(data, [])
     error = exc.value.args[0]
     assert '-> list[2] item did not match 1' in error
Пример #5
0
 def test_all_items_fail_on_non_lists(self):
     data = 4
     schema = 1
     all_items = iterables.AllItems(schema)
     with raises(Invalid) as exc:
         all_items(data, [])
     error = exc.value.args[0]
     assert 'top level did not pass validation against callable: AllItems' in error
Пример #6
0
 def test_hybrid_delegates_when_dict_or_list(self):
     # send off to Recursive when isinstance(value, (dict, list))
     data = {'a': ['a']}
     hybrid = Hybrid(types.string, iterables.AllItems('b'))
     schema = ('a', hybrid)
     with raises(Invalid) as exc:
         validate(data, schema)
     error = exc.value.args[0]
     assert "list[0] item did not match 'b'" in error
Пример #7
0
    def test_traverser_returns_the_iterable_leaf_if_seen(self):
        data = {'a': {'b': [1, 1, 1, 1]}}
        schema = ('a', ('b', iterables.AllItems(2)))
        with raises(Invalid) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert '-> a -> b -> list[0] item did not match 2' in error
Пример #8
0
 def test_fails_when_missing_items(self):
     data = [{"host": "example.com"}]
     schema = (("host", types.string), ("interface", types.string))
     all_items = iterables.AllItems(schema)
     with raises(Invalid) as exc:
         all_items(data, [])
     error = exc.value.args[0]
     assert "-> list[0] -> item[1] did not match 'interface'" in error
     assert "(required item in schema is missing: interface)" in error
Пример #9
0
    def test_all_items_fail_uses_first_invalid(self):
        data = [3, 5, 2, 3]
        schema = 1
        all_items = iterables.AllItems(schema)
        with raises(Invalid) as exc:
            all_items(data, [])

        error = exc.value.args[0]
        assert '-> list[0] item did not match 1' in error
Пример #10
0
 def test_all_items_pass(self):
     data = {'a': [1, 2, 3, 4, 5]}
     schema = ('a', iterables.AllItems(types.integer))
     assert validate(data, schema) is None
Пример #11
0
 def test_hybrid_delegates_when_dict_or_empty_list(self):
     # send off to Recursive when isinstance(value, (dict, list))
     data = {'a': []}
     hybrid = Hybrid(types.string, iterables.AllItems('b'))
     schema = ('a', hybrid)
     assert validate(data, schema) is None
Пример #12
0
    ("monitor_interface", validate_monitor_options),
    ("public_network", types.string),
)

rados_options = (
    ("radosgw_address", validate_rados_options),
    ("radosgw_address_block", validate_rados_options),
    ("radosgw_interface", validate_rados_options),
)

osd_options = (
    (optional("dmcrypt"), validate_dmcrypt_bool_value),
    (optional("osd_auto_discovery"), types.boolean),
)

lvm_batch_scenario = ("devices", iterables.AllItems(types.string))

lvm_filestore_scenario = ("lvm_volumes",
                          iterables.AllItems((
                              (optional('crush_device_class'), types.string),
                              ('data', types.string),
                              (optional('data_vg'), types.string),
                              ('journal', types.string),
                              (optional('journal_vg'), types.string),
                          )))

lvm_bluestore_scenario = ("lvm_volumes",
                          iterables.AllItems((
                              (optional('crush_device_class'), types.string),
                              ('data', types.string),
                              (optional('data_vg'), types.string),
Пример #13
0
 def test_all_items_pass(self):
     data = [1, 1, 1, 1]
     schema = 1
     all_items = iterables.AllItems(schema)
     assert all_items(data, []) is None