toxygen/tests/tests.py

71 lines
2.1 KiB
Python
Raw Normal View History

from src.bootstrap import node_generator
2016-02-27 15:52:27 +00:00
from src.profile import *
2016-04-03 20:51:46 +00:00
from src.settings import ProfileHelper
from src.tox_dns import tox_dns
2016-07-01 20:15:00 +00:00
import src.toxencryptsave as encr
2016-02-17 21:32:15 +00:00
2016-02-18 16:15:38 +00:00
2016-07-01 20:15:00 +00:00
class TestProfile:
2016-02-18 16:15:38 +00:00
def test_search(self):
2016-02-25 20:40:00 +00:00
arr = ProfileHelper.find_profiles()
2016-03-06 12:44:52 +00:00
assert len(arr) >= 2
def test_open(self):
2016-05-15 10:39:03 +00:00
data = ProfileHelper(Settings.get_default_path(), 'alice').open_profile()
assert data
2016-02-23 11:11:00 +00:00
2016-07-01 20:15:00 +00:00
class TestTox:
2016-02-23 11:11:00 +00:00
def test_loading(self):
2016-05-15 10:39:03 +00:00
data = ProfileHelper(Settings.get_default_path(), 'alice').open_profile()
2016-02-23 11:11:00 +00:00
settings = Settings.get_default_settings()
tox = tox_factory(data, settings)
for data in node_generator():
tox.bootstrap(*data)
del tox
2016-02-25 12:11:14 +00:00
2016-03-06 12:44:52 +00:00
def test_creation(self):
2016-07-01 20:15:00 +00:00
name = b'Toxygen User'
status_message = b'Toxing on Toxygen'
2016-03-06 12:44:52 +00:00
tox = tox_factory()
tox.self_set_name(name)
tox.self_set_status_message(status_message)
data = tox.get_savedata()
del tox
2016-03-15 19:12:37 +00:00
tox = tox_factory(data)
2016-07-01 20:15:00 +00:00
assert tox.self_get_name() == str(name, 'utf-8')
assert tox.self_get_status_message() == str(status_message, 'utf-8')
2016-03-06 12:44:52 +00:00
2016-02-25 12:11:14 +00:00
def test_friend_list(self):
2016-05-15 10:39:03 +00:00
data = ProfileHelper(Settings.get_default_path(), 'bob').open_profile()
2016-02-25 12:11:14 +00:00
settings = Settings.get_default_settings()
tox = tox_factory(data, settings)
s = tox.self_get_friend_list()
2016-02-25 20:40:00 +00:00
size = tox.self_get_friend_list_size()
2016-05-15 10:39:03 +00:00
assert size <= 2
assert len(s) <= 2
2016-02-25 12:11:14 +00:00
del tox
2016-07-01 20:15:00 +00:00
class TestDNS:
def test_dns(self):
bot_id = '56A1ADE4B65B86BCD51CC73E2CD4E542179F47959FE3E0E21B4B0ACDADE51855D34D34D37CB5'
tox_id = tox_dns('groupbot@toxme.io')
assert tox_id == bot_id
2016-05-15 10:39:03 +00:00
2016-07-01 20:15:00 +00:00
class TestEncryption:
2016-05-15 10:39:03 +00:00
def test_encr_decr(self):
2016-07-01 20:15:00 +00:00
with open(settings.Settings.get_default_path() + '/alice.tox', 'rb') as fl:
2016-05-15 10:39:03 +00:00
data = fl.read()
2016-07-01 20:15:00 +00:00
lib = encr.ToxEncryptSave()
lib.set_password('easypassword')
2016-05-15 10:39:03 +00:00
copy_data = data[:]
data = lib.pass_encrypt(data)
data = lib.pass_decrypt(data)
assert copy_data == data