Пример #1
0
 def test_forms_are_in_index(self):
     for form in self.forms:
         self.assertFalse(doc_exists_in_es(XFORM_INDEX_INFO, form.wrapped_form.form_id))
     self._ship_forms_to_es([None, None])
     self.assertEqual(2, len(self.forms))
     for form in self.forms:
         self.assertTrue(doc_exists_in_es(XFORM_INDEX_INFO, form.wrapped_form.form_id))
Пример #2
0
 def test_forms_are_in_index(self):
     for form in self.forms:
         self.assertFalse(
             doc_exists_in_es(XFORM_INDEX_INFO, form.wrapped_form.form_id))
     self._ship_forms_to_es([None, None])
     self.assertEqual(2, len(self.forms))
     for form in self.forms:
         self.assertTrue(
             doc_exists_in_es(XFORM_INDEX_INFO, form.wrapped_form.form_id))
Пример #3
0
def update_unknown_user_from_form_if_necessary(es, doc_dict):
    if doc_dict is None:
        return

    user_id, username, domain, xform_id = _get_user_fields_from_form_doc(
        doc_dict)

    if (not user_id or user_id in WEIRD_USER_IDS
            or _user_exists_in_couch(user_id)):
        return

    if not doc_exists_in_es(USER_INDEX_INFO, user_id):
        doc_type = "AdminUser" if username == "admin" else "UnknownUser"
        doc = {
            "_id": user_id,
            "domain": domain,
            "username": username,
            "first_form_found_in": xform_id,
            "doc_type": doc_type,
        }
        if domain:
            doc["domain_membership"] = {"domain": domain}
        ElasticsearchInterface(es).create_doc(USER_INDEX_INFO.alias,
                                              ES_META['users'].type,
                                              doc=doc,
                                              doc_id=user_id)
Пример #4
0
def update_unknown_user_from_form_if_necessary(es, doc_dict):
    if doc_dict is None:
        return

    user_id, username, domain, xform_id = _get_user_fields_from_form_doc(
        doc_dict)

    if user_id in WEIRD_USER_IDS:
        user_id = None

    if not user_id:
        return

    if _user_exists_in_couch(user_id):
        return

    if not doc_exists_in_es(USER_INDEX_INFO, user_id):
        doc_type = "AdminUser" if username == "admin" else "UnknownUser"
        doc = {
            "_id": user_id,
            "domain": domain,
            "username": username,
            "first_form_found_in": xform_id,
            "doc_type": doc_type,
        }
        if domain:
            doc["domain_membership"] = {"domain": domain}
        es.create(USER_INDEX, ES_META['users'].type, body=doc, id=user_id)
Пример #5
0
def update_unknown_user_from_form_if_necessary(es, doc_dict):
    if doc_dict is None:
        return

    user_id, username, domain, xform_id = _get_user_fields_from_form_doc(doc_dict)

    if user_id in WEIRD_USER_IDS:
        user_id = None

    if user_id and not _user_exists(user_id) and not doc_exists_in_es(USER_INDEX_INFO, user_id):
        doc_type = "AdminUser" if username == "admin" else "UnknownUser"
        doc = {
            "_id": user_id,
            "domain": domain,
            "username": username,
            "first_form_found_in": xform_id,
            "doc_type": doc_type,
        }
        if domain:
            doc["domain_membership"] = {"domain": domain}
        es.create(USER_INDEX, ES_META["users"].type, body=doc, id=user_id)
Пример #6
0
    def test_sync_to_es_create_update_delete(self, *mocks):
        domain = 'user_es_domain'
        user = CommCareUser(domain=domain,
                            username='******',
                            _id=uuid.uuid4().hex,
                            is_active=True,
                            first_name='user1 first name',
                            last_name='user1 last name',
                            location_id='location1')
        user.save()

        self.check_user(user)

        user.first_name = 'new first name'
        user.save()
        self.check_user(user)

        # simulate retire without needing couch
        user.base_doc += DELETED_SUFFIX
        user.save()
        self.es.indices.refresh(USER_INDEX_INFO.index)
        self.assertFalse(doc_exists_in_es(USER_INDEX_INFO, user._id))
Пример #7
0
    def test_sync_to_es_create_update_delete(self, *mocks):
        domain = 'user_es_domain'
        user = CommCareUser(
            domain=domain,
            username='******',
            _id=uuid.uuid4().hex,
            is_active=True,
            first_name='user1 first name',
            last_name='user1 last name',
        )
        user.save()

        self.check_user(user)

        user.first_name = 'new first name'
        user.save()
        self.check_user(user)

        # simulate retire without needing couch
        user.base_doc += DELETED_SUFFIX
        user.save()
        self.es.indices.refresh(USER_INDEX_INFO.index)
        self.assertFalse(doc_exists_in_es(USER_INDEX_INFO, user._id))
Пример #8
0
def doc_exists(pillow, doc_id_or_dict):
    index_info = get_index_info_from_pillow(pillow)
    from corehq.elastic import doc_exists_in_es
    return doc_exists_in_es(index_info, doc_id_or_dict)
Пример #9
0
def doc_exists(pillow, doc_id_or_dict):
    index_info = get_index_info_from_pillow(pillow)
    from corehq.elastic import doc_exists_in_es
    return doc_exists_in_es(index_info, doc_id_or_dict)
Пример #10
0
 def _user_indexed(self, user_id):
     return doc_exists_in_es('users', user_id)