<commit_before>"""Factories for making test data"""
from datetime import date

import factory
from factory import fuzzy
from factory.django import DjangoModelFactory
import faker

from .models import Program, Course, CourseRun


FAKE = faker.Factory.create()


class ProgramFactory(DjangoModelFactory):
    """Factory for Programs"""
    title = fuzzy.FuzzyText(prefix="Program ")
    live = fuzzy.FuzzyAttribute(FAKE.boolean)
    description = fuzzy.FuzzyText()

    class Meta:  # pylint: disable=missing-docstring
        model = Program


class CourseFactory(DjangoModelFactory):
    """Factory for Courses"""
    title = fuzzy.FuzzyText(prefix="Course ")
    program = factory.SubFactory(ProgramFactory)
    position_in_program = factory.Sequence(lambda n: n)

    description = fuzzy.FuzzyText()
    prerequisites = fuzzy.FuzzyText(prefix="Course requires ")

    class Meta:  # pylint: disable=missing-docstring
        model = Course

    @classmethod
    def _setup_next_sequence(cls):
        last = Course.objects.order_by('position_in_program').last()
        if last is not None:
            return last.position_in_program + 1
        return 0


class CourseRunFactory(DjangoModelFactory):
    """Factory for CourseRuns"""
    title = fuzzy.FuzzyText(prefix="CourseRun ")
    course = factory.SubFactory(CourseFactory)
    edx_course_key = fuzzy.FuzzyText()
    enrollment_start = fuzzy.FuzzyDate(date(1980, 1, 1))
    start_date = fuzzy.FuzzyDate(date(1980, 1, 1))
    enrollment_end = fuzzy.FuzzyDate(date(1980, 1, 1))
    end_date = fuzzy.FuzzyDate(date(1980, 1, 1))
    fuzzy_start_date = fuzzy.FuzzyText(prefix="Starting ")
    fuzzy_enrollment_start_date = fuzzy.FuzzyText(prefix="Enrollment starting ")
    enrollment_url = fuzzy.FuzzyText(prefix="http://")
    prerequisites = fuzzy.FuzzyText(prefix="CourseRun requires ")

    class Meta:  # pylint: disable=missing-docstring
        model = CourseRun<commit_msg>Updated date to datetime to match CourseRun fields<commit_after>"""Factories for making test data"""
from datetime import datetime
import pytz

import factory
from factory import fuzzy
from factory.django import DjangoModelFactory
import faker

from .models import Program, Course, CourseRun


FAKE = faker.Factory.create()


class ProgramFactory(DjangoModelFactory):
    """Factory for Programs"""
    title = fuzzy.FuzzyText(prefix="Program ")
    live = fuzzy.FuzzyAttribute(FAKE.boolean)
    description = fuzzy.FuzzyText()

    class Meta:  # pylint: disable=missing-docstring
        model = Program


class CourseFactory(DjangoModelFactory):
    """Factory for Courses"""
    title = fuzzy.FuzzyText(prefix="Course ")
    program = factory.SubFactory(ProgramFactory)
    position_in_program = factory.Sequence(lambda n: n)

    description = fuzzy.FuzzyText()
    prerequisites = fuzzy.FuzzyText(prefix="Course requires ")

    class Meta:  # pylint: disable=missing-docstring
        model = Course

    @classmethod
    def _setup_next_sequence(cls):
        last = Course.objects.order_by('position_in_program').last()
        if last is not None:
            return last.position_in_program + 1
        return 0


class CourseRunFactory(DjangoModelFactory):
    """Factory for CourseRuns"""
    title = fuzzy.FuzzyText(prefix="CourseRun ")
    course = factory.SubFactory(CourseFactory)
    edx_course_key = fuzzy.FuzzyText()
    enrollment_start = fuzzy.FuzzyDateTime(datetime(1980, 1, 1, tzinfo=pytz.utc))
    start_date = fuzzy.FuzzyDateTime(datetime(1980, 1, 1, tzinfo=pytz.utc))
    enrollment_end = fuzzy.FuzzyDateTime(datetime(1980, 1, 1, tzinfo=pytz.utc))
    end_date = fuzzy.FuzzyDateTime(datetime(1980, 1, 1, tzinfo=pytz.utc))
    fuzzy_start_date = fuzzy.FuzzyText(prefix="Starting ")
    fuzzy_enrollment_start_date = fuzzy.FuzzyText(prefix="Enrollment starting ")
    enrollment_url = fuzzy.FuzzyText(prefix="http://")
    prerequisites = fuzzy.FuzzyText(prefix="CourseRun requires ")

    class Meta:  # pylint: disable=missing-docstring
        model = CourseRun
{'fraction_non_alphanumeric': 0.10285714285714286, 'fraction_numerical': 0.012919254658385093, 'mean_word_length': 4.161538461538462, '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': '5859661', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1187, 'n_words': 268}