Beispiel #1
0
    def setUp(self):
        super(SyncPerformanceTest, self).setUp()
        # the other user is an "owner" of the original users cases as well,
        # for convenience
        self.project = Domain(name='sync-performance-tests')
        self.project.save()
        self.factory.domain = self.project.name
        self.other_user = create_restore_user(
            domain=self.project.name,
            username=OTHER_USERNAME,
        )

        self.referral_user = create_restore_user(
            domain=self.project.name,
            username=REFERRAL_USERNAME,
        )

        self.shared_group = Group(
            domain=self.project.name,
            name='shared_group',
            case_sharing=True,
            users=[self.other_user.user_id, self.user.user_id]
        )
        self.shared_group.save()

        self.referral_group = Group(
            domain=self.project.name,
            name='referral_group',
            case_sharing=True,
            users=[self.referral_user.user_id]
        )
        self.referral_group.save()

        # this creates the initial blank sync token in the database
        self.other_sync_log = synclog_from_restore_payload(generate_restore_payload(
            self.project, self.other_user
        ))
        self.referral_sync_log = synclog_from_restore_payload(generate_restore_payload(
            self.project, self.referral_user
        ))

        self.assertTrue(self.shared_group._id in self.other_sync_log.owner_ids_on_phone)
        self.assertTrue(self.other_user.user_id in self.other_sync_log.owner_ids_on_phone)

        self.sync_log = synclog_from_restore_payload(generate_restore_payload(
            self.project, self.user
        ))
        self.assertTrue(self.shared_group._id in self.sync_log.owner_ids_on_phone)
        self.assertTrue(self.user.user_id in self.sync_log.owner_ids_on_phone)
    def setUpClass(cls):
        super(AppAwareSyncTests, cls).setUpClass()
        delete_all_users()
        cls.domain_obj = create_domain(cls.domain)
        toggles.MOBILE_UCR.set(cls.domain, True, toggles.NAMESPACE_DOMAIN)
        cls.user = create_restore_user(cls.domain)

        cls.app1 = Application.new_app(cls.domain, 'Test App 1')
        cls.report_config1 = get_sample_report_config()
        cls.report_config1.domain = cls.domain
        cls.report_config1.save()
        report_app_config = {
            'report_id': cls.report_config1.get_id,
            'uuid': '123456'
        }
        module = cls.app1.add_module(ReportModule.new_module('Reports', None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app1.save()

        cls.app2 = Application.new_app(cls.domain, 'Test App 2')
        cls.report_config2 = get_sample_report_config()
        cls.report_config2.domain = cls.domain
        cls.report_config2.save()
        report_app_config = {
            'report_id': cls.report_config2.get_id,
            'uuid': 'abcdef'
        }
        module = cls.app2.add_module(ReportModule.new_module('Reports', None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app2.save()

        cls.app3 = Application.new_app(cls.domain, 'Test App 3')
        cls.app3.save()
 def setUpClass(cls):
     super(RelatedLocationFixturesTest, cls).setUpClass()
     cls.user = create_restore_user(cls.domain, 'user', '123')
     cls.relation = LocationRelation.objects.create(
         location_a=cls.locations["Cambridge"],
         location_b=cls.locations["Boston"]
     )
    def setUpClass(cls):
        delete_all_users()
        create_domain(cls.domain)
        toggles.MOBILE_UCR.set(cls.domain, True, toggles.NAMESPACE_DOMAIN)
        cls.user = create_restore_user(cls.domain)

        cls.app1 = Application.new_app(cls.domain, "Test App 1")
        cls.report_config1 = get_sample_report_config()
        cls.report_config1.domain = cls.domain
        cls.report_config1.save()
        report_app_config = {"report_id": cls.report_config1.get_id, "uuid": "123456"}
        module = cls.app1.add_module(ReportModule.new_module("Reports", None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app1.save()

        cls.app2 = Application.new_app(cls.domain, "Test App 2")
        cls.report_config2 = get_sample_report_config()
        cls.report_config2.domain = cls.domain
        cls.report_config2.save()
        report_app_config = {"report_id": cls.report_config2.get_id, "uuid": "abcdef"}
        module = cls.app2.add_module(ReportModule.new_module("Reports", None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app2.save()

        cls.app3 = Application.new_app(cls.domain, "Test App 3")
        cls.app3.save()
 def setUpClass(cls):
     super(BaseAsyncRestoreTest, cls).setUpClass()
     delete_all_cases()
     delete_all_sync_logs()
     delete_all_users()
     cls.domain = 'dummy-project'
     cls.project = Domain(name=cls.domain)
     cls.project.save()
     cls.user = create_restore_user(domain=cls.domain)
Beispiel #6
0
 def setUpClass(cls):
     super(TestNewSyncSpecifics, cls).setUpClass()
     cls.domain = uuid.uuid4().hex
     cls.project = Domain(name=cls.domain)
     cls.user = create_restore_user(
         cls.domain,
         username=uuid.uuid4().hex,
     )
     cls.user_id = cls.user.user_id
    def setUpClass(cls):
        super(ReportFiltersSuiteTest, cls).setUpClass()
        delete_all_users()
        cls.report_id = '7b97e8b53d00d43ca126b10093215a9d'
        cls.report_config_uuid = 'a98c812873986df34fd1b4ceb45e6164ae9cc664'
        cls.domain = 'report-filter-test-domain'
        cls.user = create_restore_user(
            domain=cls.domain,
            username='******',
        )
        MOBILE_UCR.set(cls.domain, True, NAMESPACE_DOMAIN)

        report_configuration = cls.make_report_config(cls.domain, cls.report_id)
        cls.report_configs_by_id = {
            cls.report_id: report_configuration
        }
        cls.app = Application.new_app(cls.domain, "Report Filter Test App")
        module = cls.app.add_module(ReportModule.new_module("Report Module", 'en'))
        module.report_configs.append(
            ReportAppConfig(
                report_id=cls.report_id,
                header={},
                description="",
                complete_graph_configs={
                    '7451243209119342931': GraphConfiguration(
                        graph_type="bar",
                        series=[GraphSeries(
                            config={},
                            locale_specific_config={},
                            data_path="",
                            x_function="",
                            y_function="",
                        )],
                    )
                },
                filters=OrderedDict([
                    ('fav_fruit_abc123_1', MobileSelectFilter()),
                    ('computed_owner_name_40cc88a0_1', MobileSelectFilter()),
                ]),
                uuid=cls.report_config_uuid,
            )
        )
        with mock_report_configurations(cls.report_configs_by_id):
            cls.suite = cls.app.create_suite()
        cls.data = [
            {'color_94ec39e6': 'red', 'count': 2, 'computed_owner_name_40cc88a0': 'cory', 'fav_fruit_abc123': 'c'},
            {'color_94ec39e6': 'black', 'count': 1, 'computed_owner_name_40cc88a0': 'ctsims', 'fav_fruit_abc123': 'b'},
            {'color_94ec39e6': 'red', 'count': 3, 'computed_owner_name_40cc88a0': 'daniel', 'fav_fruit_abc123': 'b'},
        ]
        with mock_report_data(cls.data):
            with mock_report_configuration_get(cls.report_configs_by_id):
                with mock.patch('corehq.apps.app_manager.fixtures.mobile_ucr.get_apps_in_domain',
                                lambda domain, include_remote: [cls.app]):
                    with mock_datasource_config():
                        fixture, = call_fixture_generator(report_fixture_generator, cls.user)
        cls.fixture = ElementTree.tostring(fixture)
    def setUp(self):
        super(ForkedHierarchiesTest, self).setUp()
        self.domain = 'test'
        self.domain_obj = bootstrap_domain(self.domain)
        self.addCleanup(self.domain_obj.delete)

        self.user = create_restore_user(self.domain, 'user', '123')

        location_type_structure = [
            LocationTypeStructure('ctd', [
                LocationTypeStructure('sto', [
                    LocationTypeStructure('cto', [
                        LocationTypeStructure('dto', [
                            LocationTypeStructure('tu', [
                                LocationTypeStructure('phi', []),
                                LocationTypeStructure('dmc', []),
                            ]),
                        ])
                    ]),
                    LocationTypeStructure('drtb', []),
                    LocationTypeStructure('cdst', []),
                ])
            ])
        ]
        location_structure = [
            LocationStructure('CTD', 'ctd', [
                LocationStructure('STO', 'sto', [
                    LocationStructure('CTO', 'cto', [
                        LocationStructure('DTO', 'dto', [
                            LocationStructure('TU', 'tu', [
                                LocationStructure('PHI', 'phi', []),
                                LocationStructure('DMC', 'dmc', []),
                            ]),
                        ])
                    ]),
                    LocationStructure('DRTB', 'drtb', []),
                    LocationStructure('CDST', 'cdst', []),
                ]),
                LocationStructure('STO1', 'sto', [
                    LocationStructure('CTO1', 'cto', [
                        LocationStructure('DTO1', 'dto', [
                            LocationStructure('TU1', 'tu', [
                                LocationStructure('PHI1', 'phi', []),
                                LocationStructure('DMC1', 'dmc', []),
                            ]),
                        ])
                    ]),
                    LocationStructure('DRTB1', 'drtb', []),
                    LocationStructure('CDST1', 'cdst', []),
                ])
            ])
        ]

        location_metadata = {'is_test': 'no', 'nikshay_code': 'nikshay_code'}
        setup_location_types_with_structure(self.domain, location_type_structure),
        self.locations = setup_locations_with_structure(self.domain, location_structure, location_metadata)
 def setUp(self):
     FormProcessorTestUtils.delete_all_cases()
     FormProcessorTestUtils.delete_all_xforms()
     delete_all_users()
     self.domain = "domain"
     self.project = Domain(name=self.domain)
     self.user = create_restore_user(self.domain, username='******', password="******")
     self.factory = CaseFactory(domain=self.domain)
     self.extension_ids = ['1', '2', '3']
     self.host_id = 'host'
 def setUpClass(cls):
     super(LocationFixturesDataTest, cls).setUpClass()
     cls.user = create_restore_user(cls.domain, 'user', '123')
     cls.loc_fields = CustomDataFieldsDefinition.get_or_create(cls.domain, LocationFieldsView.field_type)
     cls.loc_fields.fields = [
         CustomDataField(slug='baseball_team'),
         CustomDataField(slug='favorite_passtime'),
     ]
     cls.loc_fields.save()
     cls.field_slugs = [f.slug for f in cls.loc_fields.fields]
 def setUpClass(cls):
     super(AutoCloseExtensionsTest, cls).setUpClass()
     delete_all_users()
     cls.domain = "domain"
     cls.project = Domain(name=cls.domain)
     cls.user = create_restore_user(cls.domain, username='******', password="******")
     cls.factory = CaseFactory(domain=cls.domain)
     cls.extension_ids = ['1', '2', '3']
     cls.host_id = 'host-{}'.format(uuid.uuid4().hex)
     cls.parent_id = 'parent-{}'.format(uuid.uuid4().hex)
Beispiel #12
0
    def test_program_fixture(self):
        user = create_restore_user(self.domain.name)
        Program(domain=user.domain, name="test1", code="t1").save()

        program_list = Program.by_domain(user.domain)
        program_xml = self.generate_program_xml(program_list, user)

        fixture = program_fixture_generator(user, V1)

        self.assertXmlEqual(program_xml, ElementTree.tostring(fixture[0]))
Beispiel #13
0
    def setUp(self):
        delete_all_cases()
        delete_all_xforms()
        delete_all_sync_logs()
        delete_all_users()
        self.project = Domain(name='state-hash-tests-project')
        self.project.save()
        self.user = create_restore_user(domain=self.project.name)

        # this creates the initial blank sync token in the database
        generate_restore_payload(self.project, self.user)
        self.sync_log = get_exactly_one_wrapped_sync_log()
    def testUserRestoreWithCase(self):
        restore_user = create_restore_user(domain=self.domain)
        expected_case_block = CaseBlock(
            create=True,
            case_id='my-case-id',
            user_id=restore_user.user_id,
            owner_id=restore_user.user_id,
            case_type='test-case-type',
            update={'external_id': 'someexternal'},
        )
        _, [case] = post_case_blocks([expected_case_block.as_xml()], {'domain': self.domain})

        assert_user_has_case(self, restore_user, case.case_id)
 def testUserRestoreWithCase(self):
     restore_user = create_restore_user(domain=self.domain)
     case_id = 'my-case-id'
     device = MockDevice(self.project, restore_user)
     device.change_cases(CaseBlock(
         create=True,
         case_id=case_id,
         user_id=restore_user.user_id,
         owner_id=restore_user.user_id,
         case_type='test-case-type',
         update={'external_id': 'someexternal'},
     ))
     self.assertIn(case_id, device.sync().cases)
 def testUserRestoreWithCase(self):
     restore_user = create_restore_user(domain=self.domain)
     case_id = 'my-case-id'
     device = MockDevice(self.project, restore_user)
     device.change_cases(CaseBlock(
         create=True,
         case_id=case_id,
         user_id=restore_user.user_id,
         owner_id=restore_user.user_id,
         case_type='test-case-type',
         update={'external_id': 'someexternal'},
     ))
     self.assertIn(case_id, device.sync().cases)
    def testUserRestoreWithCase(self):
        restore_user = create_restore_user(domain=self.domain)
        expected_case_block = CaseBlock(
            create=True,
            case_id='my-case-id',
            user_id=restore_user.user_id,
            owner_id=restore_user.user_id,
            case_type='test-case-type',
            update={'external_id': 'someexternal'},
        )
        _, [case] = post_case_blocks([expected_case_block.as_xml()],
                                     {'domain': self.domain})

        assert_user_has_case(self, restore_user, case.case_id)
 def setUpClass(cls):
     super(TestIndexedLocationsFixture, cls).setUpClass()
     cls.user = create_restore_user(cls.domain, 'user', '123')
     cls.loc_fields = CustomDataFieldsDefinition.get_or_create(cls.domain, LocationFieldsView.field_type)
     cls.loc_fields.fields = [
         CustomDataField(slug='is_test', index_in_fixture=True),
         CustomDataField(slug='favorite_color'),
     ]
     cls.loc_fields.save()
     cls.field_slugs = [f.slug for f in cls.loc_fields.fields]
     for location in cls.locations.values():
         location.metadata = {
             'is_test': 'no',
             'favorite_color': 'blue',
         }
         location.save()
Beispiel #19
0
 def setUpClass(cls):
     super(TestIndexedLocationsFixture, cls).setUpClass()
     cls.user = create_restore_user(cls.domain, 'user', '123')
     cls.loc_fields = CustomDataFieldsDefinition.get_or_create(cls.domain, LocationFieldsView.field_type)
     cls.loc_fields.fields = [
         CustomDataField(slug='is_test', index_in_fixture=True),
         CustomDataField(slug='favorite_color'),
     ]
     cls.loc_fields.save()
     cls.field_slugs = [f.slug for f in cls.loc_fields.fields]
     for location in cls.locations.values():
         location.metadata = {
             'is_test': 'no',
             'favorite_color': 'blue',
         }
         location.save()
Beispiel #20
0
    def setUpClass(cls):
        delete_all_users()
        cls.report_id = '7b97e8b53d00d43ca126b10093215a9d'
        cls.report_config_uuid = 'a98c812873986df34fd1b4ceb45e6164ae9cc664'
        cls.domain = 'report-filter-test-domain'
        cls.user = create_restore_user(
            domain=cls.domain,
            username='******',
        )
        update_toggle_cache(MOBILE_UCR.slug, cls.domain, True, NAMESPACE_DOMAIN)

        report_configuration = cls.make_report_config(cls.domain, cls.report_id)
        cls.report_configs_by_id = {
            cls.report_id: report_configuration
        }
        cls.app = Application.new_app(cls.domain, "Report Filter Test App")
        module = cls.app.add_module(ReportModule.new_module("Report Module", 'en'))
        module.report_configs.append(
            ReportAppConfig(
                report_id=cls.report_id,
                header={},
                description="",
                graph_configs={
                    '7451243209119342931': ReportGraphConfig(
                        series_configs={'count': {}}
                    )
                },
                filters={'computed_owner_name_40cc88a0_1': MobileSelectFilter()},
                uuid=cls.report_config_uuid,
            )
        )
        with mock_report_configurations(cls.report_configs_by_id):
            cls.suite = cls.app.create_suite()
        cls.data = [
            {'color_94ec39e6': 'red', 'count': 2, 'computed_owner_name_40cc88a0': 'cory'},
            {'color_94ec39e6': 'black', 'count': 1, 'computed_owner_name_40cc88a0': 'ctsims'},
            {'color_94ec39e6': 'red', 'count': 3, 'computed_owner_name_40cc88a0': 'daniel'},
        ]
        with mock_report_data(cls.data):
            with mock_report_configuration_get(cls.report_configs_by_id):
                with mock.patch('corehq.apps.app_manager.fixtures.mobile_ucr.get_apps_in_domain',
                                lambda domain, include_remote: [cls.app]):
                    with mock_sql_backend():
                        with mock_datasource_config():
                            fixture, = report_fixture_generator(cls.user, '2.0')
        cls.fixture = ElementTree.tostring(fixture)
Beispiel #21
0
    def test_program_fixture(self):
        user = self.user
        Program(domain=user.domain, name="test1", code="t1").save()

        program_list = Program.by_domain(user.domain)
        program_xml = self.generate_program_xml(program_list, user)

        fixture = call_fixture_generator(program_fixture_generator, user)

        self.assertXmlEqual(program_xml, fixture[0])

        # test restore with different user
        user2 = create_restore_user(self.domain, username='******')
        self.addCleanup(user2._couch_user.delete)
        program_xml = self.generate_program_xml(program_list, user2)
        fixture = call_fixture_generator(program_fixture_generator, user2)

        self.assertXmlEqual(program_xml, fixture[0])
Beispiel #22
0
    def test_selective_program_sync(self):
        user = create_restore_user(self.domain.name)
        Program(domain=user.domain, name="test1", code="t1").save()

        program_list = Program.by_domain(user.domain)
        program_xml = self.generate_program_xml(program_list, user)

        fixture_original = program_fixture_generator(user, V1)

        generate_restore_payload(self.domain, user)
        self.assertXmlEqual(program_xml, ElementTree.tostring(fixture_original[0]))

        first_sync = sorted(
            SyncLog.view("phone/sync_logs_by_user", include_docs=True, reduce=False).all(), key=lambda x: x.date
        )[-1]

        # make sure the time stamp on this first sync is
        # not on the same second that the programs were created
        first_sync.date += datetime.timedelta(seconds=1)

        # second sync is before any changes are made, so there should
        # be no programs synced
        fixture_pre_change = program_fixture_generator(user, V1, last_sync=first_sync)
        generate_restore_payload(self.domain, user)
        self.assertEqual([], fixture_pre_change, "Fixture was not empty on second sync")

        second_sync = sorted(
            SyncLog.view("phone/sync_logs_by_user", include_docs=True, reduce=False).all(), key=lambda x: x.date
        )[-1]

        self.assertTrue(first_sync._id != second_sync._id)

        # save should make the program more recently updated than the
        # last sync
        for program in program_list:
            program.save()

        # now that we've updated a program, we should get
        # program data in sync again
        fixture_post_change = program_fixture_generator(user, V1, last_sync=second_sync)

        # regenerate the fixture xml to make sure it is still legit
        self.assertXmlEqual(program_xml, ElementTree.tostring(fixture_post_change[0]))
Beispiel #23
0
    def test_date_opened_coercion(self):
        delete_all_users()
        self.project = Domain(name='some-domain')
        self.project.save()
        user = create_restore_user(self.project.name)
        case_id = uuid.uuid4().hex
        modified_on = datetime.utcnow()
        case = CaseBlock(
            create=True,
            case_id=case_id,
            user_id=user.user_id, owner_id=user.user_id, case_type='demo',
            case_name='create_case', date_modified=modified_on, date_opened=modified_on, update={
                'dynamic': '123'
            }
        )

        post_case_blocks([case.as_xml()], domain='some-domain')
        # update the date_opened to date type to check for value on restore
        case.date_opened = case.date_opened.date()
        deprecated_check_user_has_case(self, user, case.as_xml())
Beispiel #24
0
    def test_date_opened_coercion(self):
        delete_all_users()
        self.project = Domain(name='some-domain')
        self.project.save()
        user = create_restore_user(self.project.name)
        case_id = uuid.uuid4().hex
        modified_on = datetime.utcnow()
        case = CaseBlock(
            create=True,
            case_id=case_id,
            user_id=user.user_id, owner_id=user.user_id, case_type='demo',
            case_name='create_case', date_modified=modified_on, date_opened=modified_on, update={
                'dynamic': '123'
            }
        )

        post_case_blocks([case.as_xml()], domain='some-domain')
        # update the date_opened to date type to check for value on restore
        case.date_opened = case.date_opened.date()
        check_user_has_case(self, user, case.as_xml())
Beispiel #25
0
    def test_name_and_number(self):
        user = create_restore_user(
            first_name='mclovin',
            last_name=None,
            phone_number='555555',
        )
        payload = get_registration_xml(user)

        def assertRegistrationData(key, val):
            if val is None:
                template = '<data key="{prefix}_{key}" />'
            else:
                template = '<data key="{prefix}_{key}">{val}</data>'
            self.assertIn(
                template.format(prefix=SYSTEM_PREFIX, key=key, val=val),
                payload,
            )

        assertRegistrationData("first_name", "mclovin")
        assertRegistrationData("last_name", None)
        assertRegistrationData("phone_number", "555555")
    def test_name_and_number(self):
        user = create_restore_user(
            first_name='mclovin',
            last_name=None,
            phone_number='555555',
        )
        payload = xml.get_registration_xml(user)

        def assertRegistrationData(key, val):
            if val is None:
                template = '<data key="{prefix}_{key}" />'
            else:
                template = '<data key="{prefix}_{key}">{val}</data>'
            self.assertIn(
                template.format(prefix=SYSTEM_PREFIX, key=key, val=val),
                payload,
            )

        assertRegistrationData("first_name", "mclovin")
        assertRegistrationData("last_name", None)
        assertRegistrationData("phone_number", "555555")
Beispiel #27
0
    def setUpClass(cls):
        delete_all_users()
        create_domain(cls.domain)
        toggles.MOBILE_UCR.set(cls.domain, True, toggles.NAMESPACE_DOMAIN)
        cls.user = create_restore_user(cls.domain)

        cls.app1 = Application.new_app(cls.domain,
                                       'Test App 1',
                                       application_version=APP_V2)
        cls.report_config1 = get_sample_report_config()
        cls.report_config1.domain = cls.domain
        cls.report_config1.save()
        report_app_config = {
            'report_id': cls.report_config1.get_id,
            'uuid': '123456'
        }
        module = cls.app1.add_module(ReportModule.new_module('Reports', None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app1.save()

        cls.app2 = Application.new_app(cls.domain,
                                       'Test App 2',
                                       application_version=APP_V2)
        cls.report_config2 = get_sample_report_config()
        cls.report_config2.domain = cls.domain
        cls.report_config2.save()
        report_app_config = {
            'report_id': cls.report_config2.get_id,
            'uuid': 'abcdef'
        }
        module = cls.app2.add_module(ReportModule.new_module('Reports', None))
        module.report_configs = [ReportAppConfig.wrap(report_app_config)]
        cls.app2.save()

        cls.app3 = Application.new_app(cls.domain,
                                       'Test App 3',
                                       application_version=APP_V2)
        cls.app3.save()
Beispiel #28
0
 def setUpClass(cls):
     super(IndexTest, cls).setUpClass()
     delete_all_users()
     cls.project = Domain(name='index-test')
     cls.project.save()
     cls.user = create_restore_user(domain=cls.project.name)
Beispiel #29
0
 def setUpClass(cls):
     super(StateHashTest, cls).setUpClass()
     delete_all_users()
     cls.project = Domain(name='state-hash-tests-project')
     cls.project.save()
     cls.user = create_restore_user(domain=cls.project.name)
Beispiel #30
0
    def test_product_fixture(self):
        user = create_restore_user(self.domain.name)
        xml = self.generate_product_fixture_xml(user)
        fixture = product_fixture_generator(user, V1)

        self.assertXmlEqual(xml, ElementTree.tostring(fixture[0]))
Beispiel #31
0
 def setUpClass(cls):
     cls.domain = Domain.get_or_create_with_name(DOMAIN, is_active=True)
     cls.restore_user = create_restore_user(domain=DOMAIN, is_mobile_user=False)
 def setUp(self):
     self.domain_obj = bootstrap_domain(self.domain)
     self.user = create_restore_user(self.domain, 'user', '123')
     self.location_types = setup_location_types_with_structure(self.domain, self.location_type_structure)
     self.locations = setup_locations_with_structure(self.domain, self.location_structure)
Beispiel #33
0
 def setUp(self):
     super(IndexTest, self).setUp()
     delete_all_users()
     self.project = Domain(name='index-test')
     self.project.save()
     self.user = create_restore_user(domain=self.project.name)
Beispiel #34
0
 def setUpClass(cls):
     super(FixtureTest, cls).setUpClass()
     cls.domain_obj = util.bootstrap_domain(cls.domain)
     util.bootstrap_location_types(cls.domain)
     util.bootstrap_products(cls.domain)
     cls.user = create_restore_user(cls.domain)
Beispiel #35
0
 def setUp(self):
     self.domain_obj = bootstrap_domain(self.domain)
     self.user = create_restore_user(self.domain, 'user', '123')
     self.location_types = setup_location_types_with_structure(self.domain, self.location_type_structure)
     self.locations = setup_locations_with_structure(self.domain, self.location_structure)
 def test_registration_xml(self):
     user = create_restore_user()
     check_xml_line_by_line(self, dummy_user_xml(user),
                            xml.get_registration_xml(user))
 def test_username_doesnt_have_domain(self):
     user = create_restore_user(
         username=normalize_username('withdomain', domain='thedomain'))
     restore_payload = xml.get_registration_xml(user)
     self.assertTrue('thedomain' not in restore_payload)
 def setUp(self):
     super(WebUserOtaRestoreTest, self).setUp()
     delete_all_users()
     self.restore_user = create_restore_user(self.project.name,
                                             is_mobile_user=False)
Beispiel #39
0
 def setUp(self):
     super(WebUserLocationFixturesTest, self).setUp()
     delete_all_users()
     self.user = create_restore_user(self.domain, 'web_user', '123', is_mobile_user=False)
Beispiel #40
0
 def setUpClass(cls):
     super(RelatedLocationFixturesTest, cls).setUpClass()
     cls.user = create_restore_user(cls.domain, 'user', '123')
     cls.relation = LocationRelation.objects.create(
         location_a=cls.locations["Cambridge"],
         location_b=cls.locations["Boston"])
Beispiel #41
0
 def setUpClass(cls):
     cls.project = Domain(name=cls.domain)
     cls.project.save()
     cls.restore_user = create_restore_user(cls.domain,
                                            username=uuid.uuid4().hex)
 def setUp(self):
     super(BaseOtaRestoreTest, self).setUp()
     delete_all_users()
     self.restore_user = create_restore_user(self.project.name)
Beispiel #43
0
 def setUpClass(cls):
     super(TestSyncPurge, cls).setUpClass()
     cls.domain = uuid.uuid4().hex
     cls.project = Domain(name=cls.domain)
     cls.project.save()
     cls.restore_user = create_restore_user(domain=cls.domain)
    def setUpClass(cls):
        super(ReportFiltersSuiteTest, cls).setUpClass()
        delete_all_users()
        cls.report_id = '7b97e8b53d00d43ca126b10093215a9d'
        cls.report_config_mobile_id = 'a98c812873986df34fd1b4ceb45e6164ae9cc664'
        cls.domain = 'report-filter-test-domain'
        create_domain(cls.domain)
        cls.user = create_restore_user(
            domain=cls.domain,
            username='******',
        )
        MOBILE_UCR.set(cls.domain, True, NAMESPACE_DOMAIN)
        ADD_ROW_INDEX_TO_MOBILE_UCRS.set(cls.domain, True, NAMESPACE_DOMAIN)

        report_configuration = cls.make_report_config(cls.domain, cls.report_id)

        # also make a report with a hidden column
        cls.hidden_column_report_id = 'bd2a43018ad9463682165c1bc16347ac'
        cls.hidden_column_mobile_id = '45152061d8dc4d2a8d987a0568abe1ae'
        report_configuration_with_hidden_column = MAKE_REPORT_CONFIG(
            cls.domain,
            cls.hidden_column_report_id,
            columns=[
                FieldColumn(
                    type='field',
                    aggregation="simple",
                    column_id="color_94ec39e6",
                    display="color",
                    field="color_94ec39e6"
                ).to_json(),
                FieldColumn(
                    type='field',
                    aggregation="simple",
                    column_id="hidden_color_94ec39e6",
                    display="color",
                    field="color_94ec39e6",
                    visible=False,
                ).to_json(),
            ]
        )
        cls.report_configs_by_id = {
            cls.report_id: report_configuration,
            cls.hidden_column_report_id: report_configuration_with_hidden_column
        }
        cls.app = Application.new_app(cls.domain, "Report Filter Test App")
        report_module = cls.app.add_module(ReportModule.new_module("Report Module", 'en'))
        report_module.report_context_tile = True
        report_module.report_configs.append(
            ReportAppConfig(
                report_id=cls.report_id,
                header={},
                description="",
                complete_graph_configs={
                    '7451243209119342931': GraphConfiguration(
                        graph_type="bar",
                        series=[GraphSeries(
                            config={},
                            locale_specific_config={},
                            data_path="",
                            x_function="",
                            y_function="",
                        )],
                    )
                },
                filters=OrderedDict([
                    ('fav_fruit_abc123_1', MobileSelectFilter()),
                    ('computed_owner_name_40cc88a0_1', MobileSelectFilter()),
                ]),
                uuid=cls.report_config_mobile_id,
            )
        )
        report_module.report_configs.append(
            ReportAppConfig(
                report_id=cls.hidden_column_report_id,
                header={},
                description="",
                complete_graph_configs={},
                filters={},
                uuid=cls.hidden_column_mobile_id,
            )
        )

        case_module = cls.app.add_module(Module.new_module("Case Module", 'en'))
        case_module.case_type = "fish"
        case_module.report_context_tile = True
        case_form = case_module.new_form("Update Fish", None)
        case_form.requires = "case"
        case_form.xmlns = "http://openrosa.org/formdesigner/2423EFB5-2E8C-4B8F-9DA0-23FFFD4391AF"

        survey_module = cls.app.add_module(Module.new_module("Survey Module", 'en'))
        survey_module.report_context_tile = True
        survey_form = survey_module.new_form("Survey", None)
        survey_form.xmlns = "http://openrosa.org/formdesigner/2423EFB5-2E8C-4B8F-9DA0-23FFFD4391AE"

        with mock_report_configurations(cls.report_configs_by_id):
            cls.suite = cls.app.create_suite()
        cls.data = [
            {'color_94ec39e6': 'red', 'count': 2, 'computed_owner_name_40cc88a0': 'cory', 'fav_fruit_abc123': 'c'},
            {'color_94ec39e6': 'black', 'count': 1, 'computed_owner_name_40cc88a0': 'ctsims', 'fav_fruit_abc123': 'b'},
            {'color_94ec39e6': 'red', 'count': 3, 'computed_owner_name_40cc88a0': 'daniel', 'fav_fruit_abc123': 'b'},
        ]
        with mock_report_data(cls.data):
            with mock_report_configuration_get(cls.report_configs_by_id):
                with mock.patch('corehq.apps.app_manager.fixtures.mobile_ucr.get_apps_in_domain',
                                lambda domain, include_remote: [cls.app]):
                    with mock_datasource_config():
                        fixtures = call_fixture_generator(report_fixture_generator, cls.user)
                        fixture = [f for f in fixtures if f.attrib.get('id') == ReportFixturesProviderV1.id][0]
        cls.fixture = ElementTree.tostring(fixture, encoding='utf-8')
Beispiel #45
0
 def setUp(self):
     super(LocationFixturesTest, self).setUp()
     self.user = create_restore_user(self.domain, 'user', '123')
Beispiel #46
0
    def setUpClass(cls):
        super(ReportFiltersSuiteTest, cls).setUpClass()
        delete_all_users()
        cls.report_id = '7b97e8b53d00d43ca126b10093215a9d'
        cls.report_config_mobile_id = 'a98c812873986df34fd1b4ceb45e6164ae9cc664'
        cls.domain = 'report-filter-test-domain'
        create_domain(cls.domain)
        cls.user = create_restore_user(
            domain=cls.domain,
            username='******',
        )
        MOBILE_UCR.set(cls.domain, True, NAMESPACE_DOMAIN)

        report_configuration = cls.make_report_config(cls.domain,
                                                      cls.report_id)

        # also make a report with a hidden column
        cls.hidden_column_report_id = 'bd2a43018ad9463682165c1bc16347ac'
        cls.hidden_column_mobile_id = '45152061d8dc4d2a8d987a0568abe1ae'
        report_configuration_with_hidden_column = MAKE_REPORT_CONFIG(
            cls.domain,
            cls.hidden_column_report_id,
            columns=[
                FieldColumn(type='field',
                            aggregation="simple",
                            column_id="color_94ec39e6",
                            display="color",
                            field="color_94ec39e6").to_json(),
                FieldColumn(
                    type='field',
                    aggregation="simple",
                    column_id="hidden_color_94ec39e6",
                    display="color",
                    field="color_94ec39e6",
                    visible=False,
                ).to_json(),
            ])
        cls.report_configs_by_id = {
            cls.report_id: report_configuration,
            cls.hidden_column_report_id:
            report_configuration_with_hidden_column
        }
        cls.app = Application.new_app(cls.domain, "Report Filter Test App")
        module = cls.app.add_module(
            ReportModule.new_module("Report Module", 'en'))
        module.report_configs.append(
            ReportAppConfig(
                report_id=cls.report_id,
                header={},
                description="",
                complete_graph_configs={
                    '7451243209119342931':
                    GraphConfiguration(
                        graph_type="bar",
                        series=[
                            GraphSeries(
                                config={},
                                locale_specific_config={},
                                data_path="",
                                x_function="",
                                y_function="",
                            )
                        ],
                    )
                },
                filters=OrderedDict([
                    ('fav_fruit_abc123_1', MobileSelectFilter()),
                    ('computed_owner_name_40cc88a0_1', MobileSelectFilter()),
                ]),
                uuid=cls.report_config_mobile_id,
            ))
        module.report_configs.append(
            ReportAppConfig(
                report_id=cls.hidden_column_report_id,
                header={},
                description="",
                complete_graph_configs={},
                filters={},
                uuid=cls.hidden_column_mobile_id,
            ))
        with mock_report_configurations(cls.report_configs_by_id):
            cls.suite = cls.app.create_suite()
        cls.data = [
            {
                'color_94ec39e6': 'red',
                'count': 2,
                'computed_owner_name_40cc88a0': 'cory',
                'fav_fruit_abc123': 'c'
            },
            {
                'color_94ec39e6': 'black',
                'count': 1,
                'computed_owner_name_40cc88a0': 'ctsims',
                'fav_fruit_abc123': 'b'
            },
            {
                'color_94ec39e6': 'red',
                'count': 3,
                'computed_owner_name_40cc88a0': 'daniel',
                'fav_fruit_abc123': 'b'
            },
        ]
        with mock_report_data(cls.data):
            with mock_report_configuration_get(cls.report_configs_by_id):
                with mock.patch(
                        'corehq.apps.app_manager.fixtures.mobile_ucr.get_apps_in_domain',
                        lambda domain, include_remote: [cls.app]):
                    with mock_datasource_config():
                        fixture, = call_fixture_generator(
                            report_fixture_generator, cls.user)
        cls.fixture = ElementTree.tostring(fixture)
Beispiel #47
0
    def setUpClass(cls):
        delete_all_users()
        cls.report_id = '7b97e8b53d00d43ca126b10093215a9d'
        cls.report_config_uuid = 'a98c812873986df34fd1b4ceb45e6164ae9cc664'
        cls.domain = 'report-filter-test-domain'
        cls.user = create_restore_user(
            domain=cls.domain,
            username='******',
        )
        update_toggle_cache(MOBILE_UCR.slug, cls.domain, True,
                            NAMESPACE_DOMAIN)

        report_configuration = cls.make_report_config(cls.domain,
                                                      cls.report_id)
        cls.report_configs_by_id = {cls.report_id: report_configuration}
        cls.app = Application.new_app(cls.domain, "Report Filter Test App")
        module = cls.app.add_module(
            ReportModule.new_module("Report Module", 'en'))
        module.report_configs.append(
            ReportAppConfig(
                report_id=cls.report_id,
                header={},
                description="",
                graph_configs={
                    '7451243209119342931':
                    ReportGraphConfig(series_configs={'count': {}})
                },
                filters={
                    'computed_owner_name_40cc88a0_1': MobileSelectFilter(),
                    'fav_fruit_abc123_1': MobileSelectFilter()
                },
                uuid=cls.report_config_uuid,
            ))
        with mock_report_configurations(cls.report_configs_by_id):
            cls.suite = cls.app.create_suite()
        cls.data = [
            {
                'color_94ec39e6': 'red',
                'count': 2,
                'computed_owner_name_40cc88a0': 'cory',
                'fav_fruit_abc123': 'c'
            },
            {
                'color_94ec39e6': 'black',
                'count': 1,
                'computed_owner_name_40cc88a0': 'ctsims',
                'fav_fruit_abc123': 'b'
            },
            {
                'color_94ec39e6': 'red',
                'count': 3,
                'computed_owner_name_40cc88a0': 'daniel',
                'fav_fruit_abc123': 'b'
            },
        ]
        with mock_report_data(cls.data):
            with mock_report_configuration_get(cls.report_configs_by_id):
                with mock.patch(
                        'corehq.apps.app_manager.fixtures.mobile_ucr.get_apps_in_domain',
                        lambda domain, include_remote: [cls.app]):
                    with mock_sql_backend():
                        with mock_datasource_config():
                            fixture, = call_fixture_generator(
                                report_fixture_generator, cls.user)
        cls.fixture = ElementTree.tostring(fixture)
Beispiel #48
0
 def setUpClass(cls):
     super(SyncLogModelTest, cls).setUpClass()
     cls.project = Domain(name=cls.domain)
     cls.project.save()
     cls.restore_user = create_restore_user(cls.domain,
                                            username=uuid.uuid4().hex)