示例#1
0
 def test_overwrite_attributes(self):
     class GF(Factory):
         name = generators.StaticGenerator('bar')
     class M(SimpleMockup):
         factory = GF
     mockups.register(SimpleModel, M)
     for obj in mockups.create(SimpleModel, 10):
         self.assertEqual(obj.name, 'bar')
     obj = mockups.create_one(SimpleModel)
     self.assertEqual(obj.name, 'bar')
示例#2
0
 def test_using_registry(self):
     mockups.register(SimpleModel, SimpleMockup)
     models = ("mockups_test.SimpleModel:10",)
     self.command.handle(*models, **self.options)
     for obj in SimpleModel.objects.all():
         self.assertEqual(obj.name, "foo")
示例#3
0
 def test_create(self):
     mockups.register(SimpleModel, SimpleMockup)
     for obj in mockups.create(SimpleModel, 10):
         self.assertEqual(obj.name, "foo")
     obj = mockups.create_one(SimpleModel)
     self.assertEqual(obj.name, "foo")
示例#4
0
 def test_registration(self):
     mockups.register(SimpleModel, SimpleMockup)
     self.assertTrue(SimpleModel in mockups.helpers._registry)
     self.assertEqual(mockups.helpers._registry[SimpleModel], SimpleMockup)
示例#5
0
#-*- coding: utf-8 -*-
import mockups
from models import UserProfile
from mockups import Mockup, Factory
import string
import random


class UserProfileFactory(Factory):
    pass


class UserProfileMockup(Mockup):
    # don't follow permissions and groups
    follow_m2m = False
    # generate_fk= False
    factory = UserProfileFactory

    def post_process_instance(self, instance):
        instance.user.username = ''.join(
            (random.choice(string.letters + string.digits)
             for _ in xrange(random.randint(5, 8))))
        instance.user.save()


mockups.register(UserProfile, UserProfileMockup, fail_silently=True)
示例#6
0
            mockups.create_one('auth.User', username='******', password='******'foo', password='******')
        '''
        self.username = kwargs.pop('username', None)
        self.password = kwargs.pop('password', None)
        super(UserMockup, self).__init__(*args, **kwargs)
        if self.username:
            self.update_fieldname_generator(
                username = generators.StaticGenerator(self.username)
                )

    def unique_email(self, model, instance):
        if User.objects.filter(email=instance.email):
            raise mockups.InvalidConstraint(('email',))

    def prepare_class(self):
        self.add_constraint(self.unique_email)

    def post_process_instance(self, instance):
        # make sure user's last login was not before he joined
        if instance.last_login < instance.date_joined:
            instance.last_login = instance.date_joined
        if self.password:
            instance.set_password(self.password)
            instance.save()
        return instance


mockups.register(User, UserMockup, fail_silently=True)
示例#7
0
 def test_using_registry(self):
     mockups.register(SimpleModel, SimpleMockup)
     models = ('mockups_test.SimpleModel:10',)
     self.command.handle(*models, **self.options)
     for obj in SimpleModel.objects.all():
         self.assertEqual(obj.name, 'foo')
示例#8
0
 def test_create(self):
     mockups.register(SimpleModel, SimpleMockup)
     for obj in mockups.create(SimpleModel, 10):
         self.assertEqual(obj.name, 'foo')
     obj = mockups.create_one(SimpleModel)
     self.assertEqual(obj.name, 'foo')
示例#9
0
 def test_registration(self):
     mockups.register(SimpleModel, SimpleMockup)
     self.assertTrue(SimpleModel in mockups.helpers._registry)
     self.assertEqual(mockups.helpers._registry[SimpleModel], SimpleMockup)
示例#10
0
        can provide a ``username`` and a ``password`` argument. Then you can do
        something like::

            mockups.create_one('auth.User', username='******', password='******'foo', password='******')
        '''
        self.username = kwargs.pop('username', None)
        self.password = kwargs.pop('password', None)
        super(UserMockup, self).__init__(*args, **kwargs)
        if self.username:
            self.update_fieldname_generator(
                username=generators.StaticGenerator(self.username))

    def unique_email(self, model, instance):
        if User.objects.filter(email=instance.email):
            raise mockups.InvalidConstraint(('email', ))

    def prepare_class(self):
        self.add_constraint(self.unique_email)

    def post_process_instance(self, instance):
        # make sure user's last login was not before he joined
        if instance.last_login < instance.date_joined:
            instance.last_login = instance.date_joined
        if self.password:
            instance.set_password(self.password)
        return instance


mockups.register(User, UserMockup, fail_silently=True)