<commit_before>import factory
from django.contrib.auth.models import User
from django.utils import timezone

from events.models import Event, EventInvite
from userprofiles.models import FriendRequest


class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = User

    class Params:
        join_event = None
        get_invited_to = None
        friend_user = None

    @classmethod
    def create(cls, **kwargs):
        obj = super().create(**kwargs)
        join_event = kwargs.get('join_event')
        get_invited_to = kwargs.get('get_invited_to')
        friend_user = kwargs.get('friend_user')
        if isinstance(join_event, Event):
            EventInvite.objects.join(join_event, obj, check_perm=False)
        elif isinstance(get_invited_to, Event):
            from_user = get_invited_to.created_by
            EventInvite.objects.invite(get_invited_to, from_user, obj.pk)
        if friend_user:
            FriendRequest.objects.send_friend_request(friend_user, obj.pk)
            FriendRequest.objects.accept(obj, friend_user.pk)
        return obj

    username = factory.Sequence(lambda n: f'user{n}')
    password = '<PASSWORD>'


class EventFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Event

    class Params:
        past_or_future = 'future'
        join = False

    @classmethod
    def create(cls, **kwargs):
        obj = super().create(**kwargs)
        if kwargs.get('join'):
            EventInvite.objects.join(obj, obj.created_by)
        return obj

    @staticmethod
    def _get_date_time(obj):
        if obj.past_or_future == 'future':
            return timezone.now() + timezone.timedelta(hours=24)
        elif obj.past_or_future == 'past':
            return timezone.now() - timezone.timedelta(hours=24)

    created_by = factory.SubFactory(UserFactory)
    title = 'Event title'
    start_date = factory.LazyAttribute(lambda o: EventFactory._get_date_time(o))<commit_msg>add FriendshipFactory<commit_after>import factory
from django.contrib.auth.models import User
from django.utils import timezone

from events.models import Event, EventInvite
from userprofiles.models import FriendRequest


class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = User

    class Params:
        join_event = None
        get_invited_to = None
        friend_user = None

    @classmethod
    def create(cls, **kwargs):
        obj = super().create(**kwargs)
        join_event = kwargs.get('join_event')
        get_invited_to = kwargs.get('get_invited_to')
        friend_user = kwargs.get('friend_user')
        if isinstance(join_event, Event):
            EventInvite.objects.join(join_event, obj, check_perm=False)
        elif isinstance(get_invited_to, Event):
            from_user = get_invited_to.created_by
            EventInvite.objects.invite(get_invited_to, from_user, obj.pk)
        if friend_user:
            FriendRequest.objects.send_friend_request(friend_user, obj.pk)
            FriendRequest.objects.accept(obj, friend_user.pk)
        return obj

    username = factory.Sequence(lambda n: f'user{n}')
    password = '<PASSWORD>'


class EventFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = Event

    class Params:
        past_or_future = 'future'
        join = False

    @classmethod
    def create(cls, **kwargs):
        obj = super().create(**kwargs)
        if kwargs.get('join'):
            EventInvite.objects.join(obj, obj.created_by)
        return obj

    @staticmethod
    def _get_date_time(obj):
        if obj.past_or_future == 'future':
            return timezone.now() + timezone.timedelta(hours=24)
        elif obj.past_or_future == 'past':
            return timezone.now() - timezone.timedelta(hours=24)

    created_by = factory.SubFactory(UserFactory)
    title = 'Event title'
    start_date = factory.LazyAttribute(lambda o: EventFactory._get_date_time(o))


class FriendshipFactory(factory.DjangoModelFactory):
    class Meta:
        model = FriendRequest

    @classmethod
    def create(cls, **kwargs):
        obj = super().create(**kwargs)
        FriendRequest.objects.accept(obj.to_user, obj.from_user.pk)
        return obj
{'fraction_non_alphanumeric': 0.09697970740915526, 'fraction_numerical': 0.0018876828692779614, 'mean_word_length': 2.860655737704918, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4649632', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1246, 'n_words': 258}