test_schema.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. from borgmatic.config import schema as module
  2. def test_get_properties_with_simple_object():
  3. schema = {
  4. 'type': 'object',
  5. 'properties': dict(
  6. [
  7. ('field1', {'example': 'Example'}),
  8. ]
  9. ),
  10. }
  11. assert module.get_properties(schema) == schema['properties']
  12. def test_get_properties_merges_oneof_list_properties():
  13. schema = {
  14. 'type': 'object',
  15. 'oneOf': [
  16. {
  17. 'properties': dict(
  18. [
  19. ('field1', {'example': 'Example 1'}),
  20. ('field2', {'example': 'Example 2'}),
  21. ]
  22. ),
  23. },
  24. {
  25. 'properties': dict(
  26. [
  27. ('field2', {'example': 'Example 2'}),
  28. ('field3', {'example': 'Example 3'}),
  29. ]
  30. ),
  31. },
  32. ],
  33. }
  34. assert module.get_properties(schema) == dict(
  35. schema['oneOf'][0]['properties'], **schema['oneOf'][1]['properties']
  36. )
  37. def test_get_properties_interleaves_oneof_list_properties():
  38. schema = {
  39. 'type': 'object',
  40. 'oneOf': [
  41. {
  42. 'properties': dict(
  43. [
  44. ('field1', {'example': 'Example 1'}),
  45. ('field2', {'example': 'Example 2'}),
  46. ('field3', {'example': 'Example 3'}),
  47. ]
  48. ),
  49. },
  50. {
  51. 'properties': dict(
  52. [
  53. ('field4', {'example': 'Example 4'}),
  54. ('field5', {'example': 'Example 5'}),
  55. ]
  56. ),
  57. },
  58. ],
  59. }
  60. assert module.get_properties(schema) == dict(
  61. [
  62. ('field1', {'example': 'Example 1'}),
  63. ('field4', {'example': 'Example 4'}),
  64. ('field2', {'example': 'Example 2'}),
  65. ('field5', {'example': 'Example 5'}),
  66. ('field3', {'example': 'Example 3'}),
  67. ]
  68. )