2
0

test_json.py 889 B

12345678910111213141516171819202122232425
  1. from flexmock import flexmock
  2. from borgmatic.actions import json as module
  3. def test_parse_json_loads_json_from_string():
  4. flexmock(module.json).should_receive('loads').and_return({'repository': {'id': 'foo'}})
  5. assert module.parse_json('{"repository": {"id": "foo"}}', label=None) == {
  6. 'repository': {'id': 'foo', 'label': ''}
  7. }
  8. def test_parse_json_injects_label_into_parsed_data():
  9. flexmock(module.json).should_receive('loads').and_return({'repository': {'id': 'foo'}})
  10. assert module.parse_json('{"repository": {"id": "foo"}}', label='bar') == {
  11. 'repository': {'id': 'foo', 'label': 'bar'}
  12. }
  13. def test_parse_json_injects_nothing_when_repository_missing():
  14. flexmock(module.json).should_receive('loads').and_return({'stuff': {'id': 'foo'}})
  15. assert module.parse_json('{"stuff": {"id": "foo"}}', label='bar') == {'stuff': {'id': 'foo'}}