def test_linked_reports_are_popped(self): self._create_sync_event( MODEL_REPORT, ReportLinkDetail(report_id=self.linked_report.get_id).to_json()) _, downstream_reports = get_upstream_and_downstream_reports( self.downstream_domain) self.assertTrue(1, len(downstream_reports)) build_pullable_view_models_from_data_models(self.downstream_domain, self.domain_link, {}, {}, downstream_reports, {}, {}, pytz.UTC) self.assertEqual(0, len(downstream_reports))
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))
def test_linked_apps_are_popped(self): self._create_sync_event( MODEL_APP, AppLinkDetail(app_id=self.linked_app._id).to_json()) _, downstream_apps = get_upstream_and_downstream_apps( self.downstream_domain) self.assertTrue(1, len(downstream_apps)) build_pullable_view_models_from_data_models(self.downstream_domain, self.domain_link, downstream_apps, {}, {}, {}, {}, pytz.UTC) self.assertEqual(0, len(downstream_apps))
def test_linked_keywords_are_popped(self): self._create_sync_event( MODEL_KEYWORD, KeywordLinkDetail( keyword_id=str(self.linked_keyword.id)).to_json()) _, downstream_keywords = get_upstream_and_downstream_keywords( self.downstream_domain) self.assertTrue(1, len(downstream_keywords)) build_pullable_view_models_from_data_models(self.downstream_domain, self.domain_link, {}, {}, {}, downstream_keywords, {}, pytz.UTC) self.assertEqual(0, len(downstream_keywords))
def test_already_synced_superuser_view_models_are_built_if_superuser(self): self._create_sync_event(MODEL_FLAGS) view_models = build_pullable_view_models_from_data_models( self.downstream_domain, self.domain_link, {}, {}, {}, {}, {}, pytz.UTC, is_superuser=True) expected_length = len(DOMAIN_LEVEL_DATA_MODELS) + len( SUPERUSER_DATA_MODELS) self.assertEqual(expected_length, len(view_models))
def test_already_synced_report_view_models_are_built(self): self._create_sync_event( MODEL_REPORT, ReportLinkDetail(report_id=self.linked_report.get_id).to_json()) _, downstream_reports = get_upstream_and_downstream_reports( self.downstream_domain) view_models = build_pullable_view_models_from_data_models( self.downstream_domain, self.domain_link, {}, {}, downstream_reports, {}, {}, pytz.UTC) expected_length = len(DOMAIN_LEVEL_DATA_MODELS) + 1 self.assertEqual(expected_length, len(view_models))
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))
def test_already_synced_superuser_view_models_are_not_built_if_not_superuser( self): # this is an important one # ensures an already synced view model is not included if user does not have access self._create_sync_event(MODEL_FLAGS) view_models = build_pullable_view_models_from_data_models( self.downstream_domain, self.domain_link, {}, {}, {}, {}, {}, pytz.UTC, is_superuser=False) expected_length = len(DOMAIN_LEVEL_DATA_MODELS) self.assertEqual(expected_length, len(view_models))
def test_already_synced_keyword_view_models_are_built(self): self._create_sync_event( MODEL_KEYWORD, KeywordLinkDetail( keyword_id=str(self.linked_keyword.id)).to_json()) _, downstream_keywords = get_upstream_and_downstream_keywords( self.downstream_domain) self.assertTrue(1, len(downstream_keywords)) view_models = build_pullable_view_models_from_data_models( self.downstream_domain, self.domain_link, {}, {}, {}, downstream_keywords, {}, pytz.UTC) expected_length = len(DOMAIN_LEVEL_DATA_MODELS) + 1 self.assertEqual(expected_length, len(view_models))
def page_context(self): """ This view services both domains that are upstream, downstream, and legacy domains that are both """ timezone = get_timezone_for_request() upstream_link = get_upstream_domain_link(self.domain) linked_domains = [build_domain_link_view_model(link, timezone) for link in get_linked_domains(self.domain)] upstream_apps, downstream_apps = get_upstream_and_downstream_apps(self.domain) upstream_fixtures, downstream_fixtures = get_upstream_and_downstream_fixtures(self.domain, upstream_link) upstream_reports, downstream_reports = get_upstream_and_downstream_reports(self.domain) upstream_keywords, downstream_keywords = get_upstream_and_downstream_keywords(self.domain) upstream_ucr_expressions, downstream_ucr_expressions = get_upstream_and_downstream_ucr_expressions( self.domain ) is_superuser = self.request.couch_user.is_superuser timezone = get_timezone_for_request() view_models_to_pull = build_pullable_view_models_from_data_models( self.domain, upstream_link, downstream_apps, downstream_fixtures, downstream_reports, downstream_keywords, downstream_ucr_expressions, timezone, is_superuser=is_superuser ) view_models_to_push = build_view_models_from_data_models( self.domain, upstream_apps, upstream_fixtures, upstream_reports, upstream_keywords, upstream_ucr_expressions, is_superuser=is_superuser ) available_domains_to_link = get_available_domains_to_link(self.request.domain, self.request.couch_user) upstream_domain_urls = [] for domain in get_available_upstream_domains(self.request.domain, self.request.couch_user): upstream_domain_urls.append({'name': domain, 'url': reverse('domain_links', args=[domain])}) if upstream_link and upstream_link.is_remote: remote_linkable_ucr = get_remote_linkable_ucr(upstream_link) else: remote_linkable_ucr = None return { 'domain': self.domain, 'timezone': timezone.localize(datetime.utcnow()).tzname(), 'view_data': { 'is_superuser': is_superuser, 'is_downstream_domain': bool(upstream_link), 'upstream_domains': upstream_domain_urls, 'available_domains': available_domains_to_link, 'upstream_link': build_domain_link_view_model(upstream_link, timezone) if upstream_link else None, 'view_models_to_pull': sorted(view_models_to_pull, key=lambda m: m['name']), 'view_models_to_push': sorted(view_models_to_push, key=lambda m: m['name']), 'linked_domains': sorted(linked_domains, key=lambda d: d['downstream_domain']), 'linkable_ucr': remote_linkable_ucr, 'has_full_access': can_domain_access_linked_domains(self.domain, include_lite_version=False), }, }