示例#1
0
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
示例#3
0
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)
示例#6
0
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] == ''
示例#7
0
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'
示例#8
0
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": "******"})
示例#9
0
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")
示例#10
0
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"
        }
    }
示例#11
0
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"
            })
示例#12
0
def test_delete_from_empty_json():
    json = {}
    jm = JSONManager(json)
    with pytest.raises(KeyError):
        x = jm.delete_entry("Two")
示例#13
0
def test_get_keys_no_json():
    json = "Error"
    jm = JSONManager(json)
    with pytest.raises(ValueError):
        x = jm.get_keys()
示例#14
0
def test_get_keys_empty():
    json = {}
    jm = JSONManager(json)
    x = jm.get_keys()
    assert x == []
示例#15
0
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)
示例#18
0
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()
示例#20
0
def test_delete_element_does_not_exist():
    json = {"One": 1}
    jm = JSONManager(json)
    with pytest.raises(KeyError):
        x = jm.delete_entry("Two")
示例#21
0
def test_get_keys():
    json = {"One": 1, "Two": 2}
    jm = JSONManager(json)
    x = jm.get_keys()
    assert x == ["One", "Two"]