def test_modify_value(): json = { "One": { "user": "******", "password": "******", "url": "url1", "other": "other1" }, "Two": { "user": "******", "password": "******", "url": "url2", "other": "other2" } } jm = JSONManager(json) x = jm.modify_values("One", {"user": "******"}) assert x == { "One": { "user": "******", "password": "******", "url": "url1", "other": "other1" }, "Two": { "user": "******", "password": "******", "url": "url2", "other": "other2" } }
def modify_content(self, id, json_content): if (os.path.isfile(self.gpg.get_file())): jm = JSONManager(json.loads(str(self.gpg.decrypt_content()))) else: jm = JSONManager(json.loads('{}')) jkv = jm.modify_values(id, json.loads(str(json_content))) jkv = json.dumps(jkv) self.gpg.encrypt_content(jkv)
def test_modify_values_does_not_exist(): json = { "One": { "user": "******", "password": "******", "url": "url1", "other": "other1" }, "Two": { "user": "******", "password": "******", "url": "url2", "other": "other2" } } jm = JSONManager(json) with pytest.raises(KeyError): x = jm.modify_values("One", {"aaaa": "user3", "password": "******"})