Exemplo n.º 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"
        }
    }
Exemplo n.º 2
0
 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
Exemplo n.º 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"
        }
    }
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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)
Exemplo n.º 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] == ''
Exemplo n.º 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'
Exemplo 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": "******"})
Exemplo n.º 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")
Exemplo n.º 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"
        }
    }
Exemplo n.º 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"
            })
Exemplo n.º 12
0
def test_delete_from_empty_json():
    json = {}
    jm = JSONManager(json)
    with pytest.raises(KeyError):
        x = jm.delete_entry("Two")
Exemplo n.º 13
0
def test_get_keys_no_json():
    json = "Error"
    jm = JSONManager(json)
    with pytest.raises(ValueError):
        x = jm.get_keys()
Exemplo n.º 14
0
def test_get_keys_empty():
    json = {}
    jm = JSONManager(json)
    x = jm.get_keys()
    assert x == []
Exemplo n.º 15
0
def test_delete_last_element():
    json = {"One": 1}
    jm = JSONManager(json)
    x = jm.delete_entry("One")
    assert x == {}
Exemplo n.º 16
0
 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)
Exemplo n.º 17
0
 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)
Exemplo n.º 18
0
def test_delete_element():
    json = {"One": 1, "Two": 2}
    jm = JSONManager(json)
    x = jm.delete_entry("Two")
    assert x == {"One": True}
Exemplo n.º 19
0
 def get_keys(self):
     jm = JSONManager(json.loads(str(self.gpg.decrypt_content())))
     return jm.get_keys()
Exemplo n.º 20
0
def test_delete_element_does_not_exist():
    json = {"One": 1}
    jm = JSONManager(json)
    with pytest.raises(KeyError):
        x = jm.delete_entry("Two")
Exemplo n.º 21
0
def test_get_keys():
    json = {"One": 1, "Two": 2}
    jm = JSONManager(json)
    x = jm.get_keys()
    assert x == ["One", "Two"]