factories.py 865 Bytes
Newer Older
1 2
import factory
import hashlib
Jean-Baptiste's avatar
Jean-Baptiste committed
3
from .models import Account, ChatProfile
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
from django.db.models.signals import post_save
from djangoldp.factories import UserFactory

@factory.django.mute_signals(post_save)
class AccountFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Account

    user = factory.SubFactory(UserFactory)

    @factory.post_generation
    def members(self, create, extracted, **kwargs):
        if not create:
            return

        emailMd5 = hashlib.md5(self.user.email.encode('utf-8')).hexdigest()
        self.picture = "https://www.gravatar.com/avatar/%s" % emailMd5
        self.save()

@factory.django.mute_signals(post_save)
class ChatProfileFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = ChatProfile

    user = factory.SubFactory(UserFactory)
Jean-Baptiste's avatar
Jean-Baptiste committed
29 30
    jabberID = factory.Faker('email')