<commit_before>"""Utilities for tests"""

import functools as ft

import factory
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.test import TestCase
from factory.django import DjangoModelFactory
from rest_framework.test import APIClient

from powerdns.models.powerdns import Record, Domain
from powerdns.models.requests import DeleteRequest, RecordRequest
from powerdns.models.ownership import ServiceOwner, Service
from powerdns.models.templates import RecordTemplate, DomainTemplate
from powerdns.utils import AutoPtrOptions


class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = get_user_model()
        django_get_or_create = ('username',)

    username = factory.Sequence(lambda n: "user_%d" % n)

    @classmethod
    def _generate(cls, create, attrs):
        user = super(UserFactory, cls)._generate(create, attrs)
        user.set_password('password')
        user.save()
        return user


class DomainTemplateFactory(DjangoModelFactory):
    class Meta:
        model = DomainTemplate

    name = factory.Sequence(lambda n: 'name%d' % n)


class RecordTemplateFactory(DjangoModelFactory):
    class Meta:
        model = RecordTemplate


class ServiceFactory(DjangoModelFactory):
    class Meta:
        model = Service
    name = factory.Sequence(lambda n: 'service%d' % n)
    uid = factory.Sequence(lambda n: 'uid%d' % n)


class ServiceOwnerFactory(DjangoModelFactory):
    class Meta:
        model = ServiceOwner
    service = factory.SubFactory(UserFactory)
    user = factory.SubFactory(UserFactory)<commit_msg>Fix factory (#172)<commit_after>"""Utilities for tests"""

import functools as ft

import factory
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.test import TestCase
from factory.django import DjangoModelFactory
from rest_framework.test import APIClient

from powerdns.models.powerdns import Record, Domain
from powerdns.models.requests import DeleteRequest, RecordRequest
from powerdns.models.ownership import ServiceOwner, Service
from powerdns.models.templates import RecordTemplate, DomainTemplate
from powerdns.utils import AutoPtrOptions


class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = get_user_model()
        django_get_or_create = ('username',)

    username = factory.Sequence(lambda n: "user_%d" % n)

    @classmethod
    def _generate(cls, create, attrs):
        user = super(UserFactory, cls)._generate(create, attrs)
        user.set_password('password')
        user.save()
        return user


class DomainTemplateFactory(DjangoModelFactory):
    class Meta:
        model = DomainTemplate

    name = factory.Sequence(lambda n: 'name%d' % n)


class RecordTemplateFactory(DjangoModelFactory):
    class Meta:
        model = RecordTemplate


class ServiceFactory(DjangoModelFactory):
    class Meta:
        model = Service
    name = factory.Sequence(lambda n: 'service%d' % n)
    uid = factory.Sequence(lambda n: 'uid%d' % n)


class ServiceOwnerFactory(DjangoModelFactory):
    class Meta:
        model = ServiceOwner
    service = factory.SubFactory(ServiceFactory)
    user = factory.SubFactory(UserFactory)
{'fraction_non_alphanumeric': 0.07949172576832152, 'fraction_numerical': 0.0008865248226950354, 'mean_word_length': 4.264385692068429, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6165414', 'n_tokens_mistral': 938, 'n_tokens_neox': 916, 'n_words': 253}