class TestCaseESAccessorsSQL(TestCaseESAccessors):
    def _send_case_to_es(self,
                         domain=None,
                         owner_id=None,
                         user_id=None,
                         case_type=None,
                         opened_on=None,
                         closed_on=None):

        case = CommCareCaseSQL(case_id=uuid.uuid4().hex,
                               domain=domain or self.domain,
                               owner_id=owner_id or self.owner_id,
                               modified_by=user_id or self.user_id,
                               type=case_type or self.case_type,
                               opened_on=opened_on or datetime.now(),
                               opened_by=user_id or self.user_id,
                               closed_on=closed_on,
                               modified_on=datetime.now(),
                               closed_by=user_id or self.user_id,
                               server_modified_on=datetime.utcnow(),
                               closed=bool(closed_on))

        case.track_create(
            CaseTransaction(
                type=CaseTransaction.TYPE_FORM,
                form_id=uuid.uuid4().hex,
                case=case,
                server_date=opened_on,
            ))
示例#2
0
def create_case(case) -> CommCareCaseSQL:
    form = XFormInstanceSQL(
        form_id=uuid4().hex,
        xmlns='http://commcarehq.org/formdesigner/form-processor',
        received_on=case.server_modified_on,
        user_id=case.owner_id,
        domain=case.domain,
    )
    transaction = CaseTransaction(
        type=CaseTransaction.TYPE_FORM,
        form_id=form.form_id,
        case=case,
        server_date=case.server_modified_on,
    )
    with patch.object(FormProcessorSQL, "publish_changes_to_kafka"):
        case.track_create(transaction)
        processed_forms = ProcessedForms(form, [])
        FormProcessorSQL.save_processed_models(processed_forms, [case])
示例#3
0
    def get_case(self, case_json=None):
        utcnow = datetime.utcnow()
        case_json = self.props if case_json is None else case_json
        intent_case = CommCareCase(
            domain=SOURCE_DOMAIN,
            type=self.CASE_TYPE,
            case_json=case_json,
            case_id=uuid.uuid4().hex,
            user_id="local_user1",
            opened_on=utcnow,
            modified_on=utcnow,
        )
        intent_case.track_create(CaseTransaction(form_id="form123", type=CaseTransaction.TYPE_FORM))

        def _mock_subcases(*args, **kwargs):
            return self.subcases

        intent_case.get_subcases = _mock_subcases
        return intent_case
示例#4
0
class TestCaseESAccessors(BaseESAccessorsTest):

    es_index_infos = [CASE_INDEX_INFO, USER_INDEX_INFO]

    def setUp(self):
        super(TestCaseESAccessors, self).setUp()
        self.owner_id = 'batman'
        self.user_id = 'robin'
        self.case_type = 'heroes'

    def _send_case_to_es(self,
                         domain=None,
                         owner_id=None,
                         user_id=None,
                         case_type=None,
                         opened_on=None,
                         closed_on=None,
                         modified_on=None):

        case = CommCareCase(case_id=uuid.uuid4().hex,
                            domain=domain or self.domain,
                            owner_id=owner_id or self.owner_id,
                            modified_by=user_id or self.user_id,
                            type=case_type or self.case_type,
                            opened_on=opened_on or datetime.now(),
                            opened_by=user_id or self.user_id,
                            closed_on=closed_on,
                            modified_on=modified_on or datetime.now(),
                            closed_by=user_id or self.user_id,
                            server_modified_on=datetime.utcnow(),
                            closed=bool(closed_on))

        case.track_create(
            CaseTransaction(
                type=CaseTransaction.TYPE_FORM,
                form_id=uuid.uuid4().hex,
                case=case,
                server_date=opened_on,
            ))