-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
82 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,11 @@ | |
|
||
class BaseTest(TestCase): | ||
USERNAME = 'billy' | ||
PASSWORD = 'billy1234' | ||
PASSWORD = 'correcthorsebatterystaple' | ||
EMAIL = '[email protected]' | ||
FIRST_NAME = 'Billy' | ||
LAST_NAME = 'Bloggs' | ||
|
||
fixtures = settings.TEST_FIXTURES | ||
|
||
def setUp(self): | ||
self.setUp_user() | ||
|
||
|
@@ -29,6 +27,7 @@ def setUp_user(self): | |
) | ||
user.save() | ||
self.user = user | ||
self.mp = user.memberprofile | ||
|
||
def login(self, c): | ||
"""Login a client with USERNAME""" | ||
|
@@ -49,6 +48,7 @@ def get_page_status_code(self, view_name=None, kwargs=None): | |
return response.status_code | ||
|
||
class BaseAsGroupTest(BaseTest): | ||
fixtures = ['groups'] | ||
def setUp(self): | ||
super(BaseAsGroupTest, self).setUp() | ||
self.set_groups() | ||
|
@@ -60,3 +60,6 @@ def set_groups(self): | |
|
||
class BaseTrainingTest(BaseAsGroupTest): | ||
GROUPS=[3] | ||
|
||
class FixtureMixin(object): | ||
fixtures = settings.TEST_FIXTURES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,136 +7,106 @@ | |
from django.test import TestCase | ||
from django.contrib.auth import get_user_model | ||
|
||
from xSACdb.test_helpers import * | ||
|
||
from xsd_members.models import MemberProfile | ||
from xsd_training.models import Lesson, PerformedLesson | ||
|
||
class PresetUser(TestCase): | ||
USERNAME = 'bob' | ||
EMAIL = '[email protected]' | ||
PASSWORD = 'correcthorsebatterystaple' | ||
|
||
fixtures = settings.TEST_FIXTURES | ||
class MPFunc(BaseTest): | ||
|
||
def setUp(self): | ||
self.make_user() | ||
self.make_pls() | ||
def test_u_mp_relationship(self): | ||
self.assertEqual(self.mp, self.user.memberprofile) | ||
|
||
def make_user(self): | ||
U = get_user_model() | ||
self.u = U.objects.create_user( | ||
email=self.EMAIL, | ||
password=self.PASSWORD, | ||
first_name='Bob', | ||
last_name='Blobby', | ||
def test_age(self): | ||
test_age = 21 | ||
today = datetime.date.today() | ||
t_years_ago = datetime.date( | ||
year = (today.year-test_age), | ||
month = today.month, | ||
day = today.day, | ||
) | ||
|
||
self.u.save() | ||
self.mp.date_of_birth = t_years_ago | ||
self.assertEqual(self.mp.age(),test_age) | ||
|
||
self.mp = self.u.memberprofile | ||
def test_personal_fields(self): | ||
# We have missing personal fields | ||
self.assertEqual(self.mp.missing_personal_details(), True) | ||
# Set all of them | ||
self.mp.address='Demo address' | ||
self.mp.postcode='P0ST CDE' | ||
self.mp.home_phone='555-SEXY' | ||
self.mp.mobile_phone='07123456789' | ||
self.mp.next_of_kin_name='Mary Bloggs' | ||
self.mp.next_of_kin_relation='Mother dearest' | ||
self.mp.next_of_kin_phone='01234 567890' | ||
self.mp.save() | ||
# We now shouldn't have any | ||
self.assertEqual(self.mp.missing_personal_details(), False) | ||
|
||
def get_logged_in_client(self): | ||
c = Client() | ||
res = c.post('/accounts/login/', {'username':self.EMAIL, 'password':self.PASSWORD}) | ||
return c | ||
def test_caching(self): | ||
pass | ||
|
||
class MPExternalFunc(FixtureMixin, BaseTest): | ||
def setUp(self): | ||
super(MPExternalFunc, self).setUp() | ||
self.make_pls() | ||
def make_pls(self): | ||
PLS = [ | ||
{ | ||
'trainee': self.u.memberprofile, | ||
'lesson': Lesson.objects.get(code='OO3'), | ||
'trainee': self.mp, | ||
'lesson': Lesson.objects.get(code='OO2'), | ||
'completed': False, | ||
'partially_complted': False, | ||
'partially_completed': False, | ||
'public_notes': 'Note', | ||
'private_notes': 'Note', | ||
}, | ||
{ | ||
'trainee': self.u.memberprofile, | ||
'trainee': self.mp, | ||
'lesson': Lesson.objects.get(code='OO3'), | ||
'completed': True, | ||
'partially_complted': False, | ||
'partially_completed': False, | ||
'public_notes': 'Note', | ||
'private_notes': 'Note', | ||
}, | ||
{ | ||
'trainee': self.u.memberprofile, | ||
'lesson': Lesson.objects.get(code='OO3'), | ||
'trainee': self.mp, | ||
'lesson': Lesson.objects.get(code='OO4'), | ||
'completed': False, | ||
'partially_complted': True, | ||
'partially_completed': True, | ||
'public_notes': 'Note', | ||
'private_notes': 'Note', | ||
}, | ||
{ | ||
'trainee': self.u.memberprofile, | ||
'trainee': self.mp, | ||
'lesson': None, | ||
'completed': False, | ||
'partially_complted': False, | ||
'partially_completed': False, | ||
'public_notes': 'Note', | ||
'private_notes': 'Note', | ||
}, | ||
{ | ||
'trainee': self.u.memberprofile, | ||
'trainee': self.mp, | ||
'lesson': None, | ||
'completed': False, | ||
'partially_complted': False, | ||
'partially_completed': False, | ||
'public_notes': '', | ||
'private_notes': '', | ||
} | ||
] | ||
for PL in PLS: | ||
new_pl = PerformedLesson() | ||
new_pl.trainee = PL['trainee'] | ||
new_pl.lesson = PL['lesson'] | ||
new_pl.completed = PL['completed'] | ||
new_pl.partially_complted = PL['partially_complted'] | ||
new_pl.public_notes = PL['public_notes'] | ||
new_pl.private_notes = PL['private_notes'] | ||
new_pl = PerformedLesson( | ||
trainee = PL['trainee'], | ||
lesson = PL['lesson'], | ||
completed = PL['completed'], | ||
partially_completed = PL['partially_completed'], | ||
public_notes = PL['public_notes'], | ||
private_notes = PL['private_notes'], | ||
) | ||
new_pl.save() | ||
|
||
class PresetAdminUser(PresetUser): | ||
def setUp(self): | ||
super(PresetAdminUser, self).setUp() | ||
self.make_admin() | ||
def make_admin(self): | ||
g = Group.objects.get(pk=2) | ||
self.u.groups.add(g) | ||
self.u.save() | ||
|
||
class MPFunctionality(PresetUser): | ||
|
||
def test_u_mp_relationship(self): | ||
self.assertEqual(self.mp, self.u.memberprofile) | ||
|
||
def test_age(self): | ||
test_age = 21 | ||
today = datetime.date.today() | ||
t_years_ago = datetime.date( | ||
year = (today.year-test_age), | ||
month = today.month, | ||
day = today.day, | ||
) | ||
|
||
self.mp.date_of_birth = t_years_ago | ||
self.assertEqual(self.mp.age(),test_age) | ||
|
||
def test_personal_fields(self): | ||
# We have missing personal fields | ||
self.assertEqual(self.mp.missing_personal_details(), True) | ||
# Set all of them | ||
self.mp.address='Demo address' | ||
self.mp.postcode='P0ST CDE' | ||
self.mp.home_phone='555-SEXY' | ||
self.mp.mobile_phone='07123456789' | ||
self.mp.next_of_kin_name='Mary Flobby' | ||
self.mp.next_of_kin_relation='Mother dearest' | ||
self.mp.next_of_kin_phone='01234 567890' | ||
self.mp.save() | ||
# We now shouldn't have any | ||
self.assertEqual(self.mp.missing_personal_details(), False) | ||
|
||
def test_performed_lesson_ramble(self): | ||
self.assertTrue(PerformedLesson.objects.get_lessons( | ||
trainee=self.mp).count() > 3) | ||
out = self.mp.performed_lesson_ramble() | ||
self.assertTrue('OO3' in out) | ||
|
||
def test_caching(self): | ||
pass | ||
self.assertTrue(('OO2' in out) and ('OO3' in out) and | ||
('OO4' in out)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters