<commit_before>from django.conf import settings
from django.contrib.auth.models import Permission
from django.core.files import File
from django.db.models.query import QuerySet
from django.test import TestCase

import factory
from taggit.models import Tag

from ..models import Pin, Image
from ...users.models import User


TEST_IMAGE_PATH = settings.SITE_ROOT + 'logo.png'


class UserFactory(factory.Factory):
    username = factory.Sequence(lambda n: 'user_{}'.format(n))
    email = factory.Sequence(lambda n: '<EMAIL>'.format(n))

    @factory.post_generation(extract_prefix='password')
    def set_password(self, create, extracted, **kwargs):
        self.set_password(extracted)
        self.save()

    @factory.post_generation(extract_prefix='user_permissions')
    def set_user_permissions(self, create, extracted, **kwargs):
        self.user_permissions = Permission.objects.filter(codename__in=['add_pin', 'add_image'])


class TagFactory(factory.Factory):
    name = factory.Sequence(lambda n: 'tag_{}'.format(n))


class ImageFactory(factory.Factory):
    image = factory.LazyAttribute(lambda a: File(open(TEST_IMAGE_PATH)))

<commit_msg>Use a relative path for the test image<commit_after>from django.conf import settings
from django.contrib.auth.models import Permission
from django.core.files import File
from django.db.models.query import QuerySet
from django.test import TestCase

import factory
from taggit.models import Tag

from ..models import Pin, Image
from ...users.models import User


TEST_IMAGE_PATH = 'logo.png'


class UserFactory(factory.Factory):
    username = factory.Sequence(lambda n: 'user_{}'.format(n))
    email = factory.Sequence(lambda n: '<EMAIL>'.<EMAIL>(n))

    @factory.post_generation(extract_prefix='password')
    def set_password(self, create, extracted, **kwargs):
        self.set_password(extracted)
        self.save()

    @factory.post_generation(extract_prefix='user_permissions')
    def set_user_permissions(self, create, extracted, **kwargs):
        self.user_permissions = Permission.objects.filter(codename__in=['add_pin', 'add_image'])


class TagFactory(factory.Factory):
    name = factory.Sequence(lambda n: 'tag_{}'.format(n))


class ImageFactory(factory.Factory):
    image = factory.LazyAttribute(lambda a: File(open(TEST_IMAGE_PATH)))


{'fraction_non_alphanumeric': 0.11596711380354825, 'fraction_numerical': 0.0, 'mean_word_length': 5.0365535248041775, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '4483194', 'n_tokens_mistral': 689, 'n_tokens_neox': 667, 'n_words': 160}