Skip to content

Commit

Permalink
rewritten with regexps and naming changed a little
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolerd committed Jul 28, 2015
1 parent 9c8629d commit 4423e4a
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions project/tests/test_bl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from project.tests.utils import ProjectTestCase
from project.extensions import mail
from project.models import User, Vacancy
import re


class TestUserBL(ProjectTestCase):
Expand Down Expand Up @@ -49,7 +50,11 @@ def test_reset_password(self):
[email],
msg="Incorrect recipients",
)
token = outbox[0].body[-20:]
match = re.search(
r'/auth/reset/(?P<token>\w{20})',
outbox[0].body,
)
token = match.groupdict()['token'] if match else None
is_success = User.bl.reset_password(token)
self.assertTrue(
is_success,
Expand All @@ -70,7 +75,11 @@ def test_reset_password(self):
msg="User authenticated w/ old password",
)
del usr
new_password = outbox[1].body[-8:]
match = re.search(
r'Новый пароль: (?P<new_password>\w{8})',
outbox[1].body,
)
new_password = match.groupdict()['new_password'] if match else None
usr = User.bl.authenticate(login, new_password)
self.assertIsNotNone(
usr,
Expand Down Expand Up @@ -107,7 +116,7 @@ def test_create_with_password(self):
msg='Surnames do not match',
)

def test_screate_without_password(self):
def test_create_without_password(self):
with mail.record_messages() as outbox:
email = 'celestia@canterlot.com'
login = 'celestia'
Expand All @@ -134,12 +143,18 @@ def test_screate_without_password(self):
[email],
msg='Incorrect recipients',
)
password = outbox[0].body[-8:]
self.assertTrue(
'login: %s' % login in outbox[0].body,
msg='missing login %s in mesage body' % login,
match = re.search(
r'login: (?P<_login>\w+)\npassword:(?P<_password>\w{8})',
outbox[0].body,
)
_login = match.groupdict()['_login'] if match else None
_password = match.groupdict()['_password'] if match else None
self.assertEqual(
_login,
login,
msg='Logins do not match!',
)
usr = User.bl.authenticate(login, password)
usr = User.bl.authenticate(login, _password)
self.assertIsNotNone(
usr,
msg="Cannot authenticate created user",
Expand Down

0 comments on commit 4423e4a

Please sign in to comment.