Permalink
Browse files

fixing the UserMockup

  • Loading branch information...
1 parent 20c6e19 commit 12e9418b33799e31fdb96c1c736078cc67b42e20 Mikko Hellsing committed Oct 16, 2010
View
@@ -1,12 +1,24 @@
# -*- coding: utf-8 -*-
import mockups
-import string
from datetime import datetime
from django.contrib.auth.models import User, UNUSABLE_PASSWORD
-from mockups import Mockup
+from mockups import Mockup, Factory
from mockups import generators
+class UserFactory(Factory):
+ username = generators.UUIDGenerator(max_length=30)
+ first_name = generators.LoremWordGenerator(1)
+ last_name = generators.LoremWordGenerator(1)
+ password = generators.StaticGenerator(UNUSABLE_PASSWORD)
+ is_active = generators.StaticGenerator(True)
+ # don't generate admin users
+ is_staff = generators.StaticGenerator(False)
+ is_superuser = generators.StaticGenerator(False)
+ date_joined = generators.DateTimeGenerator(max_date=datetime.now())
+ last_login = generators.DateTimeGenerator(max_date=datetime.now())
+
+
class UserMockup(Mockup):
'''
:class:`UserMockup` is automatically used by default to create new
@@ -22,19 +34,10 @@ class UserMockup(Mockup):
* ``date_joined`` and ``last_login`` are always in the past and it is
assured that ``date_joined`` will be lower than ``last_login``.
'''
- username = generators.UUIDGenerator(max_length=30)
- first_name = generators.LoremWordGenerator(1)
- last_name = generators.LoremWordGenerator(1)
- password = generators.StaticGenerator(UNUSABLE_PASSWORD)
- is_active = generators.StaticGenerator(True)
- # don't generate admin users
- is_staff = generators.StaticGenerator(False)
- is_superuser = generators.StaticGenerator(False)
- date_joined = generators.DateTimeGenerator(max_date=datetime.now())
- last_login = generators.DateTimeGenerator(max_date=datetime.now())
# don't follow permissions and groups
follow_m2m = False
+ factory = UserFactory
def __init__(self, *args, **kwargs):
'''
@@ -52,8 +55,9 @@ def __init__(self, *args, **kwargs):
self.password = kwargs.pop('password', None)
super(UserMockup, self).__init__(*args, **kwargs)
if self.username:
- self.field_generators['username'] = generators.StaticGenerator(
- self.username)
+ self.update_fieldname_generator(
+ username = generators.StaticGenerator(self.username)
+ )
def unique_email(self, model, instance):
if User.objects.filter(email=instance.email):
View
@@ -94,9 +94,7 @@ def create(model, count, *args, **kwargs):
superusers::
import mockups
- mockups = mockups.create('auth.User', 10, field_generators={
- 'is_superuser': generators.StaticGenerator(True)
- })
+ mockup = mockups.create('auth.User', 10)
.. note:: See :ref:`Mockup` for more information.
Binary file not shown.
@@ -58,7 +58,7 @@ def test_constraints(self):
self.assertTrue(len(obj.ipaddressfield) >= 7)
self.assertEqual(BasicModel.objects.count(), 100)
- def test_field_generators(self):
+ def test_factory(self):
int_value = 1
char_values = (u'a', u'b')
class GF(Factory):

0 comments on commit 12e9418

Please sign in to comment.