Skip to content

Commit

Permalink
added more tests and a crutch to execute celery tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolerd committed Jul 28, 2015
1 parent 49325cf commit 57919e5
Showing 1 changed file with 82 additions and 3 deletions.
85 changes: 82 additions & 3 deletions project/tests/test_bl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

class TestUserBL(ProjectTestCase):

# Crutch for executing celery tasks
from project.tasks.mail import celery_send_mail
celery_send_mail.delay = celery_send_mail

def test_set_password(self):
"""Check password setter correctness"""
raw_pass = 'celestia'
Expand All @@ -30,9 +34,6 @@ def test_reset_password(self):
'surname': 'Princess',
}
User.bl.create(data)
usr = User.bl.authenticate(login, orig_password)
self.assertIsNotNone(usr)
del usr
User.bl.forgot_password(email)
self.assertEqual(
len(outbox),
Expand Down Expand Up @@ -76,6 +77,84 @@ def test_reset_password(self):
msg="User was not authenticated with new password"
)

def test_create_with_password(self):
password = 'cadence'
email = 'cadence@canterlot.com'
login = 'cadence'
name = 'Cadence'
surname = 'Princess'
data = {
'login': login,
'password': password,
'email': email,
'name': name,
'surname': surname,
}
User.bl.create(data)
usr = User.bl.authenticate(login, password)
self.assertIsNotNone(
usr,
msg="Cannot authenticate created user",
)
self.assertEqual(
usr.name,
name,
msg='Names do not match',
)
self.assertEqual(
usr.surname,
surname,
msg='Surnames do not match',
)

def test_screate_without_password(self):
with mail.record_messages() as outbox:
email = 'celestia@canterlot.com'
login = 'celestia'
name = 'Celestia'
surname = 'Princess'
data = {
'login': login,
'email': email,
'name': name,
'surname': surname,
}
User.bl.create(data)
self.assertEqual(
len(outbox),
1,
)
self.assertEqual(
outbox[0].subject,
'Вам была создана учетная запись на HR портале!',
msg='Incorrect mail subject',
)
self.assertEqual(
outbox[0].recipients,
[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,
)
usr = User.bl.authenticate(login, password)
self.assertIsNotNone(
usr,
msg="Cannot authenticate created user",
)
self.assertEqual(
usr.name,
name,
msg='Names do not match',
)
self.assertEqual(
usr.surname,
surname,
msg='Surnames do not match',
)


class TestVacancyBL(ProjectTestCase):

Expand Down

0 comments on commit 57919e5

Please sign in to comment.