<commit_before>from __future__ import absolute_import
from __future__ import unicode_literals
import functools
import uuid
import datetime
from django.test import TestCase
from casexml.apps.case.models import CommCareCase
from corehq.apps.commtrack.models import CommtrackConfig
from corehq.apps.domain.dbaccessors import (
    count_downloads_for_all_snapshots,
    get_doc_count_in_domain_by_class,
    get_doc_ids_in_domain_by_class,
    get_docs_in_domain_by_class,
    get_domain_ids_by_names,
)
from corehq.apps.domain.models import Domain
from corehq.apps.domain.shortcuts import create_domain
from corehq.apps.groups.models import Group
from corehq.apps.users.models import UserRole
from couchforms.models import XFormInstance
from corehq.apps.domain.dbaccessors import get_doc_ids_in_domain_by_type, iterate_doc_ids_in_domain_by_type
from dimagi.utils.couch.database import get_db


class DBAccessorsTest(TestCase):

    @classmethod
    def setUpClass(cls):
        super(DBAccessorsTest, cls).setUpClass()
        cls.domain = 'domain-domain'
        cls.project = create_domain(cls.domain)
        cls.db = get_db()

    @classmethod
    def tearDownClass(cls):
        super(DBAccessorsTest, cls).tearDownClass()
        for snapshot in cls.project.snapshots():
            snapshot.delete()
        cls.project.delete()

    def test_get_doc_count_in_domain_by_class(self):
        case = CommCareCase(domain=self.domain, opened_on=datetime.datetime(2000, 1, 1))
        case.save()
        self.addCleanup(case.delete)
        case2 = CommCareCase(domain=self.domain, opened_on=datetime.datetime(2001, 1, 1))
        case2.save()
        self.addCleanup(case2.delete)

        get = functools.partial(
            get_doc_count_in_domain_by_class, self.domain, CommCareCase)

        self.assertEqual(get(), 2)
        self.assertEqual(get(start_date=datetime.datetime(1999, 7, 1)), 2)
        self.assertEqual(get(start_date=datetime.datetime(2000, 7, 1)), 1)
        self.assertEqual(get(start_date=datetime.datetime(2001, 7, 1)), 0)
        self.assertEqual(get(end_date=datetime.datetime(2001, 7, 1)), 2)
        self.assertEqual(get(end_date=datetime.datetime(2000, 7, 1)), 1)
        self.assertEqual(get(end_date=datetime.datetime(1999, 7, 1)), 0)

    def test_get_doc_ids_in_domain_by_class(self):
        user_role = UserRole(domain=self.domain)
        group = Group(domain=self.domain)
        xform = XFormInstance(domain=self.domain)
        user_role.save()
        group.save()
        xform.save()
        self.addCleanup(user_role.delete)
        self.addCleanup(group.delete)
        self.addCleanup(xform.delete)
        [doc_id] = get_doc_ids_in_domain_by_class(self.domain, UserRole)
        self.assertEqual(doc_id, user_role.get_id)

    def test_get_docs_in_domain_by_class(self):
        commtrack_config = CommtrackConfig(domain=self.domain)
        group = Group(domain=self.domain)
        xform = XFormInstance(domain=self.domain)
        commtrack_config.save()
        group.save()<commit_msg>Removed tests<commit_after>from __future__ import absolute_import
from __future__ import unicode_literals
import functools
import uuid
import datetime
from django.test import TestCase
from casexml.apps.case.models import CommCareCase
from corehq.apps.commtrack.models import CommtrackConfig
from corehq.apps.domain.dbaccessors import (
    count_downloads_for_all_snapshots,
    get_doc_count_in_domain_by_class,
    get_doc_ids_in_domain_by_class,
    get_docs_in_domain_by_class,
    get_domain_ids_by_names,
)
from corehq.apps.domain.models import Domain
from corehq.apps.domain.shortcuts import create_domain
from corehq.apps.groups.models import Group
from corehq.apps.users.models import UserRole
from couchforms.models import XFormInstance
from corehq.apps.domain.dbaccessors import get_doc_ids_in_domain_by_type, iterate_doc_ids_in_domain_by_type
from dimagi.utils.couch.database import get_db


class DBAccessorsTest(TestCase):

    @classmethod
    def setUpClass(cls):
        super(DBAccessorsTest, cls).setUpClass()
        cls.domain = 'domain-domain'
        cls.project = create_domain(cls.domain)
        cls.db = get_db()

    @classmethod
    def tearDownClass(cls):
        super(DBAccessorsTest, cls).tearDownClass()
        for snapshot in cls.project.snapshots():
            snapshot.delete()
        cls.project.delete()

    def test_get_doc_count_in_domain_by_class(self):
        case = CommCareCase(domain=self.domain, opened_on=datetime.datetime(2000, 1, 1))
        case.save()
        self.addCleanup(case.delete)
        case2 = CommCareCase(domain=self.domain, opened_on=datetime.datetime(2001, 1, 1))
        case2.save()
        self.addCleanup(case2.delete)

        get = functools.partial(
            get_doc_count_in_domain_by_class, self.domain, CommCareCase)

        self.assertEqual(get(), 2)

    def test_get_doc_ids_in_domain_by_class(self):
        user_role = UserRole(domain=self.domain)
        group = Group(domain=self.domain)
        xform = XFormInstance(domain=self.domain)
        user_role.save()
        group.save()
        xform.save()
        self.addCleanup(user_role.delete)
        self.addCleanup(group.delete)
        self.addCleanup(xform.delete)
        [doc_id] = get_doc_ids_in_domain_by_class(self.domain, UserRole)
        self.assertEqual(doc_id, user_role.get_id)

    def test_get_docs_in_domain_by_class(self):
        commtrack_config = CommtrackConfig(domain=self.domain)
        group = Group(domain=self.domain)
        xform = XFormInstance(domain=self.domain)
        commtrack_config.save()
        group.save()
{'fraction_non_alphanumeric': 0.09013484740951029, 'fraction_numerical': 0.01312987934705465, 'mean_word_length': 3.7053422370617697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2357222', 'n_tokens_mistral': 1887, 'n_tokens_neox': 1810, 'n_words': 302}