1
0

test_util.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2021 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from synapse.config import ConfigError
  16. from synapse.config._util import validate_config
  17. from tests.unittest import TestCase
  18. class ValidateConfigTestCase(TestCase):
  19. """Test cases for synapse.config._util.validate_config"""
  20. def test_bad_object_in_array(self):
  21. """malformed objects within an array should be validated correctly"""
  22. # consider a structure:
  23. #
  24. # array_of_objs:
  25. # - r: 1
  26. # foo: 2
  27. #
  28. # - r: 2
  29. # bar: 3
  30. #
  31. # ... where each entry must contain an "r": check that the path
  32. # to the required item is correclty reported.
  33. schema = {
  34. "type": "object",
  35. "properties": {
  36. "array_of_objs": {
  37. "type": "array",
  38. "items": {"type": "object", "required": ["r"]},
  39. },
  40. },
  41. }
  42. with self.assertRaises(ConfigError) as c:
  43. validate_config(schema, {"array_of_objs": [{}]}, ("base",))
  44. self.assertEqual(c.exception.path, ["base", "array_of_objs", "<item 0>"])