from django.utils.datetime_safe import datetime
import factory
from yunity.models import Category


class Factory(factory.DjangoModelFactory):
    class Meta:
        strategy = factory.CREATE_STRATEGY
        model = None
        abstract = True

class UserFactory(Factory):
    class Meta:
        model = "yunity.User"
        strategy = factory.CREATE_STRATEGY

    type = Category.objects.get(name="user.default")
    display_name = factory.Sequence(lambda n: "user{}".format(n))
    email = factory.LazyAttribute(lambda obj: '%s@email.com' % obj.display_name)
    is_active = True
    is_staff = False
    date_joined = datetime.now()
    password = factory.PostGeneration(lambda obj, *args, **kwargs: obj.set_password(obj.display_name))
    last_login = datetime.now()
    locations = {}
@@ -787,8 +787,523 @@
 ons = %7B%7D
+%0A%0Aclass ChatFactory(Factory):%0A    class Meta:%0A        model = %22yunity.Chat%22%0A        strategy = factory.CREATE_STRATEGY%0A%0A    administrated_by = factory.SubFactory(UserFactory)%0A%0A    @factory.post_generation%0A    def participants(self, create, extracted, **kwargs):%0A        if not create:%0A            # Simple build, do nothing.%0A            return%0A%0A        if extracted:%0A            # A list of groups were passed in, use them%0A            for participant in extracted:%0A                self.participants.add(participant)

test factories: added ChatFactory