def test_render_dataconnexions_6_with_data(self): # Use tags until we are sure all reuse are correctly labeled for tag, label, description in DATACONNEXIONS_6_CATEGORIES: badge = Badge(kind=DATACONNEXIONS_6_CANDIDATE) VisibleReuseFactory(tags=['dataconnexions-6', tag], badges=[badge]) response = self.client.get(url_for('gouvfr.dataconnexions6')) self.assert200(response)
def test_set_home_reuses(self): ids = [r.id for r in VisibleReuseFactory.create_batch(3)] self.login(AdminFactory()) response = self.put(url_for('api.home_reuses'), ids) self.assert200(response) self.assertEqual(len(response.json), len(ids)) site = Site.objects.get(id=self.app.config['SITE_ID']) self.assertEqual([r.id for r in site.settings.home_reuses], ids)
def test_get_home_reuses(self): site = SiteFactory.create( id=self.app.config['SITE_ID'], settings__home_reuses=VisibleReuseFactory.create_batch(3) ) current_site.reload() self.login(AdminFactory()) response = self.get(url_for('api.home_reuses')) self.assert200(response) self.assertEqual(len(response.json), len(site.settings.home_reuses))
def test_render_reuses(self): '''It should render a topic reuses page''' with self.autoindex(): [VisibleReuseFactory(tags=['tag-{0}'.format(i)]) for i in range(3)] topic = TopicFactory(tags=['tag-0', 'tag-2']) response = self.get(url_for('topics.reuses', topic=topic)) self.assert200(response) rendered_reuses = self.get_context_variable('reuses') self.assertEqual(len(rendered_reuses), 2) for reuse in rendered_reuses: self.assertIn(reuse.tags[0], ['tag-0', 'tag-2'])
def test_render_display(self): '''It should render a topic page''' with self.autoindex(): reuses = [ VisibleReuseFactory(tags=['tag-{0}'.format(i)]) for i in range(3) ] datasets = [ VisibleDatasetFactory(tags=['tag-{0}'.format(i)]) for i in range(3) ] topic = TopicFactory(tags=['tag-0', 'tag-2'], datasets=datasets, reuses=reuses) response = self.get(url_for('topics.display', topic=topic)) self.assert200(response)
def test_count(self): for i in range(1, 4): VisibleDatasetFactory(tags=['tag-{0}'.format(j) for j in range(i)]) VisibleReuseFactory(tags=['tag-{0}'.format(j) for j in range(i)]) count_tags.run() expected = { 'tag-0': 3, 'tag-1': 2, 'tag-2': 1, } self.assertEqual(len(Tag.objects), len(expected)) for name, count in expected.items(): tag = Tag.objects.get(name=name) self.assertEqual(tag.total, 2 * count) self.assertEqual(tag.counts['datasets'], count) self.assertEqual(tag.counts['reuses'], count)
def test_count(self): for i in range(1, 4): # Tags should be slugified and deduplicated. tags = ['Tag "{0}"'.format(j) for j in range(i)] + ['tag-0'] VisibleDatasetFactory(tags=tags) VisibleReuseFactory(tags=tags) count_tags.run() expected = { 'tag-0': 3, 'tag-1': 2, 'tag-2': 1, } self.assertEqual(len(Tag.objects), len(expected)) for name, count in expected.items(): tag = Tag.objects.get(name=name) self.assertEqual(tag.total, 2 * count) self.assertEqual(tag.counts['datasets'], count) self.assertEqual(tag.counts['reuses'], count)
def test_render_dataconnexions_5_with_data(self): for tag, label, description in DATACONNEXIONS_5_CATEGORIES: badge = Badge(kind=DATACONNEXIONS_5_CANDIDATE) VisibleReuseFactory(tags=[tag], badges=[badge]) response = self.client.get(url_for('gouvfr.dataconnexions5')) self.assert200(response)