added is_friend test for onionrusers and fixed bug where isFriend was setting instead of getting the value
parent
ae8d1fc5ea
commit
d13d9a3039
|
@ -87,7 +87,7 @@ class OnionrUser:
|
||||||
keydb.userinfo.set_user_info(self.publicKey, 'trust', newTrust)
|
keydb.userinfo.set_user_info(self.publicKey, 'trust', newTrust)
|
||||||
|
|
||||||
def isFriend(self):
|
def isFriend(self):
|
||||||
if keydb.userinfo.set_peer_info(self.publicKey, 'trust') == 1:
|
if keydb.userinfo.get_user_info(self.publicKey, 'trust') == 1:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,10 @@ class OnionrUserTests(unittest.TestCase):
|
||||||
'''
|
'''
|
||||||
Tests both the onionrusers class and the contactmanager (which inherits it)
|
Tests both the onionrusers class and the contactmanager (which inherits it)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def test_users(self):
|
def test_users(self):
|
||||||
keypair = crypto.generate()
|
keypair = crypto.generate()
|
||||||
onionrusers.OnionrUser(keypair[0])
|
onionrusers.OnionrUser(keypair[0])
|
||||||
return
|
|
||||||
|
|
||||||
def test_contact_init_no_save(self):
|
def test_contact_init_no_save(self):
|
||||||
contact = crypto.generate()[0]
|
contact = crypto.generate()[0]
|
||||||
|
@ -34,7 +33,7 @@ class OnionrUserTests(unittest.TestCase):
|
||||||
contact = crypto.generate()[0]
|
contact = crypto.generate()[0]
|
||||||
contact = contactmanager.ContactManager(contact, saveUser=True)
|
contact = contactmanager.ContactManager(contact, saveUser=True)
|
||||||
self.assertTrue(contact.publicKey in keydb.listkeys.list_peers())
|
self.assertTrue(contact.publicKey in keydb.listkeys.list_peers())
|
||||||
|
|
||||||
def test_contact_set_info(self):
|
def test_contact_set_info(self):
|
||||||
contact = crypto.generate()[0]
|
contact = crypto.generate()[0]
|
||||||
contact = contactmanager.ContactManager(contact, saveUser=True)
|
contact = contactmanager.ContactManager(contact, saveUser=True)
|
||||||
|
@ -44,10 +43,10 @@ class OnionrUserTests(unittest.TestCase):
|
||||||
|
|
||||||
with open(fileLocation, 'r') as data:
|
with open(fileLocation, 'r') as data:
|
||||||
data = data.read()
|
data = data.read()
|
||||||
|
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
self.assertEqual(data['alias'], 'bob')
|
self.assertEqual(data['alias'], 'bob')
|
||||||
|
|
||||||
def test_contact_get_info(self):
|
def test_contact_get_info(self):
|
||||||
contact = crypto.generate()[0]
|
contact = crypto.generate()[0]
|
||||||
contact = contactmanager.ContactManager(contact, saveUser=True)
|
contact = contactmanager.ContactManager(contact, saveUser=True)
|
||||||
|
@ -55,18 +54,25 @@ class OnionrUserTests(unittest.TestCase):
|
||||||
|
|
||||||
with open(fileLocation, 'w') as contactFile:
|
with open(fileLocation, 'w') as contactFile:
|
||||||
contactFile.write('{"alias": "bob"}')
|
contactFile.write('{"alias": "bob"}')
|
||||||
|
|
||||||
self.assertEqual(contact.get_info('alias', forceReload=True), 'bob')
|
self.assertEqual(contact.get_info('alias', forceReload=True), 'bob')
|
||||||
self.assertEqual(contact.get_info('fail', forceReload=True), None)
|
self.assertEqual(contact.get_info('fail', forceReload=True), None)
|
||||||
self.assertEqual(contact.get_info('fail'), None)
|
self.assertEqual(contact.get_info('fail'), None)
|
||||||
|
|
||||||
|
def test_is_friend(self):
|
||||||
|
contact = crypto.generate()[0]
|
||||||
|
contact = onionrusers.OnionrUser(contact, saveUser=True)
|
||||||
|
self.assertFalse(contact.isFriend())
|
||||||
|
contact.setTrust(1)
|
||||||
|
self.assertTrue(contact.isFriend())
|
||||||
|
|
||||||
def test_encrypt(self):
|
def test_encrypt(self):
|
||||||
contactPair = crypto.generate()
|
contactPair = crypto.generate()
|
||||||
contact = contactmanager.ContactManager(contactPair[0], saveUser=True)
|
contact = contactmanager.ContactManager(contactPair[0], saveUser=True)
|
||||||
encrypted = contact.encrypt('test')
|
encrypted = contact.encrypt('test')
|
||||||
decrypted = crypto.encryption.pub_key_decrypt(encrypted, privkey=contactPair[1], encodedData=True).decode()
|
decrypted = crypto.encryption.pub_key_decrypt(encrypted, privkey=contactPair[1], encodedData=True).decode()
|
||||||
self.assertEqual('test', decrypted)
|
self.assertEqual('test', decrypted)
|
||||||
|
|
||||||
def test_delete_contact(self):
|
def test_delete_contact(self):
|
||||||
contact = crypto.generate()[0]
|
contact = crypto.generate()[0]
|
||||||
contact = contactmanager.ContactManager(contact, saveUser=True)
|
contact = contactmanager.ContactManager(contact, saveUser=True)
|
||||||
|
|
Loading…
Reference in New Issue