Пример #1
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')
        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()
Пример #2
0
    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()
Пример #3
0
    def setUpClass(cls):
        create_domain(cls.domain)
        toggles.MOBILE_UCR.set(cls.domain, True, toggles.NAMESPACE_DOMAIN)
        cls.user = CommCareUser.create(cls.domain, 'john_doe', 's3cr3t')

        cls.app1 = Application.new_app(cls.domain, 'Test App 1', application_version=APP_V2)
        cls.report_config1 = get_sample_report_config()
        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.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()
Пример #4
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")
        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()
Пример #5
0
 def test_existing_uuid(self):
     existing_uuid = 'existing_uuid'
     self.assertEqual(
         existing_uuid,
         ReportAppConfig.wrap({
             "report_id": "report_id",
             "uuid": existing_uuid,
         }).uuid)
Пример #6
0
 def test_existing_uuid(self):
     existing_uuid = 'existing_uuid'
     self.assertEqual(
         existing_uuid,
         ReportAppConfig.wrap({
             "report_id": "report_id",
             "uuid": existing_uuid,
         }).uuid
     )
Пример #7
0
def edit_report_module(request, domain, app_id, module_unique_id):
    """
    Overwrite module case details. Only overwrites components that have been
    provided in the request. Components are short, long, filter, parent_select,
    and sort_elements.
    """
    params = json_request(request.POST)
    app = get_app(domain, app_id)

    try:
        module = app.get_module_by_unique_id(module_unique_id)
    except ModuleNotFoundException:
        # temporary fallback
        module = app.get_module(module_unique_id)

    assert isinstance(module, ReportModule)
    module.name = params['name']

    try:
        module.report_configs = [
            ReportAppConfig.wrap(spec) for spec in params['reports']
        ]
    except Exception:
        notify_exception(
            request,
            message="Something went wrong while editing report modules",
            details={
                'domain': domain,
                'app_id': app_id,
            })
        return HttpResponseBadRequest(
            _("There was a problem processing your request."))

    if app.enable_module_filtering:
        module['module_filter'] = request.POST.get('module_filter')
    module.media_image.update(params['multimedia']['mediaImage'])
    module.media_audio.update(params['multimedia']['mediaAudio'])

    try:
        app.save()
    except Exception:
        notify_exception(
            request,
            message=
            "Something went wrong while saving app {} while editing report modules"
            .format(app_id),
            details={
                'domain': domain,
                'app_id': app_id,
            })
        return HttpResponseBadRequest(
            _("There was a problem processing your request."))

    get_uuids_by_instance_id.clear(domain)
    return json_response('success')
Пример #8
0
def edit_report_module(request, domain, app_id, module_id):
    """
    Overwrite module case details. Only overwrites components that have been
    provided in the request. Components are short, long, filter, parent_select,
    and sort_elements.
    """
    params = json_request(request.POST)
    app = get_app(domain, app_id)
    module = app.get_module(module_id)
    assert isinstance(module, ReportModule)
    module.name = params['name']
    module.report_configs = [ReportAppConfig.wrap(spec) for spec in params['reports']]
    app.save()
    return json_response('success')
Пример #9
0
def edit_report_module(request, domain, app_id, module_unique_id):
    """
    Overwrite module case details. Only overwrites components that have been
    provided in the request. Components are short, long, filter, parent_select,
    and sort_elements.
    """
    params = json_request(request.POST)
    app = get_app(domain, app_id)

    try:
        module = app.get_module_by_unique_id(module_unique_id)
    except ModuleNotFoundException:
        # temporary fallback
        module = app.get_module(module_unique_id)

    assert isinstance(module, ReportModule)
    module.name = params['name']

    try:
        module.report_configs = [ReportAppConfig.wrap(spec) for spec in params['reports']]
    except Exception:
        notify_exception(
            request,
            message="Something went wrong while editing report modules",
            details={'domain': domain, 'app_id': app_id, }
        )
        return HttpResponseBadRequest(_("There was a problem processing your request."))

    if app.enable_module_filtering:
        module['module_filter'] = request.POST.get('module_filter')

    module.media_image.update(params['multimedia']['mediaImage'])
    module.media_audio.update(params['multimedia']['mediaAudio'])

    if 'name_enum' in params:
        name_enum = json.loads(request.POST.get("name_enum"))
        module.name_enum = [MappingItem(i) for i in name_enum]

    try:
        app.save()
    except Exception:
        notify_exception(
            request,
            message="Something went wrong while saving app {} while editing report modules".format(app_id),
            details={'domain': domain, 'app_id': app_id, }
        )
        return HttpResponseBadRequest(_("There was a problem processing your request."))

    get_uuids_by_instance_id.clear(domain)
    return json_response('success')
Пример #10
0
    def test_get_report_fixture_for_user(self):
        from corehq.apps.userreports.reports.data_source import ConfigurableReportDataSource
        from corehq.apps.userreports.tests.utils import mock_datasource_config
        from corehq.apps.app_manager.models import ReportAppConfig

        app_report_config = ReportAppConfig.wrap({
            'report_id': self.report_config1.get_id,
            'uuid': 'abcdef'
        })
        with mock.patch.object(ConfigurableReportDataSource, 'get_data') as get_data_mock, \
            mock.patch('custom.icds.messaging.indicators.get_report_configs') as get_report_configs:
            get_report_configs.return_value = {'test_id': app_report_config}
            get_data_mock.return_value = [{'owner': 'bob', 'count': 3, 'is_starred': True}]

            with mock_datasource_config():
                fixture = _get_report_fixture_for_user(self.domain, 'test_id', self.user).decode('utf8')
                self.assertIn(self.report_config1.get_id, fixture)
Пример #11
0
def edit_report_module(request, domain, app_id, module_id):
    """
    Overwrite module case details. Only overwrites components that have been
    provided in the request. Components are short, long, filter, parent_select,
    and sort_elements.
    """
    params = json_request(request.POST)
    app = get_app(domain, app_id)
    module = app.get_module(module_id)
    assert isinstance(module, ReportModule)
    module.name = params['name']
    module.report_configs = [ReportAppConfig.wrap(spec) for spec in params['reports']]
    if (feature_previews.MODULE_FILTER.enabled(domain) and
            app.enable_module_filtering):
        module['module_filter'] = request.POST.get('module_filter')
    module.media_image.update(params['multimedia']['mediaImage'])
    module.media_audio.update(params['multimedia']['mediaAudio'])
    app.save()
    return json_response('success')
Пример #12
0
def edit_report_module(request, domain, app_id, module_id):
    """
    Overwrite module case details. Only overwrites components that have been
    provided in the request. Components are short, long, filter, parent_select,
    and sort_elements.
    """
    params = json_request(request.POST)
    app = get_app(domain, app_id)
    module = app.get_module(module_id)
    assert isinstance(module, ReportModule)
    module.name = params['name']

    try:
        module.report_configs = [ReportAppConfig.wrap(spec) for spec in params['reports']]
    except Exception:
        notify_exception(
            request,
            message="Something went wrong while editing report modules",
            details={'domain': domain, 'app_id': app_id, }
        )
        return HttpResponseBadRequest(_("There was a problem processing your request."))

    if (feature_previews.MODULE_FILTER.enabled(domain) and
            app.enable_module_filtering):
        module['module_filter'] = request.POST.get('module_filter')
    module.media_image.update(params['multimedia']['mediaImage'])
    module.media_audio.update(params['multimedia']['mediaAudio'])

    try:
        app.save()
    except Exception:
        notify_exception(
            request,
            message="Something went wrong while saving app {} while editing report modules".format(app_id),
            details={'domain': domain, 'app_id': app_id, }
        )
        return HttpResponseBadRequest(_("There was a problem processing your request."))

    return json_response('success')