def test_modify_id(): json = { "One": { "user": "******", "password": "******", "url": "url1", "other": "other1" }, "Two": { "user": "******", "password": "******", "url": "url2", "other": "other2" } } jm = JSONManager(json) x = jm.modify_id("One", "Three") assert x == { "Three": { "user": "******", "password": "******", "url": "url1", "other": "other1" }, "Two": { "user": "******", "password": "******", "url": "url2", "other": "other2" } }
def get_key_value(self, key, option): jm = JSONManager(json.loads(str(self.gpg.decrypt_content()))) jm.print_values(key, option) try: pass except Exception as e: raise e
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 add_content_id_json(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.add(id, json.loads(str(json_content))) jkv = json.dumps(jkv) self.gpg.encrypt_content(jkv)
def test_fix_json_2(): json = {"user": "******", "password": "******", "no": "aha"} jm = JSONManager(json) x = jm.fix_json(j.dumps(json)) for i in ['user', 'password', 'url', 'other']: if (i in json): assert x[i] == json[i] else: assert x[i] == ''
def test_print_values(capsys): json = { "One": { "user": "******", "password": "******", "url": "url1", "other": "other1" } } jm = JSONManager(json) jm.print_values('One', 'all') out, err = capsys.readouterr() assert out == 'User: user1\nPassword: password1\nUrl: url1\nOther: other1\n'
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": "******"})
def test_modify_id_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_id("Four", "Three")
def test_add_value(): json = { "One": { "user": "******", "password": "******", "url": "url1", "other": "other1" }, "Two": { "user": "******", "password": "******", "url": "url2", "other": "other2" } } jm = JSONManager(json) x = jm.add("Three", { "user": "******", "password": "******", "url": "url3", "other": "other3" }) assert x == { "One": { "user": "******", "password": "******", "url": "url1", "other": "other1" }, "Two": { "user": "******", "password": "******", "url": "url2", "other": "other2" }, "Three": { "user": "******", "password": "******", "url": "url3", "other": "other3" } }
def test_add_value_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.add( "Two", { "user": "******", "password": "******", "url": "url3", "other": "other3" })
def test_delete_from_empty_json(): json = {} jm = JSONManager(json) with pytest.raises(KeyError): x = jm.delete_entry("Two")
def test_get_keys_no_json(): json = "Error" jm = JSONManager(json) with pytest.raises(ValueError): x = jm.get_keys()
def test_get_keys_empty(): json = {} jm = JSONManager(json) x = jm.get_keys() assert x == []
def test_delete_last_element(): json = {"One": 1} jm = JSONManager(json) x = jm.delete_entry("One") assert x == {}
def del_id(self, id): jm = JSONManager(json.loads(str(self.gpg.decrypt_content()))) jkv = json.dumps(jm.delete_entry(id)) self.gpg.encrypt_content(jkv)
def modify_id(self, old_id, new_id): jm = JSONManager(json.loads(str(self.gpg.decrypt_content()))) jkv = json.dumps(jm.modify_id(old_id, new_id)) self.gpg.encrypt_content(jkv)
def test_delete_element(): json = {"One": 1, "Two": 2} jm = JSONManager(json) x = jm.delete_entry("Two") assert x == {"One": True}
def get_keys(self): jm = JSONManager(json.loads(str(self.gpg.decrypt_content()))) return jm.get_keys()
def test_delete_element_does_not_exist(): json = {"One": 1} jm = JSONManager(json) with pytest.raises(KeyError): x = jm.delete_entry("Two")
def test_get_keys(): json = {"One": 1, "Two": 2} jm = JSONManager(json) x = jm.get_keys() assert x == ["One", "Two"]