tests update, bug fix

This commit is contained in:
ingvar1995 2016-07-01 23:15:00 +03:00
parent 5204cba58d
commit 18935c5b10
8 changed files with 26 additions and 43 deletions

View File

@ -6,7 +6,7 @@ class Node:
self._ip, self._port, self._tox_key, self.rand = ip, port, tox_key, rand
def get_data(self):
return self._ip, self._port, self._tox_key
return bytes(self._ip, 'utf-8'), self._port, self._tox_key
def node_generator():

View File

@ -3,7 +3,7 @@ from sqlite3 import connect
import settings
from os import chdir
import os.path
from toxencryptsave import LibToxEncryptSave
from toxencryptsave import ToxEncryptSave
PAGE_SIZE = 42
@ -22,7 +22,7 @@ class History:
chdir(settings.ProfileHelper.get_path())
path = settings.ProfileHelper.get_path() + self._name + '.hstr'
if os.path.exists(path):
decr = LibToxEncryptSave.get_instance()
decr = ToxEncryptSave.get_instance()
try:
with open(path, 'rb') as fin:
data = fin.read()
@ -40,7 +40,7 @@ class History:
db.close()
def save(self):
encr = LibToxEncryptSave.get_instance()
encr = ToxEncryptSave.get_instance()
if encr.has_password():
path = settings.ProfileHelper.get_path() + self._name + '.hstr'
with open(path, 'rb') as fin:
@ -54,7 +54,7 @@ class History:
new_path = directory + self._name + '.hstr'
with open(path, 'rb') as fin:
data = fin.read()
encr = LibToxEncryptSave.get_instance()
encr = ToxEncryptSave.get_instance()
if encr.has_password():
data = encr.pass_encrypt(data)
with open(new_path, 'wb') as fout:

View File

@ -36,7 +36,7 @@ class Toxygen:
Show password screen
"""
tmp = [data]
p = PasswordScreen(toxencryptsave.LibToxEncryptSave.get_instance(), tmp)
p = PasswordScreen(toxencryptsave.ToxEncryptSave.get_instance(), tmp)
p.show()
self.app.connect(self.app, QtCore.SIGNAL("lastWindowClosed()"), self.app, QtCore.SLOT("quit()"))
self.app.exec_()
@ -58,7 +58,7 @@ class Toxygen:
dark_style = fl.read()
app.setStyleSheet(dark_style)
encrypt_save = toxencryptsave.LibToxEncryptSave()
encrypt_save = toxencryptsave.ToxEncryptSave()
if self.path is not None:
path = os.path.dirname(self.path) + '/'

View File

@ -205,7 +205,7 @@ class ProfileSettings(CenteredWidget):
def new_password(self):
if self.password.text() == self.confirm_password.text():
if not len(self.password.text()) or len(self.password.text()) >= 8:
e = toxencryptsave.LibToxEncryptSave.get_instance()
e = toxencryptsave.ToxEncryptSave.get_instance()
e.set_password(self.password.text())
self.close()
else:

View File

@ -16,7 +16,7 @@ class PluginLoader(util.Singleton):
self._settings = settings
self._plugins = {} # dict. key - plugin unique short name, value - tuple (plugin instance, is active)
self._tox = tox
self._encr = toxencryptsave.LibToxEncryptSave.get_instance()
self._encr = toxencryptsave.ToxEncryptSave.get_instance()
def set_tox(self, tox):
"""

View File

@ -4,7 +4,7 @@ import os
import locale
from util import Singleton, curr_directory, log
import pyaudio
from toxencryptsave import LibToxEncryptSave
from toxencryptsave import ToxEncryptSave
import smileys
@ -20,7 +20,7 @@ class Settings(dict, Singleton):
if os.path.isfile(self.path):
with open(self.path, 'rb') as fl:
data = fl.read()
inst = LibToxEncryptSave.get_instance()
inst = ToxEncryptSave.get_instance()
try:
if inst.is_data_encrypted(data):
data = inst.pass_decrypt(data)
@ -145,7 +145,7 @@ class Settings(dict, Singleton):
def save(self):
text = json.dumps(self)
inst = LibToxEncryptSave.get_instance()
inst = ToxEncryptSave.get_instance()
if inst.has_password():
text = bytes(inst.pass_encrypt(bytes(text, 'utf-8')))
else:
@ -224,7 +224,7 @@ class ProfileHelper(Singleton):
return self._directory
def save_profile(self, data):
inst = LibToxEncryptSave.get_instance()
inst = ToxEncryptSave.get_instance()
if inst.has_password():
data = inst.pass_encrypt(data)
with open(self._path, 'wb') as fl:

View File

@ -34,7 +34,7 @@ TOX_ERR_DECRYPTION = {
TOX_PASS_ENCRYPTION_EXTRA_LENGTH = 80
class LibToxEncryptSave(util.Singleton):
class ToxEncryptSave(util.Singleton):
libtoxencryptsave = libtox.LibToxEncryptSave()

View File

@ -2,39 +2,21 @@ from src.bootstrap import node_generator
from src.profile import *
from src.settings import ProfileHelper
from src.tox_dns import tox_dns
from src.toxencryptsave import LibToxEncryptSave
import src.toxencryptsave as encr
class TestProfile():
class TestProfile:
def test_search(self):
arr = ProfileHelper.find_profiles()
assert arr
assert len(arr) >= 2
def test_open(self):
data = ProfileHelper(Settings.get_default_path(), 'alice').open_profile()
assert data
def test_open_save(self):
data = ProfileHelper(Settings.get_default_path(), 'alice').open_profile()
ProfileHelper.get_instance().save_profile(data)
new_data = ProfileHelper(Settings.get_default_path(), 'alice').open_profile()
assert new_data == data
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():
class TestTox:
def test_loading(self):
data = ProfileHelper(Settings.get_default_path(), 'alice').open_profile()
@ -45,16 +27,16 @@ class TestTox():
del tox
def test_creation(self):
name = 'Toxygen User'
status_message = 'Toxing on Toxygen'
name = b'Toxygen User'
status_message = b'Toxing on Toxygen'
tox = tox_factory()
tox.self_set_name(name)
tox.self_set_status_message(status_message)
data = tox.get_savedata()
del tox
tox = tox_factory(data)
assert tox.self_get_name() == name
assert tox.self_get_status_message() == status_message
assert tox.self_get_name() == str(name, 'utf-8')
assert tox.self_get_status_message() == str(status_message, 'utf-8')
def test_friend_list(self):
data = ProfileHelper(Settings.get_default_path(), 'bob').open_profile()
@ -67,7 +49,7 @@ class TestTox():
del tox
class TestDNS():
class TestDNS:
def test_dns(self):
bot_id = '56A1ADE4B65B86BCD51CC73E2CD4E542179F47959FE3E0E21B4B0ACDADE51855D34D34D37CB5'
@ -75,12 +57,13 @@ class TestDNS():
assert tox_id == bot_id
class TestEncryption():
class TestEncryption:
def test_encr_decr(self):
with open(settings.Settings.get_default_path() + '/alice.tox') as fl:
with open(settings.Settings.get_default_path() + '/alice.tox', 'rb') as fl:
data = fl.read()
lib = LibToxEncryptSave('easypassword')
lib = encr.ToxEncryptSave()
lib.set_password('easypassword')
copy_data = data[:]
data = lib.pass_encrypt(data)
data = lib.pass_decrypt(data)