forked from DGNum/gestioCOF
Add some tests about how profiles types should relate to each other.
This commit is contained in:
parent
22da04c3e2
commit
25c3106168
2 changed files with 42 additions and 11 deletions
|
@ -10,10 +10,22 @@ from __future__ import division
|
|||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db.utils import IntegrityError
|
||||
from django.test import TestCase
|
||||
|
||||
from gestion.models import Profile, User
|
||||
|
||||
def create_profile(username):
|
||||
"""
|
||||
In order to create a profile, I need to create a User first.
|
||||
This is annoying in most situations, as I just want a profile.
|
||||
"""
|
||||
u = User.objects.create(username=username,
|
||||
first_name=username.title(),
|
||||
last_name=username.title())
|
||||
p, = Profile.objects.filter(user__username=username)
|
||||
return p
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_delete_user(self):
|
||||
|
@ -31,3 +43,22 @@ class SimpleTest(TestCase):
|
|||
u.save()
|
||||
Profile.objects.get(user__username='foo').delete()
|
||||
self.assertFalse(User.objects.filter(username='foo').exists())
|
||||
|
||||
def test_create_profiles(self):
|
||||
from kfet.models import Account
|
||||
from cof.models import CofProfile
|
||||
|
||||
# test that two accounts can be linked to the same profile.
|
||||
p = create_profile('foo')
|
||||
pkfet = Account.objects.create(profile=p, trigramme='PIG')
|
||||
pcof = CofProfile.objects.create(profile=p)
|
||||
self.assertEqual(pkfet.profile, pcof.profile)
|
||||
|
||||
# each profile is linked to at most one account of the same type.
|
||||
p1 = create_profile('bar')
|
||||
p2 = create_profile('baz')
|
||||
pkfet1 = Account.objects.create(profile=p1, trigramme='BAR')
|
||||
pcof2 = CofProfile.objects.create(profile=p2)
|
||||
pkfet2 = Account.objects.create(profile=p2, trigramme='BAZ')
|
||||
self.assertRaises(IntegrityError,
|
||||
CofProfile.objects.create, profile=p2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue