tests update, bug fix
This commit is contained in:
parent
5204cba58d
commit
18935c5b10
@ -6,7 +6,7 @@ class Node:
|
|||||||
self._ip, self._port, self._tox_key, self.rand = ip, port, tox_key, rand
|
self._ip, self._port, self._tox_key, self.rand = ip, port, tox_key, rand
|
||||||
|
|
||||||
def get_data(self):
|
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():
|
def node_generator():
|
||||||
|
@ -3,7 +3,7 @@ from sqlite3 import connect
|
|||||||
import settings
|
import settings
|
||||||
from os import chdir
|
from os import chdir
|
||||||
import os.path
|
import os.path
|
||||||
from toxencryptsave import LibToxEncryptSave
|
from toxencryptsave import ToxEncryptSave
|
||||||
|
|
||||||
|
|
||||||
PAGE_SIZE = 42
|
PAGE_SIZE = 42
|
||||||
@ -22,7 +22,7 @@ class History:
|
|||||||
chdir(settings.ProfileHelper.get_path())
|
chdir(settings.ProfileHelper.get_path())
|
||||||
path = settings.ProfileHelper.get_path() + self._name + '.hstr'
|
path = settings.ProfileHelper.get_path() + self._name + '.hstr'
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
decr = LibToxEncryptSave.get_instance()
|
decr = ToxEncryptSave.get_instance()
|
||||||
try:
|
try:
|
||||||
with open(path, 'rb') as fin:
|
with open(path, 'rb') as fin:
|
||||||
data = fin.read()
|
data = fin.read()
|
||||||
@ -40,7 +40,7 @@ class History:
|
|||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
encr = LibToxEncryptSave.get_instance()
|
encr = ToxEncryptSave.get_instance()
|
||||||
if encr.has_password():
|
if encr.has_password():
|
||||||
path = settings.ProfileHelper.get_path() + self._name + '.hstr'
|
path = settings.ProfileHelper.get_path() + self._name + '.hstr'
|
||||||
with open(path, 'rb') as fin:
|
with open(path, 'rb') as fin:
|
||||||
@ -54,7 +54,7 @@ class History:
|
|||||||
new_path = directory + self._name + '.hstr'
|
new_path = directory + self._name + '.hstr'
|
||||||
with open(path, 'rb') as fin:
|
with open(path, 'rb') as fin:
|
||||||
data = fin.read()
|
data = fin.read()
|
||||||
encr = LibToxEncryptSave.get_instance()
|
encr = ToxEncryptSave.get_instance()
|
||||||
if encr.has_password():
|
if encr.has_password():
|
||||||
data = encr.pass_encrypt(data)
|
data = encr.pass_encrypt(data)
|
||||||
with open(new_path, 'wb') as fout:
|
with open(new_path, 'wb') as fout:
|
||||||
|
@ -36,7 +36,7 @@ class Toxygen:
|
|||||||
Show password screen
|
Show password screen
|
||||||
"""
|
"""
|
||||||
tmp = [data]
|
tmp = [data]
|
||||||
p = PasswordScreen(toxencryptsave.LibToxEncryptSave.get_instance(), tmp)
|
p = PasswordScreen(toxencryptsave.ToxEncryptSave.get_instance(), tmp)
|
||||||
p.show()
|
p.show()
|
||||||
self.app.connect(self.app, QtCore.SIGNAL("lastWindowClosed()"), self.app, QtCore.SLOT("quit()"))
|
self.app.connect(self.app, QtCore.SIGNAL("lastWindowClosed()"), self.app, QtCore.SLOT("quit()"))
|
||||||
self.app.exec_()
|
self.app.exec_()
|
||||||
@ -58,7 +58,7 @@ class Toxygen:
|
|||||||
dark_style = fl.read()
|
dark_style = fl.read()
|
||||||
app.setStyleSheet(dark_style)
|
app.setStyleSheet(dark_style)
|
||||||
|
|
||||||
encrypt_save = toxencryptsave.LibToxEncryptSave()
|
encrypt_save = toxencryptsave.ToxEncryptSave()
|
||||||
|
|
||||||
if self.path is not None:
|
if self.path is not None:
|
||||||
path = os.path.dirname(self.path) + '/'
|
path = os.path.dirname(self.path) + '/'
|
||||||
|
@ -205,7 +205,7 @@ class ProfileSettings(CenteredWidget):
|
|||||||
def new_password(self):
|
def new_password(self):
|
||||||
if self.password.text() == self.confirm_password.text():
|
if self.password.text() == self.confirm_password.text():
|
||||||
if not len(self.password.text()) or len(self.password.text()) >= 8:
|
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())
|
e.set_password(self.password.text())
|
||||||
self.close()
|
self.close()
|
||||||
else:
|
else:
|
||||||
|
@ -16,7 +16,7 @@ class PluginLoader(util.Singleton):
|
|||||||
self._settings = settings
|
self._settings = settings
|
||||||
self._plugins = {} # dict. key - plugin unique short name, value - tuple (plugin instance, is active)
|
self._plugins = {} # dict. key - plugin unique short name, value - tuple (plugin instance, is active)
|
||||||
self._tox = tox
|
self._tox = tox
|
||||||
self._encr = toxencryptsave.LibToxEncryptSave.get_instance()
|
self._encr = toxencryptsave.ToxEncryptSave.get_instance()
|
||||||
|
|
||||||
def set_tox(self, tox):
|
def set_tox(self, tox):
|
||||||
"""
|
"""
|
||||||
|
@ -4,7 +4,7 @@ import os
|
|||||||
import locale
|
import locale
|
||||||
from util import Singleton, curr_directory, log
|
from util import Singleton, curr_directory, log
|
||||||
import pyaudio
|
import pyaudio
|
||||||
from toxencryptsave import LibToxEncryptSave
|
from toxencryptsave import ToxEncryptSave
|
||||||
import smileys
|
import smileys
|
||||||
|
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ class Settings(dict, Singleton):
|
|||||||
if os.path.isfile(self.path):
|
if os.path.isfile(self.path):
|
||||||
with open(self.path, 'rb') as fl:
|
with open(self.path, 'rb') as fl:
|
||||||
data = fl.read()
|
data = fl.read()
|
||||||
inst = LibToxEncryptSave.get_instance()
|
inst = ToxEncryptSave.get_instance()
|
||||||
try:
|
try:
|
||||||
if inst.is_data_encrypted(data):
|
if inst.is_data_encrypted(data):
|
||||||
data = inst.pass_decrypt(data)
|
data = inst.pass_decrypt(data)
|
||||||
@ -145,7 +145,7 @@ class Settings(dict, Singleton):
|
|||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
text = json.dumps(self)
|
text = json.dumps(self)
|
||||||
inst = LibToxEncryptSave.get_instance()
|
inst = ToxEncryptSave.get_instance()
|
||||||
if inst.has_password():
|
if inst.has_password():
|
||||||
text = bytes(inst.pass_encrypt(bytes(text, 'utf-8')))
|
text = bytes(inst.pass_encrypt(bytes(text, 'utf-8')))
|
||||||
else:
|
else:
|
||||||
@ -224,7 +224,7 @@ class ProfileHelper(Singleton):
|
|||||||
return self._directory
|
return self._directory
|
||||||
|
|
||||||
def save_profile(self, data):
|
def save_profile(self, data):
|
||||||
inst = LibToxEncryptSave.get_instance()
|
inst = ToxEncryptSave.get_instance()
|
||||||
if inst.has_password():
|
if inst.has_password():
|
||||||
data = inst.pass_encrypt(data)
|
data = inst.pass_encrypt(data)
|
||||||
with open(self._path, 'wb') as fl:
|
with open(self._path, 'wb') as fl:
|
||||||
|
@ -34,7 +34,7 @@ TOX_ERR_DECRYPTION = {
|
|||||||
TOX_PASS_ENCRYPTION_EXTRA_LENGTH = 80
|
TOX_PASS_ENCRYPTION_EXTRA_LENGTH = 80
|
||||||
|
|
||||||
|
|
||||||
class LibToxEncryptSave(util.Singleton):
|
class ToxEncryptSave(util.Singleton):
|
||||||
|
|
||||||
libtoxencryptsave = libtox.LibToxEncryptSave()
|
libtoxencryptsave = libtox.LibToxEncryptSave()
|
||||||
|
|
||||||
|
@ -2,39 +2,21 @@ from src.bootstrap import node_generator
|
|||||||
from src.profile import *
|
from src.profile import *
|
||||||
from src.settings import ProfileHelper
|
from src.settings import ProfileHelper
|
||||||
from src.tox_dns import tox_dns
|
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):
|
def test_search(self):
|
||||||
arr = ProfileHelper.find_profiles()
|
arr = ProfileHelper.find_profiles()
|
||||||
assert arr
|
|
||||||
assert len(arr) >= 2
|
assert len(arr) >= 2
|
||||||
|
|
||||||
def test_open(self):
|
def test_open(self):
|
||||||
data = ProfileHelper(Settings.get_default_path(), 'alice').open_profile()
|
data = ProfileHelper(Settings.get_default_path(), 'alice').open_profile()
|
||||||
assert data
|
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 TestTox:
|
||||||
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):
|
def test_loading(self):
|
||||||
data = ProfileHelper(Settings.get_default_path(), 'alice').open_profile()
|
data = ProfileHelper(Settings.get_default_path(), 'alice').open_profile()
|
||||||
@ -45,16 +27,16 @@ class TestTox():
|
|||||||
del tox
|
del tox
|
||||||
|
|
||||||
def test_creation(self):
|
def test_creation(self):
|
||||||
name = 'Toxygen User'
|
name = b'Toxygen User'
|
||||||
status_message = 'Toxing on Toxygen'
|
status_message = b'Toxing on Toxygen'
|
||||||
tox = tox_factory()
|
tox = tox_factory()
|
||||||
tox.self_set_name(name)
|
tox.self_set_name(name)
|
||||||
tox.self_set_status_message(status_message)
|
tox.self_set_status_message(status_message)
|
||||||
data = tox.get_savedata()
|
data = tox.get_savedata()
|
||||||
del tox
|
del tox
|
||||||
tox = tox_factory(data)
|
tox = tox_factory(data)
|
||||||
assert tox.self_get_name() == name
|
assert tox.self_get_name() == str(name, 'utf-8')
|
||||||
assert tox.self_get_status_message() == status_message
|
assert tox.self_get_status_message() == str(status_message, 'utf-8')
|
||||||
|
|
||||||
def test_friend_list(self):
|
def test_friend_list(self):
|
||||||
data = ProfileHelper(Settings.get_default_path(), 'bob').open_profile()
|
data = ProfileHelper(Settings.get_default_path(), 'bob').open_profile()
|
||||||
@ -67,7 +49,7 @@ class TestTox():
|
|||||||
del tox
|
del tox
|
||||||
|
|
||||||
|
|
||||||
class TestDNS():
|
class TestDNS:
|
||||||
|
|
||||||
def test_dns(self):
|
def test_dns(self):
|
||||||
bot_id = '56A1ADE4B65B86BCD51CC73E2CD4E542179F47959FE3E0E21B4B0ACDADE51855D34D34D37CB5'
|
bot_id = '56A1ADE4B65B86BCD51CC73E2CD4E542179F47959FE3E0E21B4B0ACDADE51855D34D34D37CB5'
|
||||||
@ -75,12 +57,13 @@ class TestDNS():
|
|||||||
assert tox_id == bot_id
|
assert tox_id == bot_id
|
||||||
|
|
||||||
|
|
||||||
class TestEncryption():
|
class TestEncryption:
|
||||||
|
|
||||||
def test_encr_decr(self):
|
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()
|
data = fl.read()
|
||||||
lib = LibToxEncryptSave('easypassword')
|
lib = encr.ToxEncryptSave()
|
||||||
|
lib.set_password('easypassword')
|
||||||
copy_data = data[:]
|
copy_data = data[:]
|
||||||
data = lib.pass_encrypt(data)
|
data = lib.pass_encrypt(data)
|
||||||
data = lib.pass_decrypt(data)
|
data = lib.pass_decrypt(data)
|
||||||
|
Loading…
Reference in New Issue
Block a user