TST: Coverage and adding new model tests
This commit is contained in:
parent
5c69e774f9
commit
31714215d0
10 changed files with 65 additions and 11 deletions
11
ccdb/users/factories.py
Normal file
11
ccdb/users/factories.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from factory import DjangoModelFactory, Sequence
|
||||
|
||||
from .models import User
|
||||
|
||||
|
||||
class UserFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = User
|
||||
|
||||
name = Sequence(lambda n: 'user{}'.format(n))
|
||||
username = Sequence(lambda n: 'username{}'.format(n))
|
|
@ -1,5 +1,4 @@
|
|||
from django.contrib.auth.models import AbstractUser
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
@ -9,6 +8,3 @@ class User(AbstractUser):
|
|||
|
||||
def __str__(self):
|
||||
return self.username
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('users:detail', kwargs={'username': self.username})
|
||||
|
|
0
ccdb/users/tests/__init__.py
Normal file
0
ccdb/users/tests/__init__.py
Normal file
19
ccdb/users/tests/test_models.py
Normal file
19
ccdb/users/tests/test_models.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from django.test import TestCase
|
||||
from django.db import IntegrityError, transaction
|
||||
|
||||
from ..models import User
|
||||
from ..factories import UserFactory
|
||||
|
||||
|
||||
class UserTestCase(TestCase):
|
||||
def test_creation(self):
|
||||
u = UserFactory()
|
||||
self.assertTrue(isinstance(u, User))
|
||||
self.assertEqual(u.__str__(), u.username)
|
||||
|
||||
def test_uniqueness(self):
|
||||
u1 = UserFactory()
|
||||
with transaction.atomic(), self.assertRaises(IntegrityError):
|
||||
UserFactory(username=u1.username)
|
||||
u3 = UserFactory()
|
||||
self.assertTrue(isinstance(u3, User))
|
Loading…
Add table
Add a link
Reference in a new issue