<commit_before>from datetime import datetime, timedelta

from django.test import TestCase

from corehq.apps.users.models import CommCareUser
from corehq.apps.domain.models import Domain
from corehq.dbaccessors.couchapps.all_docs import delete_all_docs_by_doc_type
from corehq.form_processor.tests.utils import create_form_for_test, FormProcessorTestUtils

from corehq.warehouse.models import (
    UserStagingTable,
    DomainStagingTable,
    UserDim,
    DomainDim,
    FormStagingTable,
    FormFact,
)


class FormFactIntegrationTest(TestCase):
    '''
    Tests a full integration of loading the FormFact table from
    staging and dimension tables.
    '''
    domain = 'form-fact-integration-test'

    @classmethod
    def setUpClass(cls):
        delete_all_docs_by_doc_type(Domain.get_db(), ['Domain', 'Domain-Deleted'])
        cls.domain_records = [
            Domain(name=cls.domain, hr_name='One', creating_user_id='abc', is_active=True),
        ]

        for domain in cls.domain_records:
            domain.save()

        cls.user_records = [
            # TODO: Handle WebUsers who have multiple domains
            # WebUser.create(
            #     cls.domain,
            #     'web-user',
            #     '***',
            #     date_joined=datetime.utcnow(),
            #     first_name='A',
            #     last_name='B',
            #     email='<EMAIL>',
            #     is_active=True,
            #     is_staff=False,
            #     is_superuser=True,
            # ),
            CommCareUser.create(
                cls.domain,<commit_msg>more defensive cleanup<commit_after>from datetime import datetime, timedelta

from django.test import TestCase

from corehq.apps.users.models import CommCareUser
from corehq.apps.domain.models import Domain
from corehq.dbaccessors.couchapps.all_docs import delete_all_docs_by_doc_type
from corehq.form_processor.tests.utils import create_form_for_test, FormProcessorTestUtils

from corehq.warehouse.models import (
    UserStagingTable,
    DomainStagingTable,
    UserDim,
    DomainDim,
    FormStagingTable,
    FormFact,
)


class FormFactIntegrationTest(TestCase):
    '''
    Tests a full integration of loading the FormFact table from
    staging and dimension tables.
    '''
    domain = 'form-fact-integration-test'

    @classmethod
    def setUpClass(cls):
        delete_all_docs_by_doc_type(Domain.get_db(), ['Domain', 'Domain-Deleted'])
        delete_all_docs_by_doc_type(CommCareUser.get_db(), ['CommCareUser', 'WebUser'])
        cls.domain_records = [
            Domain(name=cls.domain, hr_name='One', creating_user_id='abc', is_active=True),
        ]

        for domain in cls.domain_records:
            domain.save()

        cls.user_records = [
            # TODO: Handle WebUsers who have multiple domains
            # WebUser.create(
            #     cls.domain,
            #     'web-user',
            #     '***',
            #     date_joined=datetime.utcnow(),
            #     first_name='A',
            #     last_name='B',
            #     email='<EMAIL>',
            #     is_active=True,
            #     is_staff=False,
            #     is_superuser=True,
            # ),
            CommCareUser.create(
                cls.domain,
{'fraction_non_alphanumeric': 0.0945821854912764, 'fraction_numerical': 0.0, 'mean_word_length': 2.2647352647352648, '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': '401282', 'n_tokens_mistral': 978, 'n_tokens_neox': 955, 'n_words': 182}