def setUp(self): with trap_extra_setup(ConnectionError): ensure_index_deleted(USER_INDEX) self.es_client = get_es_new() initialize_index_and_mapping(self.es_client, USER_INDEX_INFO) self.user_id = 'user1' _create_es_user(self.es_client, self.user_id, self.domain)
def setUp(self): self.es = get_es_new() self.index = TEST_INDEX_INFO.index with trap_extra_setup(ConnectionError): ensure_index_deleted(self.index) initialize_index_and_mapping(self.es, TEST_INDEX_INFO)
def setUpClass(cls): @patch('couchforms.analytics.FormES.index', XFORM_INDEX_INFO.index) @patch('corehq.apps.es.es_query.ES_META', TEST_ES_META) @patch('corehq.elastic.ES_META', TEST_ES_META) def create_form_and_sync_to_es(received_on): with process_kafka_changes('XFormToElasticsearchPillow'): with process_couch_changes('DefaultChangeFeedPillow'): metadata = TestFormMetadata(domain=cls.domain, app_id=cls.app_id, xmlns=cls.xmlns, received_on=received_on) form = get_form_ready_to_save(metadata, is_db_test=True) form_processor = FormProcessorInterface(domain=cls.domain) form_processor.save_processed_models([form]) return form from casexml.apps.case.tests.util import delete_all_xforms delete_all_xforms() cls.now = datetime.datetime.utcnow() cls._60_days = datetime.timedelta(days=60) cls.domain = 'my_crazy_analytics_domain' cls.app_id = uuid.uuid4().hex cls.xmlns = 'my://crazy.xmlns/' with trap_extra_setup(ConnectionError): cls.elasticsearch = get_es_new() initialize_index_and_mapping(cls.elasticsearch, XFORM_INDEX_INFO) cls.forms = [create_form_and_sync_to_es(cls.now), create_form_and_sync_to_es(cls.now-cls._60_days)] cls.elasticsearch.indices.refresh(XFORM_INDEX_INFO.index)
def setUpClass(cls): super(TestUserSyncToEs, cls).setUpClass() # create the index cls.es = get_es_new() with trap_extra_setup(ConnectionError): initialize_index_and_mapping(cls.es, USER_INDEX_INFO)
def setUpClass(cls): super(XFormESTestCase, cls).setUpClass() cls.now = datetime.datetime.utcnow() cls.forms = [] with trap_extra_setup(ConnectionError): cls.es = get_es_new() initialize_index_and_mapping(cls.es, XFORM_INDEX_INFO)
def build(self): """Returns a reindexer that will return either all domains with case search enabled, or a single domain if passed in """ limit_to_db = self.options.pop('limit_to_db', None) domain = self.options.pop('domain', None) limit_db_aliases = [limit_to_db] if limit_to_db else None initialize_index_and_mapping(get_es_new(), CASE_SEARCH_INDEX_INFO) try: if domain is not None: if not domain_needs_search_index(domain): raise CaseSearchNotEnabledException("{} does not have case search enabled".format(domain)) domains = [domain] else: # return changes for all enabled domains domains = domains_needing_search_index() change_provider = get_domain_case_change_provider(domains=domains, limit_db_aliases=limit_db_aliases) except ProgrammingError: # The db hasn't been intialized yet, so skip this reindex and complain. return _fail_gracefully_and_tell_admins() else: return PillowChangeProviderReindexer( get_case_search_processor(), change_provider=change_provider, )
def setUp(self): self.domain_obj = create_domain(self.domain) es = get_es_new() initialize_index_and_mapping(es, USER_INDEX_INFO) self.region = LocationType.objects.create(domain=self.domain, name="region") self.town = LocationType.objects.create(domain=self.domain, name="town", parent_type=self.region) self.data_source_config = DataSourceConfiguration( domain=self.domain, display_name='Locations in Westworld', referenced_doc_type='Location', table_id=clean_table_name(self.domain, str(uuid.uuid4().hex)), configured_filter={}, configured_indicators=[{ "type": "expression", "expression": { "type": "property_name", "property_name": "name" }, "column_id": "location_name", "display_name": "location_name", "datatype": "string" }], ) self.data_source_config.validate() self.data_source_config.save() self.pillow = get_location_pillow(ucr_configs=[self.data_source_config]) self.pillow.get_change_feed().get_latest_offsets()
def setUp(self): super(XFormPillowTest, self).setUp() FormProcessorTestUtils.delete_all_xforms() with trap_extra_setup(ConnectionError): self.elasticsearch = get_es_new() initialize_index_and_mapping(self.elasticsearch, XFORM_INDEX_INFO) delete_es_index(XFORM_INDEX_INFO.index)
def test_update_settings(self): initialize_index_and_mapping(self.es, TEST_INDEX_INFO) update_settings(self.es, self.index, INDEX_REINDEX_SETTINGS) index_settings_back = self.es.indices.get_settings(self.index)[self.index]['settings'] self._compare_es_dicts(INDEX_REINDEX_SETTINGS, index_settings_back, 'index') update_settings(self.es, self.index, INDEX_STANDARD_SETTINGS) index_settings_back = self.es.indices.get_settings(self.index)[self.index]['settings'] self._compare_es_dicts(INDEX_STANDARD_SETTINGS, index_settings_back, 'index')
def setUp(self): FormProcessorTestUtils.delete_all_cases(self.domain) FormProcessorTestUtils.delete_all_ledgers(self.domain) with trap_extra_setup(ConnectionError): self.pillow = get_ledger_to_elasticsearch_pillow() self.elasticsearch = get_es_new() ensure_index_deleted(LEDGER_INDEX_INFO.index) initialize_index_and_mapping(get_es_new(), LEDGER_INDEX_INFO)
def setUp(self): FormProcessorTestUtils.delete_all_cases() self.elasticsearch = get_es_new() self.pillow = get_case_search_to_elasticsearch_pillow() ensure_index_deleted(CASE_SEARCH_INDEX) # Bootstrap ES initialize_index_and_mapping(get_es_new(), CASE_SEARCH_INDEX_INFO)
def setUp(self): super(ReportCasePillowTest, self).setUp() FormProcessorTestUtils.delete_all_xforms() FormProcessorTestUtils.delete_all_cases() with trap_extra_setup(ConnectionError): self.elasticsearch = get_es_new() ensure_index_deleted(REPORT_CASE_INDEX_INFO.index) initialize_index_and_mapping(self.elasticsearch, REPORT_CASE_INDEX_INFO)
def setUp(self): super(AppPillowTest, self).setUp() FormProcessorTestUtils.delete_all_cases() with trap_extra_setup(ConnectionError): self.es = get_es_new() ensure_index_deleted(APP_INDEX_INFO.index) initialize_index_and_mapping(self.es, APP_INDEX_INFO)
def setUpClass(cls): super(TestFilterDslLookups, cls).setUpClass() with trap_extra_setup(ConnectionError): cls.es = get_es_new() initialize_index_and_mapping(cls.es, CASE_SEARCH_INDEX_INFO) cls.child_case_id = 'margaery' cls.parent_case_id = 'mace' cls.grandparent_case_id = 'olenna' cls.domain = "Tyrell" factory = CaseFactory(domain=cls.domain) grandparent_case = CaseStructure( case_id=cls.grandparent_case_id, attrs={ 'create': True, 'case_type': 'grandparent', 'update': { "name": "Olenna", "alias": "Queen of thorns", "house": "Tyrell", }, }) parent_case = CaseStructure( case_id=cls.parent_case_id, attrs={ 'create': True, 'case_type': 'parent', 'update': { "name": "Mace", "house": "Tyrell", }, }, indices=[CaseIndex( grandparent_case, identifier='mother', relationship='child', )]) child_case = CaseStructure( case_id=cls.child_case_id, attrs={ 'create': True, 'case_type': 'child', 'update': { "name": "Margaery", "house": "Tyrell", }, }, indices=[CaseIndex( parent_case, identifier='father', relationship='extension', )], ) for case in factory.create_or_update_cases([child_case]): send_to_elasticsearch('case_search', transform_case_for_elasticsearch(case.to_json())) cls.es.indices.refresh(CASE_SEARCH_INDEX_INFO.index)
def test_mapping_initialization(self): initialize_index_and_mapping(self.es, TEST_INDEX_INFO) self.assertTrue(mapping_exists(self.es, TEST_INDEX_INFO)) mapping = get_index_mapping(self.es, self.index, TEST_INDEX_INFO.type) # we can't compare the whole dicts because ES adds a bunch of stuff to them self.assertEqual( TEST_INDEX_INFO.mapping['properties']['doc_type']['index'], mapping['properties']['doc_type']['index'] )
def setUp(self): super(CaseSearchPillowTest, self).setUp() FormProcessorTestUtils.delete_all_cases() self.elasticsearch = get_es_new() self.pillow = get_case_pillow(skip_ucr=True) ensure_index_deleted(CASE_SEARCH_INDEX) # Bootstrap ES initialize_index_and_mapping(get_es_new(), CASE_SEARCH_INDEX_INFO)
def test_refresh_index(self): initialize_index_and_mapping(self.es, TEST_INDEX_INFO) doc_id = uuid.uuid4().hex doc = {'_id': doc_id, 'doc_type': 'CommCareCase', 'type': 'mother'} self.assertEqual(0, get_doc_count(self.es, self.index)) self.es.create(self.index, 'case', doc, id=doc_id) self.assertEqual(0, get_doc_count(self.es, self.index, refresh_first=False)) self.es.indices.refresh(self.index) self.assertEqual(1, get_doc_count(self.es, self.index, refresh_first=False))
def setUpClass(cls): cls.es = get_es_new() ensure_index_deleted(XFORM_INDEX_INFO.index) initialize_index_and_mapping(cls.es, XFORM_INDEX_INFO) cls._setup_domain_user() cls._setup_apps() cls._setup_forms() cls.es.indices.refresh(XFORM_INDEX_INFO.index) cls.run_malt_generation()
def setUp(self): self.username = '******' self.first_name = 'clark' self.last_name = 'kent' self.doc_type = 'CommCareUser' self.domain = 'user-esaccessors-test' self.es = get_es_new() ensure_index_deleted(USER_INDEX) initialize_index_and_mapping(self.es, USER_INDEX_INFO)
def pre_load_hook(self): if not self.in_place and self.own_index_exists: # delete the existing index. self.log("Deleting index") self.indexing_pillow.get_es_new().indices.delete(self.indexing_pillow.es_index) self.log("Recreating index") initialize_index_and_mapping( es=self.indexing_pillow.get_es_new(), index_info=get_index_info_from_pillow(self.indexing_pillow), )
def test_assume_alias(self): initialize_index_and_mapping(self.es, TEST_INDEX_INFO) doc_id = uuid.uuid4().hex doc = {'_id': doc_id, 'doc_type': 'CommCareCase', 'type': 'mother'} send_to_elasticsearch(self.index, TEST_INDEX_INFO.type, doc_id, get_es_new, 'test', doc) self.assertEqual(1, get_doc_count(self.es, self.index)) assume_alias(self.es, self.index, TEST_INDEX_INFO.alias) es_doc = self.es.get_source(TEST_INDEX_INFO.alias, TEST_INDEX_INFO.type, doc_id) for prop in doc: self.assertEqual(doc[prop], es_doc[prop])
def setUp(self): super(BaseESAccessorsTest, self).setUp() with trap_extra_setup(ConnectionError): self.es = get_es_new() self._delete_es_index() self.domain = uuid.uuid4().hex if isinstance(self.es_index_info, (list, tuple)): for index_info in self.es_index_info: initialize_index_and_mapping(self.es, index_info) else: initialize_index_and_mapping(self.es, self.es_index_info)
def test_index_operations(self): initialize_index_and_mapping(self.es, TEST_INDEX_INFO) self.assertTrue(self.es.indices.exists(self.index)) # delete and check self.es.indices.delete(self.index) self.assertFalse(self.es.indices.exists(self.index)) # create and check initialize_index(self.es, TEST_INDEX_INFO) self.assertTrue(self.es.indices.exists(self.index))
def test_create_index(self): initialize_index_and_mapping(self.es, TEST_INDEX_INFO) # make sure it was created self.assertTrue(self.es.indices.exists(self.index)) # check the subset of settings we expected to set settings_back = self.es.indices.get_settings(self.index)[self.index]['settings'] self.assertEqual( TEST_INDEX_INFO.meta['settings']['analysis'], settings_back['index']['analysis'], ) self.es.indices.delete(self.index) self.assertFalse(self.es.indices.exists(self.index))
def setUp(self): super(ReportUtilTests, self).setUp() self.user = CommCareUser.create(DOMAIN, 'user1', '***') self.request = Mock() self.request.method = 'POST' self.request.POST = {} self.request.project.commtrack_enabled = False self.request.couch_user = self.user.user_id with trap_extra_setup(ConnectionError): ensure_index_deleted(XFORM_INDEX_INFO.index) initialize_index_and_mapping(get_es_new(), XFORM_INDEX_INFO)
def test_request_succeeded(self): with trap_extra_setup(ConnectionError): elasticsearch_instance = get_es_new() initialize_index_and_mapping(elasticsearch_instance, CASE_INDEX_INFO) self.addCleanup(self._ensure_case_index_deleted) self.web_user.set_role(self.domain.name, 'admin') self.web_user.save() correct_credentials = self._get_correct_credentials() response = self._execute_query(correct_credentials) self.assertEqual(response.status_code, 200)
def test_groups_to_user_reindexer(self): initialize_index_and_mapping(self.es, USER_INDEX_INFO) user_id = uuid.uuid4().hex domain = 'test-groups-to-user-reindex' _create_es_user(self.es, user_id, domain) # create and save a group group = Group(domain=domain, name='g1', users=[user_id]) group.save() call_command('ptop_reindexer_v2', **{'index': 'groups-to-user', 'noinput': True}) self.es.indices.refresh(USER_INDEX) _assert_es_user_and_groups(self, self.es, user_id, [group._id], [group.name])
def test_groups_to_user_reindexer(self): initialize_index_and_mapping(self.es, USER_INDEX_INFO) user_id = uuid.uuid4().hex domain = 'test-groups-to-user-reindex' _create_es_user(self.es, user_id, domain) # create and save a group group = Group(domain=domain, name='g1', users=[user_id]) group.save() reindex_and_clean('groups-to-user') self.es.indices.refresh(USER_INDEX) _assert_es_user_and_groups(self, self.es, user_id, [group._id], [group.name])
def setUp(self): super(ExportTest, self).setUp() self._clear_docs() self.domain = create_domain(DOMAIN) self.setup_subscription(self.domain.name, SoftwarePlanEdition.ADVANCED) self.couch_user = WebUser.create(None, "test", "foobar") self.couch_user.add_domain_membership(DOMAIN, is_admin=True) self.couch_user.save() with trap_extra_setup(ConnectionError): self.es = get_es_new() ensure_index_deleted(XFORM_INDEX_INFO.index) initialize_index_and_mapping(self.es, XFORM_INDEX_INFO)
def setUpClass(cls): super(TestViews, cls).setUpClass() cls.project = Domain(name='app-manager-testviews-domain', is_active=True) cls.project.save() cls.username = '******' cls.password = '******' cls.user = WebUser.create(cls.project.name, cls.username, cls.password, is_active=True) cls.user.is_superuser = True cls.user.save() cls.build = add_build(version='2.7.0', build_number=20655) cls.es = get_es_new() initialize_index_and_mapping(cls.es, APP_INDEX_INFO) toggles.CUSTOM_PROPERTIES.set("domain:{domain}".format(domain=cls.project.name), True)
def test_create_index(self): initialize_index_and_mapping(self.es, TEST_INDEX_INFO) # make sure it was created self.assertTrue(self.es.indices.exists(self.index)) # check the subset of settings we expected to set settings_back = self.es.indices.get_settings( self.index)[self.index]['settings'] if settings.ELASTICSEARCH_VERSION < 1.0: self.assertEqual( 'whitespace', settings_back['index.analysis.analyzer.default.tokenizer']) self.assertEqual( 'lowercase', settings_back['index.analysis.analyzer.default.filter.0']) else: self.assertEqual( TEST_INDEX_INFO.meta['settings']['analysis'], settings_back['index']['analysis'], ) self.es.indices.delete(self.index) self.assertFalse(self.es.indices.exists(self.index))
def setUp(self): self.domain = create_domain(DOMAIN) self.user = CommCareUser.create(DOMAIN, USERNAME, PASSWORD, None, None) initialize_index_and_mapping(get_es_new(), CASE_SEARCH_INDEX_INFO) CaseSearchConfig.objects.get_or_create(pk=DOMAIN, enabled=True) delete_all_cases() self.case_id = uuid4().hex _, [self.case] = post_case_blocks([CaseBlock.deprecated_init( create=True, case_id=self.case_id, case_type=CASE_TYPE, case_name=CASE_NAME, external_id=CASE_NAME, user_id=OWNER_ID, owner_id=OWNER_ID, update={'opened_by': OWNER_ID}, ).as_xml()], {'domain': DOMAIN}) domains_needing_search_index.clear() CaseSearchReindexerFactory(domain=DOMAIN).build().reindex() es = get_es_new() es.indices.refresh(CASE_SEARCH_INDEX)
def setUpClass(cls): super().setUpClass() # Set up domains cls.domains = [ create_domain('state'), create_domain('county'), create_domain('staging'), ] # Set up users cls.web_user = WebUser.create('state', 'webu', 'badpassword', None, None, email='*****@*****.**', is_admin=True) cls.web_user.add_domain_membership('county') cls.web_user.add_domain_membership('staging') cls.web_user.save() cls.mobile_users = [ CommCareUser.create('state', "state_u", "123", None, None), CommCareUser.create("county", "county_u", "123", None, None), CommCareUser.create("staging", "staging_u", "123", None, None), ] # Set up permissions create_enterprise_permissions(cls.web_user.username, 'state', ['county'], ['staging']) cls.es = get_es_new() ensure_index_deleted(USER_INDEX) initialize_index_and_mapping(cls.es, USER_INDEX_INFO) for user_obj in cls.mobile_users: send_to_elasticsearch( 'users', transform_user_for_elasticsearch(user_obj.to_json())) cls.es.indices.refresh(USER_INDEX)
def setUpClass(cls): super(ExportTest, cls).setUpClass() with trap_extra_setup(ConnectionError, msg="cannot connect to elasicsearch"): cls.es = get_es_new() initialize_index_and_mapping(cls.es, CASE_INDEX_INFO) case = new_case(foo="apple", bar="banana", date='2016-4-24') send_to_elasticsearch('cases', case.to_json()) case = new_case(owner_id="some_other_owner", foo="apple", bar="banana", date='2016-4-04') send_to_elasticsearch('cases', case.to_json()) case = new_case(type="some_other_type", foo="apple", bar="banana") send_to_elasticsearch('cases', case.to_json()) case = new_case(closed=True, foo="apple", bar="banana") send_to_elasticsearch('cases', case.to_json()) cls.es.indices.refresh(CASE_INDEX_INFO.index)
def test_assume_alias_deletes_old_aliases(self): # create a different index and set the alias for it initialize_index_and_mapping(self.es, TEST_INDEX_INFO) new_index = 'test_index-with-duplicate-alias' if not self.es.indices.exists(new_index): self.es.indices.create(index=new_index) self.es.indices.put_alias(new_index, TEST_INDEX_INFO.alias) self.addCleanup(functools.partial(ensure_index_deleted, new_index)) # make sure it's there in the other index aliases = self.es_interface.get_aliases() # NOTE: alias is currently applied to *both* indices now because the # `initialize_index_and_mapping` helper function both creates the index # and applies an alias to the (new) index. The `assertIn()` test is used # here as to not make this test depend on that implied functionality of # the helper function. self.assertIn(new_index, aliases[TEST_INDEX_INFO.alias]) # assume alias and make sure it's removed (and added to the right index) assume_alias(self.es, self.index, TEST_INDEX_INFO.alias) aliases = self.es_interface.get_aliases() self.assertEqual([self.index], aliases[TEST_INDEX_INFO.alias])
def setUpClass(cls): ensure_index_deleted(LEDGER_INDEX_INFO.index) es = get_es_new() initialize_index_and_mapping(es, LEDGER_INDEX_INFO) cls.expected_combos = { ('stock', 'product_a'), ('stock', 'product_b'), ('consumption', 'product_a'), ('consumption', 'product_c'), } for section, entry in cls.expected_combos: ledger = LedgerValue( domain=cls.domain, case_id=uuid.uuid4().hex, section_id=section, entry_id=entry, ) ledger_json = ledger.to_json(include_location_id=False) ledger_json['_id'] = ledger.ledger_reference.as_id() send_to_elasticsearch('ledgers', doc=ledger_json) es.indices.refresh(LEDGER_INDEX_INFO.index)
def get_case_search_reindexer(domain=None): """Returns a reindexer that will return either all domains with case search enabled, or a single domain if passed in """ initialize_index_and_mapping(get_es_new(), CASE_SEARCH_INDEX_INFO) try: if domain is not None: if not case_search_enabled_for_domain(domain): raise CaseSearchNotEnabledException( "{} does not have case search enabled".format(domain)) domains = [domain] else: # return changes for all enabled domains domains = case_search_enabled_domains() change_provider = get_domain_case_change_provider(domains=domains) except ProgrammingError: # The db hasn't been intialized yet, so skip this reindex and complain. return _fail_gracefully_and_tell_admins() else: return PillowChangeProviderReindexer( get_case_search_to_elasticsearch_pillow(), change_provider=change_provider)
def setUpClass(cls): super(ExportsFormsAnalyticsTest, cls).setUpClass() from casexml.apps.case.tests.util import delete_all_xforms from corehq.apps.app_manager.models import Application, Module, Form delete_all_xforms() with trap_extra_setup(ConnectionError, msg="cannot connect to elasicsearch"): cls.es = get_es_new() initialize_index_and_mapping(cls.es, XFORM_INDEX_INFO) cls.domain = 'exports_forms_analytics_domain' cls.app_id_1 = 'a' + uuid.uuid4().hex cls.app_id_2 = 'b' + uuid.uuid4().hex cls.xmlns_1 = 'my://crazy.xmlns/' cls.xmlns_2 = 'my://crazy.xmlns/app' cls.apps = [ Application(_id=cls.app_id_2, domain=cls.domain, modules=[Module(forms=[Form(xmlns=cls.xmlns_2)])]) ] for app in cls.apps: app.save() cls.forms = [ XFormInstance(domain=cls.domain, app_id=cls.app_id_1, xmlns=cls.xmlns_1), XFormInstance(domain=cls.domain, app_id=cls.app_id_1, xmlns=cls.xmlns_1), XFormInstance(domain=cls.domain, app_id=cls.app_id_2, xmlns=cls.xmlns_2), ] cls.error_forms = [XFormError(domain=cls.domain)] cls.all_forms = cls.forms + cls.error_forms for form in cls.all_forms: form.save() send_to_elasticsearch('forms', form.to_json()) cls.es.indices.refresh(XFORM_INDEX_INFO.index) update_analytics_indexes()
def test_update_parent(self): es = get_es_new() with trap_extra_setup(ConnectionError): initialize_index_and_mapping(es, CASE_SEARCH_INDEX_INFO) self.addCleanup(ensure_index_deleted, CASE_SEARCH_INDEX_INFO.index) duplicates, uniques = self._create_cases(num_cases=2) parent = uniques[0] child = duplicates[0] set_parent_case(self.domain, child, parent) parent_case_property_value = parent.get_case_property('name') new_parent_case_property_value = f'{parent_case_property_value}-someextratext' self.action.set_properties_to_update([ CaseDeduplicationActionDefinition.PropertyDefinition( name='parent/name', value_type=CaseDeduplicationActionDefinition.VALUE_TYPE_EXACT, value=new_parent_case_property_value, ) ]) self.action.save() for case in chain(duplicates, uniques): send_to_elasticsearch( 'case_search', transform_case_for_elasticsearch(case.to_json())) es.indices.refresh(CASE_SEARCH_INDEX_INFO.index) self.rule = AutomaticUpdateRule.objects.get(id=self.rule.id) self.rule.run_actions_when_case_matches(child) updated_parent_case = CommCareCase.objects.get_case( parent.case_id, self.domain) self.assertEqual(updated_parent_case.get_case_property('name'), new_parent_case_property_value)
def setUpClass(cls): super().setUpClass() cls.elasticsearch = get_es_new() initialize_index_and_mapping(cls.elasticsearch, USER_INDEX_INFO) cls.domain = 'test-user-es' cls.domain_obj = create_domain(cls.domain) with sync_users_to_es(): cls._create_mobile_worker('stark', metadata={ 'sigil': 'direwolf', 'seat': 'Winterfell' }) cls._create_mobile_worker('lannister', metadata={ 'sigil': 'lion', 'seat': 'Casterly Rock' }) cls._create_mobile_worker('targaryen', metadata={ 'sigil': 'dragon', 'false_sigil': 'direwolf' }) cls.elasticsearch.indices.refresh(USER_INDEX)
def test_users_assigned(self): self.es = get_es_new() ensure_index_deleted(USER_INDEX) initialize_index_and_mapping(self.es, USER_INDEX_INFO) user = CommCareUser.create(self.domain, 'pentagon', '*****', None, None, metadata={ PROFILE_SLUG: self.profile5.id, }) self.addCleanup(user.delete, deleted_by=None) send_to_elasticsearch('users', transform_user_for_elasticsearch(user.to_json())) self.es.indices.refresh(USER_INDEX) self.assertFalse(self.profile3.has_users_assigned) self.assertEqual([], self.profile3.user_ids_assigned()) self.assertTrue(self.profile5.has_users_assigned) self.assertEqual([user._id], self.profile5.user_ids_assigned()) ensure_index_deleted(USER_INDEX)
def test_many_duplicates(self): """Test what happens if there are over DUPLICATE_LIMIT matches """ es = get_es_new() with trap_extra_setup(ConnectionError): initialize_index_and_mapping(es, CASE_SEARCH_INDEX_INFO) self.addCleanup(ensure_index_deleted, CASE_SEARCH_INDEX_INFO.index) num_duplicates = 6 duplicates, uniques = self._create_cases(num_duplicates) for case in chain(duplicates, uniques): send_to_elasticsearch( 'case_search', transform_case_for_elasticsearch(case.to_json())) es.indices.refresh(CASE_SEARCH_INDEX_INFO.index) self.rule.run_actions_when_case_matches(duplicates[0]) duplicate_case_ids = CaseDuplicate.objects.all().values_list("case_id", flat=True) self.assertTrue( set(case.case_id for case in duplicates[0:3]) & set(duplicate_case_ids))
def setUpClass(cls): with trap_extra_setup(ConnectionError, msg="cannot connect to elasicsearch"): es = get_es_new() cls.tearDownClass() initialize_index_and_mapping(es, CASE_INDEX_INFO) initialize_index_and_mapping(es, GROUP_INDEX_INFO) initialize_index_and_mapping(es, XFORM_INDEX_INFO) case = new_case(closed=True) send_to_elasticsearch('cases', case.to_json()) case = new_case(closed=False) send_to_elasticsearch('cases', case.to_json()) case = new_case(closed=True, owner_id="foo") send_to_elasticsearch('cases', case.to_json()) case = new_case(closed=False, owner_id="bar") send_to_elasticsearch('cases', case.to_json()) group = Group(_id=uuid.uuid4().hex, users=["foo", "bar"]) cls.group_id = group._id send_to_elasticsearch('groups', group.to_json()) form = new_form(form={"meta": {"userID": None}}) send_to_elasticsearch('forms', form.to_json()) form = new_form(form={"meta": {"userID": ""}}) send_to_elasticsearch('forms', form.to_json()) form = new_form(form={"meta": {"deviceID": "abc"}}) send_to_elasticsearch('forms', form.to_json()) form = new_form(form={"meta": {"userID": uuid.uuid4().hex}}) send_to_elasticsearch('forms', form.to_json()) es.indices.refresh(CASE_INDEX_INFO.index) es.indices.refresh(XFORM_INDEX_INFO.index) es.indices.refresh(GROUP_INDEX_INFO.index)
def setUpClass(cls): super().setUpClass() cls.domain = 'case-list-test' cls.user = WebUser(username='******', domains=[cls.domain]) cls.user.domain_memberships = [ DomainMembership(domain=cls.domain, role_id='admin') ] UserRole.init_domain_with_presets(cls.domain) cls.request_factory = RequestFactory() from corehq.apps.reports.tests.data.case_list_report_data import ( dummy_case_list, dummy_user_list, ) for user in dummy_user_list: user_obj = CouchUser.get_by_username(user['username']) if user_obj: user_obj.delete('') cls.user_list = [] for user in dummy_user_list: user_obj = CommCareUser.create(**user) if user['doc_type'] == 'CommcareUser'\ else WebUser.create(**user) user_obj.save() cls.user_list.append(user_obj) cls.case_list = [] for case in dummy_case_list: cls.case_list.append(CommCareCase(**case)) cls.es = get_es_new() ensure_index_deleted(USER_INDEX) ensure_index_deleted(CASE_INDEX) initialize_index_and_mapping(cls.es, USER_INDEX_INFO) initialize_index_and_mapping(cls.es, CASE_INDEX_INFO) initialize_index_and_mapping(cls.es, GROUP_INDEX_INFO) cls._send_users_to_es() cls._send_cases_to_es()
def setUpClass(cls): super(PillowtopReindexerTest, cls).setUpClass() with trap_extra_setup(ConnectionError): initialize_index_and_mapping(get_es_new(), CASE_INDEX_INFO)
def setUpClass(cls): super(GroupsToUserReindexerTest, cls).setUpClass() cls.es = get_es_new() ensure_index_deleted(USER_INDEX) initialize_index_and_mapping(cls.es, USER_INDEX_INFO)
def setUp(self): ensure_index_deleted(USER_INDEX) self.es_client = get_es_new() initialize_index_and_mapping(self.es_client, USER_INDEX_INFO)
def prepare_index_for_reindex(es, index_info): initialize_index_and_mapping(es, index_info) set_index_reindex_settings(es, index_info.index)
def setUp(self): super(ESAccessorsTest, self).setUp() with trap_extra_setup(ConnectionError): self.elasticsearch = get_es_new() initialize_index_and_mapping(self.elasticsearch, CASE_INDEX_INFO) initialize_index_and_mapping(self.elasticsearch, DOMAIN_INDEX_INFO)
def setUp(self): super(TestUserESAccessors, self).setUp() self.es = get_es_new() ensure_index_deleted(USER_INDEX) initialize_index_and_mapping(self.es, USER_INDEX_INFO)
def setUp(self): self.es = get_es_new() reset_es_index(CASE_INDEX_INFO) initialize_index_and_mapping(self.es, CASE_INDEX_INFO)
def setUpClass(cls): cls.now = datetime.datetime.utcnow() cls.forms = [] with trap_extra_setup(ConnectionError): cls.es = get_es_new() initialize_index_and_mapping(cls.es, XFORM_INDEX_INFO)
def setUpClass(cls): super(TestGroupUserIds, cls).setUpClass() ensure_index_deleted(GROUP_INDEX_INFO.index) cls.es = get_es_new() initialize_index_and_mapping(cls.es, GROUP_INDEX_INFO) cls.es.indices.refresh(GROUP_INDEX_INFO.index)
def setUpClass(cls): super().setUpClass() cls.es = get_es_new() initialize_index_and_mapping(cls.es, USER_INDEX_INFO)
def setUp(self): super(MaltAnalyticsTest, self).setUp() ensure_index_deleted(XFORM_INDEX_INFO.index) initialize_index_and_mapping(self.es, XFORM_INDEX_INFO)
def _setup_es_index(index_info): with trap_extra_setup(ConnectionError): elasticsearch_instance = get_es_new() initialize_index_and_mapping(elasticsearch_instance, index_info)
def setUp(self): initialize_index_and_mapping(self.es, USER_INDEX_INFO)
def test_set_index_normal(self): initialize_index_and_mapping(self.es, TEST_INDEX_INFO) set_index_normal_settings(self.es, self.index) index_settings_back = self.es.indices.get_settings( self.index)[self.index]['settings'] self._compare_es_dicts(INDEX_STANDARD_SETTINGS, index_settings_back)
def setUp(self): for es in self.es: ensure_index_deleted(es['info'].index) initialize_index_and_mapping(es['instance'], es['info'])
def setUpClass(cls): super(TestFixFormsWithMissingXmlns, cls).setUpClass() cls.es = get_es_new() with trap_extra_setup(ConnectionError, msg="cannot connect to elasicsearch"): initialize_index_and_mapping(cls.es, XFORM_INDEX_INFO)