more tests
This commit is contained in:
parent
f41b5e5c97
commit
b227ed627a
2 changed files with 48 additions and 15 deletions
|
@ -1,8 +1,9 @@
|
||||||
from toxygen.profile import *
|
from toxygen.profile import *
|
||||||
from toxygen.tox_dns import tox_dns
|
from toxygen.tox_dns import tox_dns
|
||||||
from toxygen.history import History
|
from toxygen.history import History
|
||||||
|
from toxygen.smileys import SmileyLoader
|
||||||
|
from toxygen.messages import *
|
||||||
import toxygen.toxes as encr
|
import toxygen.toxes as encr
|
||||||
import toxygen.messages as m
|
|
||||||
import toxygen.util as util
|
import toxygen.util as util
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -60,10 +61,21 @@ class TestEncryption:
|
||||||
lib.set_password(password)
|
lib.set_password(password)
|
||||||
copy_data = data[:]
|
copy_data = data[:]
|
||||||
new_data = lib.pass_encrypt(data)
|
new_data = lib.pass_encrypt(data)
|
||||||
|
assert lib.is_data_encrypted(new_data)
|
||||||
new_data = lib.pass_decrypt(new_data)
|
new_data = lib.pass_decrypt(new_data)
|
||||||
assert copy_data == new_data
|
assert copy_data == new_data
|
||||||
|
|
||||||
|
|
||||||
|
class TestSmileys:
|
||||||
|
|
||||||
|
def test_loading(self):
|
||||||
|
settings = {'smiley_pack': 'default', 'smileys': True}
|
||||||
|
sm = SmileyLoader(settings)
|
||||||
|
assert sm.get_smileys_path() is not None
|
||||||
|
l = sm.get_packs_list()
|
||||||
|
assert len(l) == 4
|
||||||
|
|
||||||
|
|
||||||
def create_singletons():
|
def create_singletons():
|
||||||
folder = util.curr_directory() + '/abc'
|
folder = util.curr_directory() + '/abc'
|
||||||
Settings._instance = Settings.get_default_settings()
|
Settings._instance = Settings.get_default_settings()
|
||||||
|
@ -77,6 +89,13 @@ def create_friend(name, status_message, number, tox_id):
|
||||||
return friend
|
return friend
|
||||||
|
|
||||||
|
|
||||||
|
def create_random_friend():
|
||||||
|
name, status_message, number = 'Friend', 'I am friend!', 0
|
||||||
|
tox_id = '76518406F6A9F2217E8DC487CC783C25CC16A15EB36FF32E335A235342C48A39218F515C39A6'
|
||||||
|
friend = create_friend(name, status_message, number, tox_id)
|
||||||
|
return friend
|
||||||
|
|
||||||
|
|
||||||
class TestFriend:
|
class TestFriend:
|
||||||
|
|
||||||
def test_friend_creation(self):
|
def test_friend_creation(self):
|
||||||
|
@ -91,21 +110,19 @@ class TestFriend:
|
||||||
|
|
||||||
def test_friend_corr(self):
|
def test_friend_corr(self):
|
||||||
create_singletons()
|
create_singletons()
|
||||||
name, status_message, number = 'Friend', 'I am friend!', 0
|
friend = create_random_friend()
|
||||||
tox_id = '76518406F6A9F2217E8DC487CC783C25CC16A15EB36FF32E335A235342C48A39218F515C39A6'
|
|
||||||
friend = create_friend(name, status_message, number, tox_id)
|
|
||||||
t = time.time()
|
t = time.time()
|
||||||
friend.append_message(m.InfoMessage('Info message', t))
|
friend.append_message(InfoMessage('Info message', t))
|
||||||
friend.append_message(m.TextMessage('Hello! It is test!', MESSAGE_OWNER['ME'], t + 0.001, 0))
|
friend.append_message(TextMessage('Hello! It is test!', MESSAGE_OWNER['ME'], t + 0.001, 0))
|
||||||
friend.append_message(m.TextMessage('Hello!', MESSAGE_OWNER['FRIEND'], t + 0.002, 0))
|
friend.append_message(TextMessage('Hello!', MESSAGE_OWNER['FRIEND'], t + 0.002, 0))
|
||||||
assert friend.get_last_message_text() == 'Hello! It is test!'
|
assert friend.get_last_message_text() == 'Hello! It is test!'
|
||||||
assert len(friend.get_corr()) == 3
|
assert len(friend.get_corr()) == 3
|
||||||
assert len(friend.get_corr_for_saving()) == 2
|
assert len(friend.get_corr_for_saving()) == 2
|
||||||
friend.append_message(m.TextMessage('Not sent', MESSAGE_OWNER['NOT_SENT'], t + 0.002, 0))
|
friend.append_message(TextMessage('Not sent', MESSAGE_OWNER['NOT_SENT'], t + 0.002, 0))
|
||||||
arr = friend.get_unsent_messages_for_saving()
|
arr = friend.get_unsent_messages_for_saving()
|
||||||
assert len(arr) == 1
|
assert len(arr) == 1
|
||||||
assert arr[0][0] == 'Not sent'
|
assert arr[0][0] == 'Not sent'
|
||||||
tm = m.TransferMessage(MESSAGE_OWNER['FRIEND'],
|
tm = TransferMessage(MESSAGE_OWNER['FRIEND'],
|
||||||
time.time(),
|
time.time(),
|
||||||
TOX_FILE_TRANSFER_STATE['RUNNING'],
|
TOX_FILE_TRANSFER_STATE['RUNNING'],
|
||||||
100, 'file_name', friend.number, 0)
|
100, 'file_name', friend.number, 0)
|
||||||
|
@ -113,10 +130,22 @@ class TestFriend:
|
||||||
friend.clear_corr()
|
friend.clear_corr()
|
||||||
assert len(friend.get_corr()) == 1
|
assert len(friend.get_corr()) == 1
|
||||||
assert len(friend.get_corr_for_saving()) == 0
|
assert len(friend.get_corr_for_saving()) == 0
|
||||||
friend.append_message(m.TextMessage('Hello! It is test!', MESSAGE_OWNER['ME'], t, 0))
|
friend.append_message(TextMessage('Hello! It is test!', MESSAGE_OWNER['ME'], t, 0))
|
||||||
assert len(friend.get_corr()) == 2
|
assert len(friend.get_corr()) == 2
|
||||||
assert len(friend.get_corr_for_saving()) == 1
|
assert len(friend.get_corr_for_saving()) == 1
|
||||||
|
|
||||||
|
def test_history_search(self):
|
||||||
|
create_singletons()
|
||||||
|
friend = create_random_friend()
|
||||||
|
message = 'Hello! It is test!'
|
||||||
|
friend.append_message(TextMessage(message, MESSAGE_OWNER['ME'], time.time(), 0))
|
||||||
|
last_message = friend.get_last_message_text()
|
||||||
|
assert last_message == message
|
||||||
|
result = friend.search_string('e[m|s]')
|
||||||
|
assert result is not None
|
||||||
|
result = friend.search_string('tox')
|
||||||
|
assert result is None
|
||||||
|
|
||||||
|
|
||||||
class TestHistory:
|
class TestHistory:
|
||||||
|
|
||||||
|
@ -131,7 +160,7 @@ class TestHistory:
|
||||||
assert history.friend_exists_in_db(friend.tox_id)
|
assert history.friend_exists_in_db(friend.tox_id)
|
||||||
text_message = 'Test!'
|
text_message = 'Test!'
|
||||||
t = time.time()
|
t = time.time()
|
||||||
friend.append_message(m.TextMessage(text_message, MESSAGE_OWNER['ME'], t, 0))
|
friend.append_message(TextMessage(text_message, MESSAGE_OWNER['ME'], t, 0))
|
||||||
messages = friend.get_corr_for_saving()
|
messages = friend.get_corr_for_saving()
|
||||||
history.save_messages_to_db(friend.tox_id, messages)
|
history.save_messages_to_db(friend.tox_id, messages)
|
||||||
getter = history.messages_getter(friend.tox_id)
|
getter = history.messages_getter(friend.tox_id)
|
||||||
|
@ -144,3 +173,5 @@ class TestHistory:
|
||||||
getter = history.messages_getter(friend.tox_id)
|
getter = history.messages_getter(friend.tox_id)
|
||||||
messages = getter.get_all()
|
messages = getter.get_all()
|
||||||
assert len(messages) == 0
|
assert len(messages) == 0
|
||||||
|
history.delete_friend_from_db(friend.tox_id)
|
||||||
|
assert not history.friend_exists_in_db(friend.tox_id)
|
||||||
|
|
|
@ -50,6 +50,8 @@ class Contact(basecontact.BaseContact):
|
||||||
"""
|
"""
|
||||||
if (first_time and self._history_loaded) or (not hasattr(self, '_message_getter')):
|
if (first_time and self._history_loaded) or (not hasattr(self, '_message_getter')):
|
||||||
return
|
return
|
||||||
|
if self._message_getter is None:
|
||||||
|
return
|
||||||
data = list(self._message_getter.get(PAGE_SIZE))
|
data = list(self._message_getter.get(PAGE_SIZE))
|
||||||
if data is not None and len(data):
|
if data is not None and len(data):
|
||||||
data.reverse()
|
data.reverse()
|
||||||
|
@ -176,7 +178,7 @@ class Contact(basecontact.BaseContact):
|
||||||
while True:
|
while True:
|
||||||
l = len(self._corr)
|
l = len(self._corr)
|
||||||
for i in range(self._search_index - 1, -l - 1, -1):
|
for i in range(self._search_index - 1, -l - 1, -1):
|
||||||
if type(self._corr[i]) is not TextMessage:
|
if self._corr[i].get_type() > 1:
|
||||||
continue
|
continue
|
||||||
message = self._corr[i].get_data()[0]
|
message = self._corr[i].get_data()[0]
|
||||||
if re.search(self._search_string, message, re.IGNORECASE) is not None:
|
if re.search(self._search_string, message, re.IGNORECASE) is not None:
|
||||||
|
|
Loading…
Reference in a new issue