Ejemplo n.º 1
0
def build_fixture_view_model(fixture, last_update=None):
    if not fixture:
        return None

    return build_linked_data_view_model(
        model_type=MODEL_FIXTURE,
        name=f"{LINKED_MODELS_MAP[MODEL_FIXTURE]} ({fixture.tag})",
        detail=FixtureLinkDetail(tag=fixture.tag).to_json(),
        last_update=last_update,
        can_update=fixture.is_global,
    )
Ejemplo n.º 2
0
    def _get_master_model_status(self,
                                 apps,
                                 fixtures,
                                 reports,
                                 ignore_models=None):
        model_status = []
        ignore_models = ignore_models or []

        for model, name in LINKED_MODELS:
            if (model not in ignore_models
                    and model not in (MODEL_APP, MODEL_FIXTURE, MODEL_REPORT)
                    and
                (model != MODEL_CASE_SEARCH
                 or toggles.SYNC_SEARCH_CASE_CLAIM.enabled(self.domain))):
                model_status.append({
                    'type': model,
                    'name': name,
                    'last_update': ugettext('Never'),
                    'detail': None,
                    'can_update': True
                })

        linked_models = dict(LINKED_MODELS)
        for app in apps.values():
            update = {
                'type': MODEL_APP,
                'name': '{} ({})'.format(linked_models['app'], app.name),
                'last_update': None,
                'detail': AppLinkDetail(app_id=app._id).to_json(),
                'can_update': True
            }
            model_status.append(update)
        for fixture in fixtures.values():
            update = {
                'type': MODEL_FIXTURE,
                'name': '{} ({})'.format(linked_models['fixture'],
                                         fixture.tag),
                'last_update': None,
                'detail': FixtureLinkDetail(tag=fixture.tag).to_json(),
                'can_update': fixture.is_global,
            }
            model_status.append(update)
        for report in reports.values():
            report = ReportConfiguration.get(report.get_id)
            update = {
                'type': MODEL_REPORT,
                'name': f"{linked_models['report']} ({report.title})",
                'last_update': None,
                'detail': ReportLinkDetail(report_id=report.get_id).to_json(),
                'can_update': True,
            }
            model_status.append(update)

        return model_status
Ejemplo n.º 3
0
    def test_already_synced_fixture_view_models_are_built(self):
        self._create_sync_event(
            MODEL_FIXTURE,
            FixtureLinkDetail(tag=self.original_fixture.tag).to_json())

        _, downstream_fixtures = get_upstream_and_downstream_fixtures(
            self.downstream_domain, self.domain_link)
        view_models = build_pullable_view_models_from_data_models(
            self.downstream_domain, self.domain_link, {}, downstream_fixtures,
            {}, {}, {}, pytz.UTC)
        expected_length = len(DOMAIN_LEVEL_DATA_MODELS) + 1
        self.assertEqual(expected_length, len(view_models))
Ejemplo n.º 4
0
    def test_linked_fixtures_are_popped(self):
        self._create_sync_event(
            MODEL_FIXTURE,
            FixtureLinkDetail(tag=self.original_fixture.tag).to_json())

        _, downstream_fixtures = get_upstream_and_downstream_fixtures(
            self.downstream_domain, self.domain_link)
        self.assertTrue(1, len(downstream_fixtures))
        build_pullable_view_models_from_data_models(self.downstream_domain,
                                                    self.domain_link, {},
                                                    downstream_fixtures, {},
                                                    {}, {}, pytz.UTC)
        self.assertEqual(0, len(downstream_fixtures))
Ejemplo n.º 5
0
def build_fixture_view_model(fixture, last_update=None):
    can_update = False
    name = _('Unknown Table')
    detail = None

    if fixture:
        can_update = fixture.is_global
        name = fixture.tag
        detail = FixtureLinkDetail(tag=fixture.tag).to_json()

    view_model = build_linked_data_view_model(
        model_type=MODEL_FIXTURE,
        name=f"{LINKED_MODELS_MAP[MODEL_FIXTURE]} ({name})",
        detail=detail,
        last_update=last_update,
        can_update=can_update
    )

    return view_model
Ejemplo n.º 6
0
    def _get_master_model_status(self,
                                 apps,
                                 fixtures,
                                 reports,
                                 keywords,
                                 ignore_models=None):
        model_status = []
        ignore_models = ignore_models or []

        for model, name in LINKED_MODELS:
            if (model not in ignore_models
                    and model not in (MODEL_APP, MODEL_FIXTURE, MODEL_REPORT,
                                      MODEL_KEYWORD) and
                (model != MODEL_CASE_SEARCH
                 or toggles.SYNC_SEARCH_CASE_CLAIM.enabled(self.domain))
                    and (model != MODEL_DATA_DICTIONARY
                         or toggles.DATA_DICTIONARY.enabled(self.domain))
                    and (model != MODEL_DIALER_SETTINGS
                         or toggles.WIDGET_DIALER.enabled(self.domain))
                    and (model != MODEL_OTP_SETTINGS
                         or toggles.GAEN_OTP_SERVER.enabled(self.domain))
                    and (model != MODEL_HMAC_CALLOUT_SETTINGS
                         or toggles.HMAC_CALLOUT.enabled(self.domain))):
                model_status.append({
                    'type': model,
                    'name': name,
                    'last_update': ugettext('Never'),
                    'detail': None,
                    'can_update': True
                })

        linked_models = dict(LINKED_MODELS)
        for app in apps.values():
            update = {
                'type': MODEL_APP,
                'name': '{} ({})'.format(linked_models['app'], app.name),
                'last_update': None,
                'detail': AppLinkDetail(app_id=app._id).to_json(),
                'can_update': True
            }
            model_status.append(update)
        for fixture in fixtures.values():
            update = {
                'type': MODEL_FIXTURE,
                'name': '{} ({})'.format(linked_models['fixture'],
                                         fixture.tag),
                'last_update': None,
                'detail': FixtureLinkDetail(tag=fixture.tag).to_json(),
                'can_update': fixture.is_global,
            }
            model_status.append(update)
        for report in reports.values():
            report = ReportConfiguration.get(report.get_id)
            update = {
                'type': MODEL_REPORT,
                'name': f"{linked_models['report']} ({report.title})",
                'last_update': None,
                'detail': ReportLinkDetail(report_id=report.get_id).to_json(),
                'can_update': True,
            }
            model_status.append(update)

        for keyword in keywords.values():
            update = {
                'type': MODEL_KEYWORD,
                'name': f"{linked_models['keyword']} ({keyword.keyword})",
                'last_update': None,
                'detail':
                KeywordLinkDetail(keyword_id=str(keyword.id)).to_json(),
                'can_update': True,
            }
            model_status.append(update)

        return model_status