toxygen/tests/tests.py
2016-02-27 18:52:27 +03:00

79 lines
2.1 KiB
Python

from src.settings import Settings
from src.util import bin_to_string, string_to_bin
import sys
from src.bootstrap import node_generator
from src.profile import *
import os
class TestSettings():
def test_creation(self):
s = Settings()
assert s['ipv6_enabled'] is not None
assert s['notifications'] is not None
def test_with_delete(self):
path = Settings.get_default_path() + 'toxygen.json'
os.remove(path)
Settings()
assert os.path.exists(path)
class TestProfile():
def test_search(self):
arr = ProfileHelper.find_profiles()
assert arr
def test_open(self):
data = ProfileHelper.open_profile(Settings.get_default_path(), 'tox_save')
assert data
def test_open_save(self):
data = ProfileHelper.open_profile(Settings.get_default_path(), 'tox_save')
ProfileHelper.save_profile(data)
new_data = ProfileHelper.open_profile(Settings.get_default_path(), 'tox_save')
assert new_data == data
class TestUtils():
def test_convert(self):
id = 'C4CEB8C7AC607C6B374E2E782B3C00EA3A63B80D4910B8649CCACDD19F260819'
data = string_to_bin(id)
new_id = bin_to_string(data)
assert id == new_id
class TestNodeGen():
def test_generator(self):
for elem in node_generator():
assert len(elem) == 3
def test_ports(self):
for elem in node_generator():
assert elem[1] in [33445, 443, 5190, 2306, 1813]
class TestTox():
def test_loading(self):
data = ProfileHelper.open_profile(Settings.get_default_path(), 'alice')
settings = Settings.get_default_settings()
tox = tox_factory(data, settings)
for data in node_generator():
tox.bootstrap(*data)
del tox
def test_friend_list(self):
data = ProfileHelper.open_profile(Settings.get_default_path(), 'bob')
settings = Settings.get_default_settings()
tox = tox_factory(data, settings)
s = tox.self_get_friend_list()
size = tox.self_get_friend_list_size()
assert size == 2
assert len(s) == 2
del tox