コード例 #1
0
ファイル: test_utils.py プロジェクト: saketkanth/commcare-hq
def create_and_save_a_case(domain, case_id, case_name, case_properties=None, case_type=None,
        drop_signals=True, owner_id=None, user_id=None):
    from casexml.apps.case.signals import case_post_save
    from corehq.form_processor.signals import sql_case_post_save

    kwargs = {
        'create': True,
        'case_id': case_id,
        'case_name': case_name,
        'update': case_properties,
    }

    if case_type:
        kwargs['case_type'] = case_type

    if owner_id:
        kwargs['owner_id'] = owner_id

    if user_id:
        kwargs['user_id'] = user_id

    if drop_signals:
        # this avoids having to deal with all the reminders code bootstrap
        with drop_connected_signals(case_post_save), drop_connected_signals(sql_case_post_save):
            form, cases = _create_case(domain, **kwargs)
    else:
        form, cases = _create_case(domain, **kwargs)

    return cases[0]
コード例 #2
0
def create_and_save_a_case(domain, case_id, case_name, case_properties=None, case_type=None,
        drop_signals=True, owner_id=None, user_id=None):
    from casexml.apps.case.signals import case_post_save
    from corehq.form_processor.signals import sql_case_post_save

    kwargs = {
        'create': True,
        'case_id': case_id,
        'case_name': case_name,
        'update': case_properties,
    }

    if case_type:
        kwargs['case_type'] = case_type

    if owner_id:
        kwargs['owner_id'] = owner_id

    if user_id:
        kwargs['user_id'] = user_id

    if drop_signals:
        # this avoids having to deal with all the reminders code bootstrap
        with drop_connected_signals(case_post_save), drop_connected_signals(sql_case_post_save):
            form, cases = _create_case(domain, **kwargs)
    else:
        form, cases = _create_case(domain, **kwargs)

    return cases[0]
コード例 #3
0
    def test_rule(self):
        now = datetime(2015, 10, 22, 0, 0)
        with patch(
                'corehq.apps.data_interfaces.models.AutomaticUpdateRule.get_case_ids',
                new=self._get_case_ids):
            # No update: both dates are 27 days away
            last_modified = datetime(2015, 9, 25, 12, 0)
            _update_case(self.domain, self.case_id, last_modified,
                         date(2015, 9, 25))
            self._assert_case_revision(2, last_modified)
            run_case_update_rules_for_domain(self.domain, now=now)
            self._assert_case_revision(2, last_modified)

            # No update: server_modified_on is 32 days away but last_visit_date is 27 days away
            last_modified = datetime(2015, 9, 20, 12, 0)
            _update_case(self.domain, self.case_id, last_modified,
                         date(2015, 9, 25))
            self._assert_case_revision(3, last_modified)
            run_case_update_rules_for_domain(self.domain, now=now)
            self._assert_case_revision(3, last_modified)

            # No update: last_visit_date is 32 days away but server_modified_on is 27 days away
            last_modified = datetime(2015, 9, 25, 12, 0)
            _update_case(self.domain, self.case_id, last_modified,
                         date(2015, 9, 20))
            self._assert_case_revision(4, last_modified)
            run_case_update_rules_for_domain(self.domain, now=now)
            self._assert_case_revision(4, last_modified)

            # Perform update: both dates are 32 days away
            last_modified = datetime(2015, 9, 20, 12, 0)
            _update_case(self.domain, self.case_id, last_modified,
                         date(2015, 9, 20))
            self._assert_case_revision(5, last_modified)
            with drop_connected_signals(case_post_save):
                run_case_update_rules_for_domain(self.domain, now=now)
            self._assert_case_revision(6, last_modified, True)

            case = self._get_case()
            self.assertEqual(case.get_case_property('update_flag'), 'Y')

            # No update: case state matches final state
            _update_case(self.domain, self.case_id, last_modified,
                         date(2015, 9, 20))
            self._assert_case_revision(7, last_modified)
            with drop_connected_signals(case_post_save):
                run_case_update_rules_for_domain(self.domain, now=now)
            self._assert_case_revision(7, last_modified)

            # Perform update: case closed because date is 42 days away
            _update_case(self.domain, self.case_id, last_modified,
                         date(2015, 9, 10))
            with drop_connected_signals(case_post_save):
                run_case_update_rules_for_domain(self.domain, now=now)

            case = self._get_case()
            self.assertEqual(case.get_case_property('update_flag'), 'C')
            self.assertEqual(case.closed, True)
コード例 #4
0
    def test_rule(self):
        now = datetime(2015, 10, 22, 0, 0)
        with patch('corehq.apps.data_interfaces.models.AutomaticUpdateRule.get_case_ids', new=self._get_case_ids):
            # No update: both dates are 27 days away
            last_modified = datetime(2015, 9, 25, 12, 0)
            _update_case(self.domain, self.case_id, last_modified, date(2015, 9, 25))
            self._assert_case_revision(2, last_modified)
            run_case_update_rules_for_domain(self.domain, now=now)
            self._assert_case_revision(2, last_modified)

            # No update: server_modified_on is 32 days away but last_visit_date is 27 days away
            last_modified = datetime(2015, 9, 20, 12, 0)
            _update_case(self.domain, self.case_id, last_modified, date(2015, 9, 25))
            self._assert_case_revision(3, last_modified)
            run_case_update_rules_for_domain(self.domain, now=now)
            self._assert_case_revision(3, last_modified)

            # No update: last_visit_date is 32 days away but server_modified_on is 27 days away
            last_modified = datetime(2015, 9, 25, 12, 0)
            _update_case(self.domain, self.case_id, last_modified, date(2015, 9, 20))
            self._assert_case_revision(4, last_modified)
            run_case_update_rules_for_domain(self.domain, now=now)
            self._assert_case_revision(4, last_modified)

            # Perform update: both dates are 32 days away
            last_modified = datetime(2015, 9, 20, 12, 0)
            _update_case(self.domain, self.case_id, last_modified, date(2015, 9, 20))
            self._assert_case_revision(5, last_modified)
            with drop_connected_signals(case_post_save):
                run_case_update_rules_for_domain(self.domain, now=now)
            self._assert_case_revision(6, last_modified, True)

            case = self._get_case()
            self.assertEqual(case.get_case_property('update_flag'), 'Y')

            # No update: case state matches final state
            _update_case(self.domain, self.case_id, last_modified, date(2015, 9, 20))
            self._assert_case_revision(7, last_modified)
            with drop_connected_signals(case_post_save):
                run_case_update_rules_for_domain(self.domain, now=now)
            self._assert_case_revision(7, last_modified)

            # Perform update: case closed because date is 42 days away
            _update_case(self.domain, self.case_id, last_modified, date(2015, 9, 10))
            with drop_connected_signals(case_post_save):
                run_case_update_rules_for_domain(self.domain, now=now)

            case = self._get_case()
            self.assertEqual(case.get_case_property('update_flag'), 'C')
            self.assertEqual(case.closed, True)
コード例 #5
0
def _with_case(domain, case_type, last_modified, **kwargs):
    with drop_connected_signals(case_post_save), drop_connected_signals(sql_case_post_save):
        case = CaseFactory(domain).create_case(case_type=case_type, **kwargs)

    _update_case(domain, case.case_id, last_modified)
    accessors = CaseAccessors(domain)
    case = accessors.get_case(case.case_id)
    try:
        yield case
    finally:
        if should_use_sql_backend(domain):
            CaseAccessorSQL.hard_delete_cases(domain, [case.case_id])
        else:
            case.delete()
コード例 #6
0
    def setUpClass(cls):
        super(TestCaseDelayedSchema, cls).setUpClass()
        factory = AppFactory(domain=cls.domain)
        module1, form1 = factory.new_basic_module('update_case', cls.case_type)
        factory.form_requires_case(form1, cls.case_type, update={
            'age': '/data/age',
            'height': '/data/height',
        })
        cls.current_app = factory.app
        cls.current_app._id = '1234'

        factory = AppFactory(domain=cls.domain)
        module1, form1 = factory.new_basic_module('update_case', cls.case_type)
        factory.form_requires_case(form1, cls.case_type, update={
            'age': '/data/age',
            'height': '/data/height',
            'weight': '/data/weight',
        })
        cls.build = factory.app
        cls.build.copy_of = cls.current_app._id
        cls.build.version = 5
        cls.build.has_submissions = True

        cls.apps = [
            cls.current_app,
            cls.build,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #7
0
    def setUpClass(cls):
        super().setUpClass()
        cls.domain = uuid.uuid4().hex
        cls.case_ids = [uuid.uuid4().hex for i in range(4)]
        with drop_connected_signals(case_post_save), drop_connected_signals(
                sql_case_post_save):
            for case_id in cls.case_ids:
                create_form_for_test(cls.domain, case_id)

        cls.es = get_es_new()
        cls.es_interface = ElasticsearchInterface(cls.es)
        cls.index = TEST_INDEX_INFO.index

        with trap_extra_setup(ConnectionError):
            ensure_index_deleted(cls.index)
            initialize_index_and_mapping(cls.es, TEST_INDEX_INFO)
コード例 #8
0
    def setUpClass(cls):
        super(TestBuildingCaseSchemaFromMultipleApplications, cls).setUpClass()
        cls.current_app = Application.wrap(cls.get_json('basic_case_application'))
        cls.other_current_app = Application.wrap(cls.get_json('basic_case_application'))
        cls.other_current_app._id = 'other-app-id'

        cls.first_build = Application.wrap(cls.get_json('basic_case_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3

        cls.other_build = Application.wrap(cls.get_json('basic_case_application'))
        cls.other_build._id = '456'
        cls.other_build.copy_of = cls.other_current_app._id
        cls.other_build.version = 4
        cls.other_build.has_submissions = True

        cls.apps = [
            cls.current_app,
            cls.other_current_app,
            cls.first_build,
            cls.other_build,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #9
0
    def test_build_from_saved_schema(self):
        app = self.current_app

        schema = CaseExportDataSchema.generate_schema_from_builds(
            app.domain,
            app._id,
            self.case_type,
        )

        self.assertEqual(schema.last_app_versions[app._id], app.version)
        # One for case, one for case history
        self.assertEqual(len(schema.group_schemas), 2)

        # After the first schema has been saved let's add a second app to process
        second_build = Application.wrap(self.get_json('basic_case_application'))
        second_build._id = '456'
        second_build.copy_of = app.get_id
        second_build.version = 6
        with drop_connected_signals(app_post_save):
            second_build.save()
        self.addCleanup(second_build.delete)

        new_schema = CaseExportDataSchema.generate_schema_from_builds(
            app.domain,
            app._id,
            self.case_type,
        )

        self.assertEqual(new_schema._id, schema._id)
        self.assertEqual(new_schema.last_app_versions[app._id], app.version)
        # One for case, one for case history
        self.assertEqual(len(new_schema.group_schemas), 2)
コード例 #10
0
    def test_build_from_saved_schema(self):
        app = self.current_app

        schema = CaseExportDataSchema.generate_schema_from_builds(
            app.domain,
            app._id,
            self.case_type,
        )

        self.assertEqual(schema.last_app_versions[app._id], app.version)
        # One for case, one for case history
        self.assertEqual(len(schema.group_schemas), 2)

        # After the first schema has been saved let's add a second app to process
        second_build = Application.wrap(self.get_json('basic_case_application'))
        second_build._id = '456'
        second_build.copy_of = app.get_id
        second_build.version = 6
        with drop_connected_signals(app_post_save):
            second_build.save()
        self.addCleanup(second_build.delete)

        new_schema = CaseExportDataSchema.generate_schema_from_builds(
            app.domain,
            app._id,
            self.case_type,
        )

        self.assertEqual(new_schema._id, schema._id)
        self.assertEqual(new_schema.last_app_versions[app._id], app.version)
        # One for case, one for case history
        self.assertEqual(len(new_schema.group_schemas), 2)
コード例 #11
0
    def setUpClass(cls):
        super(TestDelayedSchema, cls).setUpClass()
        cls.current_app = Application.new_app(cls.domain,
                                              "Untitled Application")
        cls.current_app._id = '1234'
        cls.current_app.version = 10
        module = cls.current_app.add_module(
            Module.new_module('Untitled Module', None))
        form = module.new_form(
            "Untitled Form",
            'en',
            attachment=cls.get_xml('basic_form').decode('utf-8'))
        form.xmlns = cls.xmlns

        cls.build = Application.new_app(cls.domain, "Untitled Application")
        cls.build._id = '5678'
        cls.build.copy_of = cls.current_app._id
        cls.build.version = 5
        cls.build.has_submissions = True
        module = cls.build.add_module(
            Module.new_module('Untitled Module', None))
        form = module.new_form(
            "Untitled Form",
            'en',
            attachment=cls.get_xml('basic_form_version2').decode('utf-8'))
        form.xmlns = cls.xmlns

        cls.apps = [
            cls.current_app,
            cls.build,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #12
0
    def setUpClass(cls):
        super(TestBuildingCaseSchemaFromMultipleApplications, cls).setUpClass()
        cls.current_app = Application.wrap(
            cls.get_json('basic_case_application'))
        cls.other_current_app = Application.wrap(
            cls.get_json('basic_case_application'))
        cls.other_current_app._id = 'other-app-id'

        cls.first_build = Application.wrap(
            cls.get_json('basic_case_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3

        cls.other_build = Application.wrap(
            cls.get_json('basic_case_application'))
        cls.other_build._id = '456'
        cls.other_build.copy_of = cls.other_current_app._id
        cls.other_build.version = 4
        cls.other_build.has_submissions = True

        cls.apps = [
            cls.current_app,
            cls.other_current_app,
            cls.first_build,
            cls.other_build,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #13
0
    def setUpClass(cls):
        cls.current_app = Application.wrap(cls.get_json('basic_application'))

        cls.first_build = Application.wrap(cls.get_json('basic_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3
        cls.first_build.has_submissions = True

        cls.advanced_app = Application.new_app('domain', "Untitled Application")
        module = cls.advanced_app.add_module(AdvancedModule.new_module('Untitled Module', None))
        form = module.new_form("Untitled Form", cls.get_xml('repeat_group_form'))
        form.xmlns = 'repeat-xmlns'
        form.actions.open_cases = [
            AdvancedOpenCaseAction(
                case_type="advanced",
                case_tag="open_case_0",
                name_path="/data/question3/question4",
                repeat_context="/data/question3",
            )
        ]

        cls.apps = [
            cls.current_app,
            cls.first_build,
            cls.advanced_app,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #14
0
    def setUpClass(cls):
        super(TestBuildingSchemaFromApplication, cls).setUpClass()
        cls.current_app = Application.wrap(cls.get_json('basic_application'))

        cls.first_build = Application.wrap(cls.get_json('basic_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3
        cls.first_build.has_submissions = True

        factory = AppFactory(build_version='2.36.0')
        m0, f0 = factory.new_advanced_module('mod0', 'advanced')
        f0.source = cls.get_xml('repeat_group_form').decode('utf-8')
        f0.xmlns = 'repeat-xmlns'

        factory.form_requires_case(f0, 'case0')
        f0.actions.open_cases = [
            AdvancedOpenCaseAction(
                case_type="advanced",
                case_tag="open_case_0",
                name_path="/data/question3/question4",
                repeat_context="/data/question3",
                case_indices=[CaseIndex(tag='load_case0_0')])
        ]
        cls.advanced_app = factory.app
        cls.advanced_app.save()

        cls.apps = [
            cls.current_app,
            cls.first_build,
            cls.advanced_app,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #15
0
    def setUpClass(cls):
        super(TestDelayedSchema, cls).setUpClass()
        cls.current_app = Application.new_app(cls.domain, "Untitled Application")
        cls.current_app._id = '1234'
        cls.current_app.version = 10
        module = cls.current_app.add_module(Module.new_module('Untitled Module', None))
        form = module.new_form("Untitled Form", 'en', attachment=cls.get_xml('basic_form').decode('utf-8'))
        form.xmlns = cls.xmlns

        cls.build = Application.new_app(cls.domain, "Untitled Application")
        cls.build._id = '5678'
        cls.build.copy_of = cls.current_app._id
        cls.build.version = 5
        cls.build.has_submissions = True
        module = cls.build.add_module(Module.new_module('Untitled Module', None))
        form = module.new_form("Untitled Form", 'en',
                               attachment=cls.get_xml('basic_form_version2').decode('utf-8'))
        form.xmlns = cls.xmlns

        cls.apps = [
            cls.current_app,
            cls.build,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #16
0
    def setUpClass(cls):
        super(TestCaseDelayedSchema, cls).setUpClass()
        factory = AppFactory(domain=cls.domain)
        module1, form1 = factory.new_basic_module('update_case', cls.case_type)
        factory.form_requires_case(form1,
                                   cls.case_type,
                                   update={
                                       'age': '/data/age',
                                       'height': '/data/height',
                                   })
        cls.current_app = factory.app
        cls.current_app._id = '1234'

        factory = AppFactory(domain=cls.domain)
        module1, form1 = factory.new_basic_module('update_case', cls.case_type)
        factory.form_requires_case(form1,
                                   cls.case_type,
                                   update={
                                       'age': '/data/age',
                                       'height': '/data/height',
                                       'weight': '/data/weight',
                                   })
        cls.build = factory.app
        cls.build.copy_of = cls.current_app._id
        cls.build.version = 5
        cls.build.has_submissions = True

        cls.apps = [
            cls.current_app,
            cls.build,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #17
0
ファイル: test_pillow.py プロジェクト: xbryanc/commcare-hq
    def test_process_doc_from_couch(self, datetime_mock):
        datetime_mock.utcnow.return_value = self.fake_time_now
        sample_doc, expected_indicators = get_sample_doc_and_indicators(self.fake_time_now)

        # make sure case is in DB
        case = CommCareCase.wrap(sample_doc)
        with drop_connected_signals(case_post_save):
            case.save()
コード例 #18
0
    def setUpClass(cls):
        super(TestFormExportSubcases, cls).setUpClass()
        cls.app = Application.wrap(cls.get_json(cls.app_json_file))
        cls.app.get_forms_by_xmlns(cls.form_xmlns)[0].source = cls.get_xml(cls.form_xml_file)
        with drop_connected_signals(app_post_save):
            cls.app.save()

        cls.form_es_response = cls.get_json(cls.form_es_response_file)
コード例 #19
0
    def setUpClass(cls):
        cls.current_app = Application.wrap(cls.get_json('basic_application'))

        cls.first_build = Application.wrap(cls.get_json('basic_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3

        cls.advanced_app = Application.new_app('domain',
                                               "Untitled Application")
        module = cls.advanced_app.add_module(
            AdvancedModule.new_module('Untitled Module', None))
        form = module.new_form("Untitled Form",
                               cls.get_xml('repeat_group_form'))
        form.xmlns = 'repeat-xmlns'
        form.actions.open_cases = [
            AdvancedOpenCaseAction(
                case_type="advanced",
                case_tag="open_case_0",
                name_path="/data/question3/question4",
                repeat_context="/data/question3",
            )
        ]

        cls.apps = [
            cls.current_app,
            cls.first_build,
            cls.advanced_app,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()

        cls.inferred_schema = InferredSchema(
            domain=cls.domain,
            case_type=cls.case_type,
            group_schemas=[
                InferredExportGroupSchema(
                    path=MAIN_TABLE,
                    items=[
                        ExportItem(path=[
                            PathNode(name='data'),
                            PathNode(name='case_property')
                        ],
                                   label='Inferred 1',
                                   inferred=True),
                        ExportItem(path=[
                            PathNode(name='data'),
                            PathNode(name='case_property_2')
                        ],
                                   label='Inferred 1',
                                   inferred=True),
                    ],
                    inferred=True),
            ])
        cls.inferred_schema.save()
コード例 #20
0
ファイル: test_archive.py プロジェクト: yonglehou/commcare-hq
    def testPublishChanges(self):
        xml_data = self.get_xml('basic')
        response, xform, cases = submit_form_locally(
            xml_data,
            'test-domain',
        )

        with capture_kafka_changes_context(topics.FORM_SQL) as change_context:
            with drop_connected_signals(xform_archived):
                xform.archive()
        self.assertEqual(1, len(change_context.changes))
        self.assertEqual(change_context.changes[0].id, xform.form_id)

        xform = self.formdb.get_form(xform.form_id)
        with capture_kafka_changes_context(topics.FORM_SQL) as change_context:
            with drop_connected_signals(xform_unarchived):
                xform.unarchive()
        self.assertEqual(1, len(change_context.changes))
        self.assertEqual(change_context.changes[0].id, xform.form_id)
コード例 #21
0
 def _make_stock_state(product, section_id, value):
     with drop_connected_signals(post_save):
         return StockState.objects.create(
             stock_on_hand=value,
             case_id='case1',
             product_id=product.product_id,
             sql_product=product,
             section_id=section_id,
             last_modified_date=datetime.datetime.now(),
         )
コード例 #22
0
    def setUpClass(cls):
        cls.current_app = Application.wrap(cls.get_json('parent_child_case_application'))
        cls.current_app.copy_of = None

        cls.apps = [
            cls.current_app,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #23
0
    def testPublishChanges(self):
        xml_data = self.get_xml('basic')
        response, xform, cases = submit_form_locally(
            xml_data,
            'test-domain',
        )

        with capture_kafka_changes_context(topics.FORM_SQL) as change_context:
            with drop_connected_signals(xform_archived):
                xform.archive()
        self.assertEqual(1, len(change_context.changes))
        self.assertEqual(change_context.changes[0].id, xform.form_id)

        xform = self.formdb.get_form(xform.form_id)
        with capture_kafka_changes_context(topics.FORM_SQL) as change_context:
            with drop_connected_signals(xform_unarchived):
                xform.unarchive()
        self.assertEqual(1, len(change_context.changes))
        self.assertEqual(change_context.changes[0].id, xform.form_id)
コード例 #24
0
 def _make_stock_state(product, section_id, value):
     with drop_connected_signals(post_save):
         return StockState.objects.create(
             stock_on_hand=value,
             case_id='case1',
             product_id=product.product_id,
             sql_product=product,
             section_id=section_id,
             last_modified_date=datetime.datetime.now(),
         )
コード例 #25
0
    def setUpClass(cls):
        cls.current_app = Application.wrap(cls.get_json('parent_child_case_application'))
        cls.current_app.copy_of = None

        cls.apps = [
            cls.current_app,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #26
0
 def _new_case(cls, properties):
     id = uuid.uuid4().hex
     case_block = CaseBlock(
         create=True,
         case_id=id,
         case_type=cls.case_type,
         update=properties,
     ).as_xml()
     with drop_connected_signals(case_post_save):
         post_case_blocks([case_block], {'domain': cls.domain})
     return CommCareCase.get(id)
コード例 #27
0
 def _new_case(cls, properties):
     id = uuid.uuid4().hex
     case_block = CaseBlock(
         create=True,
         case_id=id,
         case_type=cls.case_type,
         update=properties,
     ).as_xml()
     with drop_connected_signals(case_post_save):
         post_case_blocks([case_block], {'domain': cls.domain})
     return CommCareCase.get(id)
コード例 #28
0
ファイル: tests.py プロジェクト: dimagi/commcare-hq
    def test_archive_forms_missing(self):
        uploaded_file = WorkbookJSONReader(join(BASE_PATH, MISSING_XLSX))

        with drop_connected_signals(xform_archived):
            response = archive_forms_old(DOMAIN_NAME, "user1", self.username, list(uploaded_file.get_worksheet()))

        for key, _id in self.XFORMS.iteritems():
            self.assertTrue(FormAccessors(DOMAIN_NAME).get_form(_id).is_archived)

        self.assertEqual(len(response["success"]), len(self.xforms))
        self.assertEqual(len(response["errors"]), 1, "One error for trying to archive a missing form")
コード例 #29
0
    def setUpClass(cls):
        super(TestBuildingParentCaseSchemaFromApplication, cls).setUpClass()
        cls.current_app = Application.wrap(cls.get_json('parent_child_case_application'))
        cls.current_app.copy_of = None

        cls.apps = [
            cls.current_app,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #30
0
    def setUp(self):
        self.domain = 'auto-update-test'
        self.case_db = CaseAccessors(self.domain)
        self.factory = CaseFactory(self.domain)
        self.rule = AutomaticUpdateRule(
            domain=self.domain,
            name='test-rule',
            case_type='test-case-type',
            active=True,
            server_modified_boundary=30,
        )
        self.rule.save()
        self.rule.automaticupdaterulecriteria_set = [
            AutomaticUpdateRuleCriteria(
                property_name='last_visit_date',
                property_value='30',
                match_type=AutomaticUpdateRuleCriteria.MATCH_DAYS_SINCE,
            ),
        ]
        self.rule.automaticupdateaction_set = [
            AutomaticUpdateAction(
                action=AutomaticUpdateAction.ACTION_UPDATE,
                property_name='update_flag',
                property_value='Y',
            ),
            AutomaticUpdateAction(action=AutomaticUpdateAction.ACTION_CLOSE, ),
        ]

        self.rule2 = AutomaticUpdateRule(
            domain=self.domain,
            name='test-rule-2',
            case_type='test-case-type-2',
            active=True,
            server_modified_boundary=30,
        )
        self.rule2.save()
        self.rule2.automaticupdateaction_set = [
            AutomaticUpdateAction(action=AutomaticUpdateAction.ACTION_CLOSE, ),
        ]

        self.rule3 = AutomaticUpdateRule(
            domain=self.domain,
            name='test-rule-3',
            case_type='test-case-type-2',
            active=True,
            server_modified_boundary=50,
        )
        self.rule3.save()
        self.rule3.automaticupdateaction_set = [
            AutomaticUpdateAction(action=AutomaticUpdateAction.ACTION_CLOSE, ),
        ]

        with drop_connected_signals(case_post_save):
            case = self.factory.create_case(case_type='test-case-type')
コード例 #31
0
    def setUpClass(cls):
        super(TestBuildingParentCaseSchemaFromApplication, cls).setUpClass()
        cls.current_app = Application.wrap(cls.get_json('parent_child_case_application'))
        cls.current_app.copy_of = None

        cls.apps = [
            cls.current_app,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #32
0
    def setUp(self):
        factory = AppFactory(domain=self.domain)
        self.app = factory.app
        self.app.anonymous_cloudcare_enabled = True

        factory = AppFactory(domain=self.domain)
        self.decoy = factory.app
        self.decoy.anonymous_cloudcare_enabled = False

        with drop_connected_signals(app_post_save):
            self.app.save()
            self.decoy.save()
コード例 #33
0
ファイル: tests.py プロジェクト: tlwakwella/commcare-hq
    def test_archive_forms_basic(self):
        uploaded_file = WorkbookJSONReader(join(BASE_PATH, BASIC_XLSX))

        with drop_connected_signals(xform_archived):
            response = archive_forms_old(DOMAIN_NAME, 'user1', self.username, list(uploaded_file.get_worksheet()))
            print response

        # Need to re-get instance from DB to get updated attributes
        for key, _id in self.XFORMS.iteritems():
            self.assertTrue(FormAccessors(DOMAIN_NAME).get_form(_id).is_archived)

        self.assertEqual(len(response['success']), len(self.xforms))
コード例 #34
0
ファイル: test_reindexer.py プロジェクト: bazuzi/commcare-hq
 def test_case_reindexer(self):
     FormProcessorTestUtils.delete_all_cases()
     case_name = 'reindexer-test-case-{}'.format(uuid.uuid4().hex)
     with drop_connected_signals(case_post_save):
         CommCareCase(domain=self.domain, name=case_name).save()
     call_command('ptop_fast_reindex_cases', noinput=True, bulk=True)
     results = CaseES().run()
     self.assertEqual(1, results.total)
     case_doc = results.hits[0]
     self.assertEqual(self.domain, case_doc['domain'])
     self.assertEqual(case_name, case_doc['name'])
     self.assertEqual('CommCareCase', case_doc['doc_type'])
コード例 #35
0
ファイル: tests.py プロジェクト: taylordowns2000/commcare-hq
    def test_archive_forms_missing(self):
        uploaded_file = WorkbookJSONReader(join(BASE_PATH, MISSING_XLSX))

        with drop_connected_signals(xform_archived):
            response = archive_forms_old(DOMAIN_NAME, 'user1', self.username, list(uploaded_file.get_worksheet()))

        for key, _id in self.XFORMS.iteritems():
            self.assertTrue(FormAccessors(DOMAIN_NAME).get_form(_id).is_archived)

        self.assertEqual(len(response['success']), len(self.xforms))
        self.assertEqual(len(response['errors']), 1,
                         "One error for trying to archive a missing form")
コード例 #36
0
ファイル: tests.py プロジェクト: taylordowns2000/commcare-hq
    def test_archive_forms_basic(self):
        uploaded_file = WorkbookJSONReader(join(BASE_PATH, BASIC_XLSX))

        with drop_connected_signals(xform_archived):
            response = archive_forms_old(DOMAIN_NAME, 'user1', self.username, list(uploaded_file.get_worksheet()))
            print(response)

        # Need to re-get instance from DB to get updated attributes
        for key, _id in self.XFORMS.iteritems():
            self.assertTrue(FormAccessors(DOMAIN_NAME).get_form(_id).is_archived)

        self.assertEqual(len(response['success']), len(self.xforms))
コード例 #37
0
ファイル: utils.py プロジェクト: tlwakwella/commcare-hq
def make_a_case(domain, case_id, case_name):
    # this avoids having to deal with all the reminders code bootstrap
    with drop_connected_signals(case_post_save):
        form, cases = post_case_blocks(
            [
                CaseBlock(
                    create=True,
                    case_id=case_id,
                    case_name=case_name,
                ).as_xml()
            ], domain=domain
        )
    return cases[0]
コード例 #38
0
    def setUpClass(cls):
        cls.current_app = Application.wrap(cls.get_json('basic_case_application'))

        cls.first_build = Application.wrap(cls.get_json('basic_case_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3

        cls.apps = [
            cls.current_app,
            cls.first_build,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #39
0
    def setUpClass(cls):
        cls.current_app = Application.wrap(cls.get_json('basic_case_application'))

        cls.first_build = Application.wrap(cls.get_json('basic_case_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3

        cls.apps = [
            cls.current_app,
            cls.first_build,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #40
0
ファイル: test_pillow.py プロジェクト: kkrampa/commcare-hq
def _save_sql_case(doc):
    system_props = ['_id', '_rev', 'opened_on', 'owner_id', 'doc_type', 'domain', 'type']
    with drop_connected_signals(case_post_save):
        form, cases = post_case_blocks(
            [
                CaseBlock(
                    create=True,
                    case_id=doc['_id'],
                    case_name=doc['name'],
                    case_type=doc['type'],
                    owner_id=doc['owner_id'],
                    date_opened=doc['opened_on'],
                    update={k: str(v) for k, v in doc.items() if k not in system_props}
                ).as_xml()
            ], domain=doc['domain']
        )
    return cases[0]
コード例 #41
0
ファイル: test_pillow.py プロジェクト: kkrampa/commcare-hq
    def _test_process_doc_from_couch(self, datetime_mock, pillow):
        datetime_mock.utcnow.return_value = self.fake_time_now
        sample_doc, expected_indicators = get_sample_doc_and_indicators(self.fake_time_now)

        # make sure case is in DB
        case = CommCareCase.wrap(sample_doc)
        with drop_connected_signals(case_post_save):
            case.save()

        # send to kafka
        since = self.pillow.get_change_feed().get_latest_offsets()
        producer.send_change(topics.CASE, doc_to_change(sample_doc).metadata)

        # run pillow and check changes
        pillow.process_changes(since=since, forever=False)
        self._check_sample_doc_state(expected_indicators)
        case.delete()
コード例 #42
0
    def test_kafka_domain_pillow(self):
        # make a domain
        domain_name = 'domain-pillowtest-kafka'
        with drop_connected_signals(commcare_domain_post_save):
            domain = create_domain(domain_name)

        # send to kafka
        since = get_topic_offset(topics.DOMAIN)
        producer.send_change(topics.DOMAIN, _domain_to_change_meta(domain))

        # send to elasticsearch
        pillow = get_domain_kafka_to_elasticsearch_pillow()
        pillow.process_changes(since=since, forever=False)
        self.elasticsearch.indices.refresh(self.index_info.index)

        # verify there
        self._verify_domain_in_es(domain_name)
コード例 #43
0
    def test_kafka_domain_pillow(self):
        # make a domain
        domain_name = 'domain-pillowtest-kafka'
        with drop_connected_signals(commcare_domain_post_save):
            domain = create_domain(domain_name)

        # send to kafka
        since = get_current_kafka_seq(document_types.DOMAIN)
        producer.send_change(document_types.DOMAIN, _domain_to_change_meta(domain))

        # send to elasticsearch
        pillow = get_domain_kafka_to_elasticsearch_pillow()
        pillow.process_changes(since={document_types.DOMAIN: since}, forever=False)
        self.elasticsearch.indices.refresh(self.index_info.index)

        # verify there
        self._verify_domain_in_es(domain_name)
コード例 #44
0
ファイル: test_pillow.py プロジェクト: xbryanc/commcare-hq
def _save_sql_case(doc):
    system_props = ['_id', '_rev', 'opened_on', 'owner_id', 'doc_type', 'domain', 'type']
    with drop_connected_signals(case_post_save):
        form, cases = post_case_blocks(
            [
                CaseBlock(
                    create=True,
                    case_id=doc['_id'],
                    case_name=doc['name'],
                    case_type=doc['type'],
                    owner_id=doc['owner_id'],
                    date_opened=doc['opened_on'],
                    update={k: str(v) for k, v in doc.items() if k not in system_props}
                ).as_xml()
            ], domain=doc['domain']
        )
    return cases[0]
コード例 #45
0
    def test_build_from_saved_schema(self):
        app = self.current_app

        schema = CaseExportDataSchema.generate_schema_from_builds(
            app.domain,
            app._id,
            self.case_type,
        )

        self.assertEqual(schema.last_app_versions[app._id],
                         self.first_build.version)
        # One for case, one for case history
        self.assertEqual(len(schema.group_schemas), 2)
        self.assertEqual(len(schema.group_schemas[0].items), 2)
        self.assertEqual(len(schema.group_schemas[1].items),
                         len(KNOWN_CASE_PROPERTIES) + 2)

        # After the first schema has been saved let's add a second app to process
        second_build = Application.wrap(
            self.get_json('basic_case_application'))
        second_build._id = '456'
        second_build.copy_of = app.get_id
        second_build.version = 6
        second_build.has_submissions = True
        second_build.get_module(0).get_form(
            0).actions.update_case.update['name'] = ConditionalCaseUpdate(
                question_path='/data/question2')
        with drop_connected_signals(app_post_save):
            second_build.save()
        self.addCleanup(second_build.delete)

        new_schema = CaseExportDataSchema.generate_schema_from_builds(
            app.domain,
            app._id,
            self.case_type,
        )

        self.assertEqual(new_schema._id, schema._id)
        self.assertEqual(new_schema.last_app_versions[app._id],
                         second_build.version)
        # One for case, one for case history
        self.assertEqual(len(new_schema.group_schemas), 2)
        self.assertEqual(len(schema.group_schemas[0].items), 2)
        self.assertEqual(len(schema.group_schemas[1].items),
                         len(KNOWN_CASE_PROPERTIES) + 2)
コード例 #46
0
ファイル: test_utils.py プロジェクト: twymer/commcare-hq
def _create_domain(name, cc_enabled, cc_use_fixtures, cc_case_type, cc_case_owner_id, use_location_as_owner):
    with drop_connected_signals(commcare_domain_post_save):
        domain = Domain(
            _id=uuid.uuid4().hex,
            name=name,
            is_active=True,
            date_created=datetime.utcnow(),
        )
        domain.call_center_config.enabled = cc_enabled
        domain.call_center_config.use_fixtures = cc_use_fixtures
        domain.call_center_config.case_type = cc_case_type
        domain.call_center_config.case_owner_id = cc_case_owner_id
        domain.call_center_config.use_user_location_as_owner = use_location_as_owner

        send_to_elasticsearch(
            'domains',
            doc=domain.to_json(),
        )
コード例 #47
0
def _create_domain(name, cc_enabled, cc_use_fixtures, cc_case_type, cc_case_owner_id, use_location_as_owner):
    with drop_connected_signals(commcare_domain_post_save):
        domain = Domain(
            _id=uuid.uuid4().hex,
            name=name,
            is_active=True,
            date_created=datetime.utcnow(),
        )
        domain.call_center_config.enabled = cc_enabled
        domain.call_center_config.use_fixtures = cc_use_fixtures
        domain.call_center_config.case_type = cc_case_type
        domain.call_center_config.case_owner_id = cc_case_owner_id
        domain.call_center_config.use_user_location_as_owner = use_location_as_owner

        send_to_elasticsearch(
            'domains',
            doc=domain.to_json(),
        )
コード例 #48
0
ファイル: test_utils.py プロジェクト: soitun/commcare-hq
def create_and_save_a_case(domain,
                           case_id,
                           case_name,
                           case_properties=None,
                           case_type=None,
                           drop_signals=True,
                           owner_id=None,
                           user_id=None,
                           index=None):
    """Use corehq.form_processor.tests.utils.create_case() instead if possible

    This submits a form to create the case. The form_procssor version
    creates and saves the case directly, which is faster.
    """
    from corehq.form_processor.signals import sql_case_post_save

    kwargs = {
        'create': True,
        'case_id': case_id,
        'case_name': case_name,
        'update': case_properties,
        'index': index,
    }

    if case_type:
        kwargs['case_type'] = case_type

    if owner_id:
        kwargs['owner_id'] = owner_id

    if user_id:
        kwargs['user_id'] = user_id

    if drop_signals:
        # this avoids having to deal with all the reminders code bootstrap
        with drop_connected_signals(sql_case_post_save):
            form, cases = _create_case(domain, **kwargs)
    else:
        form, cases = _create_case(domain, **kwargs)

    return cases[0]
コード例 #49
0
    def setUpClass(cls):
        cls.current_app = Application.wrap(cls.get_json('basic_application'))

        cls.first_build = Application.wrap(cls.get_json('basic_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3

        cls.apps = [
            cls.current_app,
            cls.first_build,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()

        cls.inferred_schema = InferredSchema(
            domain=cls.domain,
            case_type=cls.case_type,
            group_schemas=[
                InferredExportGroupSchema(
                    path=MAIN_TABLE,
                    items=[
                        ExportItem(path=[
                            PathNode(name='data'),
                            PathNode(name='case_property')
                        ],
                                   label='Inferred 1',
                                   inferred=True),
                        ExportItem(path=[
                            PathNode(name='data'),
                            PathNode(name='case_property_2')
                        ],
                                   label='Inferred 1',
                                   inferred=True),
                    ],
                    inferred=True),
            ])
        cls.inferred_schema.save()
コード例 #50
0
    def setUpClass(cls):
        cls.current_app = Application.wrap(cls.get_json('basic_application'))

        cls.first_build = Application.wrap(cls.get_json('basic_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3

        cls.apps = [
            cls.current_app,
            cls.first_build,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()

        cls.inferred_schema = InferredSchema(
            domain=cls.domain,
            case_type=cls.case_type,
            group_schemas=[
                InferredExportGroupSchema(
                    path=MAIN_TABLE,
                    items=[
                        ExportItem(
                            path=[PathNode(name='data'), PathNode(name='case_property')],
                            label='Inferred 1',
                            inferred=True
                        ),
                        ExportItem(
                            path=[PathNode(name='data'), PathNode(name='case_property_2')],
                            label='Inferred 1',
                            inferred=True
                        ),
                    ],
                    inferred=True
                ),
            ]
        )
        cls.inferred_schema.save()
コード例 #51
0
    def test_build_from_saved_schema(self):
        app = self.current_app

        schema = CaseExportDataSchema.generate_schema_from_builds(
            app.domain,
            app._id,
            self.case_type,
        )

        self.assertEqual(schema.last_app_versions[app._id], self.first_build.version)
        # One for case, one for case history
        self.assertEqual(len(schema.group_schemas), 2)
        self.assertEqual(len(schema.group_schemas[0].items), 2)
        self.assertEqual(len(schema.group_schemas[1].items), 8)

        # After the first schema has been saved let's add a second app to process
        second_build = Application.wrap(self.get_json('basic_case_application'))
        second_build._id = '456'
        second_build.copy_of = app.get_id
        second_build.version = 6
        second_build.has_submissions = True
        second_build.get_module(0).get_form(0).actions.update_case.update['name'] = '/data/question2'
        with drop_connected_signals(app_post_save):
            second_build.save()
        self.addCleanup(second_build.delete)

        new_schema = CaseExportDataSchema.generate_schema_from_builds(
            app.domain,
            app._id,
            self.case_type,
        )

        self.assertEqual(new_schema._id, schema._id)
        self.assertEqual(new_schema.last_app_versions[app._id], second_build.version)
        # One for case, one for case history
        self.assertEqual(len(new_schema.group_schemas), 2)
        self.assertEqual(len(schema.group_schemas[0].items), 2)
        self.assertEqual(len(schema.group_schemas[1].items), 8)
コード例 #52
0
def recalculate_domain_consumption(domain):
    """
    Given a domain, recalculate all saved consumption settings in that domain.
    """
    # note: might get slow as this gets huge
    found_doc_ids = DocDomainMapping.objects.filter(
        domain_name=domain,
        doc_type='CommCareCase',
    ).values_list('doc_id', flat=True)
    products = Product.by_domain(domain)
    for supply_point_id in found_doc_ids:
        for product in products:
            try:
                latest_transaction = StockTransaction.get_ordered_transactions_for_stock(
                    supply_point_id, const.SECTION_TYPE_STOCK, product._id)[0]
            except IndexError:
                pass
            else:
                state = get_stock_state_for_transaction(latest_transaction)
                daily_consumption = get_consumption_for_ledger(state)
                state.daily_consumption = daily_consumption
                with drop_connected_signals(post_save):
                    state.save()
コード例 #53
0
    def test_reverted_domain_pillow_deletion(self):
        domain_name = 'domain-pillow-delete'
        with drop_connected_signals(commcare_domain_post_save):
            domain = create_domain(domain_name)

        # send to kafka
        since = get_topic_offset(topics.DOMAIN)
        publish_domain_saved(domain)

        # send to elasticsearch
        pillow = get_domain_kafka_to_elasticsearch_pillow()
        pillow.process_changes(since=since, forever=False)
        self.elasticsearch.indices.refresh(self.index_info.index)

        # verify there
        self._verify_domain_in_es(domain_name)

        domain_obj = Domain.get_by_name(domain_name)
        domain_obj.doc_type = 'Domain-DUPLICATE'
        domain_obj.save()

        # send to kafka
        since = get_topic_offset(topics.DOMAIN)
        publish_domain_saved(domain_obj)

        # undelete
        domain_obj = Domain.get_by_name(domain_name)
        domain_obj.doc_type = 'Domain'
        domain_obj.save()

        # process pillow changes
        pillow = get_domain_kafka_to_elasticsearch_pillow()
        pillow.process_changes(since=since, forever=False)
        self.elasticsearch.indices.refresh(self.index_info.index)

        # confirm domain still exists
        self._verify_domain_in_es(domain_name)
コード例 #54
0
    def setUpClass(cls):
        super(TestBuildingSchemaFromApplication, cls).setUpClass()
        cls.current_app = Application.wrap(cls.get_json('basic_application'))

        cls.first_build = Application.wrap(cls.get_json('basic_application'))
        cls.first_build._id = '123'
        cls.first_build.copy_of = cls.current_app.get_id
        cls.first_build.version = 3
        cls.first_build.has_submissions = True

        factory = AppFactory(build_version='2.36.0')
        m0, f0 = factory.new_advanced_module('mod0', 'advanced')
        f0.source = cls.get_xml('repeat_group_form').decode('utf-8')
        f0.xmlns = 'repeat-xmlns'

        factory.form_requires_case(f0, 'case0')
        f0.actions.open_cases = [
            AdvancedOpenCaseAction(
                case_type="advanced",
                case_tag="open_case_0",
                name_path="/data/question3/question4",
                repeat_context="/data/question3",
                case_indices=[CaseIndex(tag='load_case0_0')]
            )
        ]
        cls.advanced_app = factory.app
        cls.advanced_app.save()

        cls.apps = [
            cls.current_app,
            cls.first_build,
            cls.advanced_app,
        ]
        with drop_connected_signals(app_post_save):
            for app in cls.apps:
                app.save()
コード例 #55
0
ファイル: consumption.py プロジェクト: dimagi/commcare-hq
def recalculate_domain_consumption(domain):
    """
    Given a domain, recalculate all saved consumption settings in that domain.
    """
    # note: might get slow as this gets huge
    found_doc_ids = DocDomainMapping.objects.filter(
        domain_name=domain,
        doc_type='CommCareCase',
    ).values_list('doc_id', flat=True)
    products = Product.by_domain(domain)
    for supply_point_id in found_doc_ids:
        for product in products:
            try:
                latest_transaction = StockTransaction.get_ordered_transactions_for_stock(
                    supply_point_id, const.SECTION_TYPE_STOCK, product._id
                )[0]
            except IndexError:
                pass
            else:
                state = get_stock_state_for_transaction(latest_transaction)
                daily_consumption = get_consumption_for_ledger(state)
                state.daily_consumption = daily_consumption
                with drop_connected_signals(post_save):
                    state.save()
コード例 #56
0
 def setUpClass(cls):
     cls.current_app = Application.wrap(cls.get_json('basic_application'))
     with drop_connected_signals(app_post_save):
         cls.current_app.save()
コード例 #57
0
    def setUp(self):
        super(AutomaticCaseUpdateTest, self).setUp()
        self.domain = 'auto-update-test'
        update_toggle_cache(AUTO_CASE_UPDATE_ENHANCEMENTS.slug, self.domain, True, NAMESPACE_DOMAIN)
        update_toggle_cache(RUN_AUTO_CASE_UPDATES_ON_SAVE.slug, self.domain, True, NAMESPACE_DOMAIN)
        self.case_db = CaseAccessors(self.domain)
        self.factory = CaseFactory(self.domain)
        self.rule = AutomaticUpdateRule(
            domain=self.domain,
            name='test-rule',
            case_type='test-case-type',
            active=True,
            server_modified_boundary=30,
        )
        self.rule.save()
        AutomaticUpdateRuleCriteria.objects.create(
            property_name='last_visit_date',
            property_value='30',
            match_type=AutomaticUpdateRuleCriteria.MATCH_DAYS_AFTER,
            rule=self.rule,
        )
        AutomaticUpdateAction.objects.create(
            action=AutomaticUpdateAction.ACTION_UPDATE,
            property_name='update_flag',
            property_value='Y',
            rule=self.rule,
        )

        self.rule2 = AutomaticUpdateRule(
            domain=self.domain,
            name='test-rule-2',
            case_type='test-case-type-2',
            active=True,
            server_modified_boundary=30,
        )
        self.rule2.save()
        AutomaticUpdateAction.objects.create(
            action=AutomaticUpdateAction.ACTION_CLOSE,
            rule=self.rule2,
        )

        self.rule3 = AutomaticUpdateRule(
            domain=self.domain,
            name='test-rule-3',
            case_type='test-case-type-2',
            active=True,
            server_modified_boundary=50,
        )
        self.rule3.save()
        AutomaticUpdateAction.objects.create(
            action=AutomaticUpdateAction.ACTION_CLOSE,
            rule=self.rule3,
        )

        self.rule4 = AutomaticUpdateRule(
            domain=self.domain,
            name='test-rule-4',
            case_type='test-case-type',
            active=True,
            server_modified_boundary=30,
        )
        self.rule4.save()
        AutomaticUpdateRuleCriteria.objects.create(
            property_name='last_visit_date',
            property_value='40',
            match_type=AutomaticUpdateRuleCriteria.MATCH_DAYS_AFTER,
            rule=self.rule4,
        )
        AutomaticUpdateAction.objects.create(
            action=AutomaticUpdateAction.ACTION_UPDATE,
            property_name='update_flag',
            property_value='C',
            rule=self.rule4,
        )
        AutomaticUpdateAction.objects.create(
            action=AutomaticUpdateAction.ACTION_CLOSE,
            rule=self.rule4,
        )
        self.rule5 = AutomaticUpdateRule(
            domain=self.domain,
            name='test-rule-5',
            case_type='test-case-type-3',
            active=True,
            filter_on_server_modified=False
        )
        self.rule5.save()
        AutomaticUpdateRuleCriteria.objects.create(
            property_name='name',
            property_value='signal',
            match_type=AutomaticUpdateRuleCriteria.MATCH_EQUAL,
            rule=self.rule5,
        )
        AutomaticUpdateAction.objects.create(
            action=AutomaticUpdateAction.ACTION_UPDATE,
            property_name='after_save',
            property_value='updated',
            rule=self.rule5,
        )

        with drop_connected_signals(case_post_save):
            case = self.factory.create_case(case_type='test-case-type')
        self.case_id = case.case_id
コード例 #58
0
 def setUpClass(cls):
     super(TestExportDataSchemaVersionControl, cls).setUpClass()
     cls.current_app = Application.wrap(cls.get_json('basic_application'))
     with drop_connected_signals(app_post_save):
         cls.current_app.save()
コード例 #59
0
    def setUp(self):
        self.domain = 'auto-update-test'
        self.case_db = CaseAccessors(self.domain)
        self.factory = CaseFactory(self.domain)
        self.rule = AutomaticUpdateRule(
            domain=self.domain,
            name='test-rule',
            case_type='test-case-type',
            active=True,
            server_modified_boundary=30,
        )
        self.rule.save()
        self.rule.automaticupdaterulecriteria_set = [
            AutomaticUpdateRuleCriteria(
                property_name='last_visit_date',
                property_value='30',
                match_type=AutomaticUpdateRuleCriteria.MATCH_DAYS_SINCE,
            ),
        ]
        self.rule.automaticupdateaction_set = [
            AutomaticUpdateAction(
                action=AutomaticUpdateAction.ACTION_UPDATE,
                property_name='update_flag',
                property_value='Y',
            ),
            AutomaticUpdateAction(
                action=AutomaticUpdateAction.ACTION_CLOSE,
            ),
        ]

        self.rule2 = AutomaticUpdateRule(
            domain=self.domain,
            name='test-rule-2',
            case_type='test-case-type-2',
            active=True,
            server_modified_boundary=30,
        )
        self.rule2.save()
        self.rule2.automaticupdateaction_set = [
            AutomaticUpdateAction(
                action=AutomaticUpdateAction.ACTION_CLOSE,
            ),
        ]

        self.rule3 = AutomaticUpdateRule(
            domain=self.domain,
            name='test-rule-3',
            case_type='test-case-type-2',
            active=True,
            server_modified_boundary=50,
        )
        self.rule3.save()
        self.rule3.automaticupdateaction_set = [
            AutomaticUpdateAction(
                action=AutomaticUpdateAction.ACTION_CLOSE,
            ),
        ]

        with drop_connected_signals(case_post_save):
            case = self.factory.create_case(case_type='test-case-type')
        self.case_id = case.case_id