<commit_before>from uuid import uuid4

from django.conf import settings
from django.test import TestCase
from django.test.utils import override_settings
from unittest import skipUnless, SkipTest

from corehq.form_processor.models import XFormInstanceSQL, CommCareCaseSQL
from corehq.form_processor.tests.utils import create_form_for_test, FormProcessorTestUtils
from corehq.sql_db.config import PartitionConfig

DOMAIN = 'sharding-test'


@override_settings(ALLOW_FORM_PROCESSING_QUERIES=True)
@skipUnless(settings.USE_PARTITIONED_DATABASE, 'Only applicable if sharding is setup')
class ShardingTests(TestCase):
    dependent_apps = ['corehq.sql_accessors', 'corehq.sql_proxy_accessors']

    @classmethod
    def setUpClass(cls):
        super(ShardingTests, cls).setUpClass()
        if not settings.USE_PARTITIONED_DATABASE:
            # https://github.com/nose-devs/nose/issues/946
            raise SkipTest('Only applicable if sharding is setup')
        cls.partion_config = PartitionConfig()
        assert len(cls.partion_config.get_form_processing_dbs()) > 1

    def tearDown(self):
        FormProcessorTestUtils.delete_all_sql_forms(DOMAIN)
        FormProcessorTestUtils.delete_all_sql_cases(DOMAIN)
        super(ShardingTests, self).tearDown()

    def test_objects_only_in_one_db(self):
        case_id = uuid4().hex
        form = create_form_for_test(DOMAIN, case_id=case_id)

        dbs_with_form = []<commit_msg>only call setUpClass if test is not skipped<commit_after>from uuid import uuid4

from django.conf import settings
from django.test import TestCase
from django.test.utils import override_settings
from unittest import skipUnless, SkipTest

from corehq.form_processor.models import XFormInstanceSQL, CommCareCaseSQL
from corehq.form_processor.tests.utils import create_form_for_test, FormProcessorTestUtils
from corehq.sql_db.config import PartitionConfig

DOMAIN = 'sharding-test'


@override_settings(ALLOW_FORM_PROCESSING_QUERIES=True)
@skipUnless(settings.USE_PARTITIONED_DATABASE, 'Only applicable if sharding is setup')
class ShardingTests(TestCase):
    dependent_apps = ['corehq.sql_accessors', 'corehq.sql_proxy_accessors']

    @classmethod
    def setUpClass(cls):
        if not settings.USE_PARTITIONED_DATABASE:
            # https://github.com/nose-devs/nose/issues/946
            raise SkipTest('Only applicable if sharding is setup')
        super(ShardingTests, cls).setUpClass()
        cls.partion_config = PartitionConfig()
        assert len(cls.partion_config.get_form_processing_dbs()) > 1

    def tearDown(self):
        FormProcessorTestUtils.delete_all_sql_forms(DOMAIN)
        FormProcessorTestUtils.delete_all_sql_cases(DOMAIN)
        super(ShardingTests, self).tearDown()

    def test_objects_only_in_one_db(self):
        case_id = uuid4().hex
        form = create_form_for_test(DOMAIN, case_id=case_id)

        dbs_with_form = []
{'fraction_non_alphanumeric': 0.07724137931034483, 'fraction_numerical': 0.004137931034482759, 'mean_word_length': 4.536259541984733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5516472', 'n_tokens_mistral': 915, 'n_tokens_neox': 897, 'n_words': 177}