Example #1
0
 def test_topic_api_update(self):
     '''It should update a topic from the API'''
     topic = TopicFactory()
     data = topic.to_dict()
     data['description'] = 'new description'
     self.login(AdminFactory())
     response = self.put(url_for('api.topic', topic=topic), data)
     self.assert200(response)
     self.assertEqual(Topic.objects.count(), 1)
     self.assertEqual(Topic.objects.first().description, 'new description')
Example #2
0
 def test_topic_api_update(self):
     '''It should update a topic from the API'''
     topic = TopicFactory()
     data = topic.to_dict()
     data['description'] = 'new description'
     self.login(AdminFactory())
     response = self.put(url_for('api.topic', topic=topic), data)
     self.assert200(response)
     self.assertEqual(Topic.objects.count(), 1)
     self.assertEqual(Topic.objects.first().description, 'new description')
Example #3
0
 def test_topic_api_delete(self):
     '''It should delete a topic from the API'''
     topic = TopicFactory()
     with self.api_user(AdminFactory()):
         response = self.delete(url_for('api.topic', topic=topic))
     self.assertStatus(response, 204)
     self.assertEqual(Topic.objects.count(), 0)
Example #4
0
    def test_topic_api_list(self):
        '''It should fetch a topic list from the API'''
        topics = TopicFactory.create_batch(3)

        response = self.get(url_for('api.topics'))
        self.assert200(response)
        self.assertEqual(len(response.json['data']), len(topics))
Example #5
0
    def test_empty_search_with_filter_and_match(self):
        '''Should match both the topic criteria and the query'''
        with self.autoindex():
            # Match both the topic condition but the queried tag
            match = VisibleDatasetFactory.create_batch(2, tags=[
                'in', 'filtered'
            ])
            # Match the topic condition but not the queried tag
            no_match = VisibleDatasetFactory.create_batch(2, tags=['in'])
            # Excluded because not matching one of the topic tag
            excluded = VisibleDatasetFactory.create_batch(2, tags=[
                'out', 'filtered'
            ])
        topic = TopicFactory(tags=['in', 'no-match'])

        query = topic_search_for(topic, DatasetSearch, tag='filtered')
        result = search.query(query)

        found = [d.id for d in result]

        self.assertEqual(len(found), 2)

        for dataset in match:
            self.assertIn(dataset.id, found)
        for dataset in no_match + excluded:
            self.assertNotIn(dataset.id, found)
Example #6
0
    def test_topic_api_list(self):
        '''It should fetch a topic list from the API'''
        topics = TopicFactory.create_batch(3)

        response = self.get(url_for('api.topics'))
        self.assert200(response)
        self.assertEqual(len(response.json['data']), len(topics))
Example #7
0
    def test_render_display_empty(self):
        '''It should render a topic page even if empty'''
        self.init_search()
        topic = TopicFactory(tags=['tag'])

        response = self.get(url_for('topics.display', topic=topic))
        self.assert200(response)
Example #8
0
    def test_render_reuses_with_topic_parameter(self):
        '''Should render a topic reuses page even with a topic parameter'''
        self.init_search()
        topic = TopicFactory(tags=['tag'])

        url = url_for('topics.reuses', topic=topic, qs={'topic': 'whatever'})
        response = self.get(url)
        self.assert200(response)
Example #9
0
    def test_topic_api_get(self):
        '''It should fetch a topic from the API'''
        topic = TopicFactory()
        response = self.get(url_for('api.topic', topic=topic))
        self.assert200(response)

        data = response.json
        for dataset, expected in zip(data['datasets'], topic.datasets):
            self.assertEqual(dataset['id'], str(expected.id))
Example #10
0
    def test_render_reuses_empty(self):
        '''It should render a topic reuses page even if empty'''
        self.init_search()
        topic = TopicFactory(tags=['tag'])

        response = self.get(url_for('topics.reuses', topic=topic))
        self.assert200(response)

        self.assertEqual(len(self.get_context_variable('reuses')), 0)
Example #11
0
    def test_empty_search_no_match(self):
        '''Should return no result if no data match the tags'''
        with self.autoindex():
            VisibleDatasetFactory.create_batch(2, tags=['whatever'])
        topic = TopicFactory(tags=['no-match'])

        query = topic_search_for(topic, DatasetSearch)
        result = search.query(query)

        self.assertEqual(len(result), 0)
Example #12
0
    def test_topics_within_sitemap(self):
        '''It should return a topic list from the sitemap.'''
        topics = TopicFactory.create_batch(3)

        self.get_sitemap_tree()

        for topic in topics:
            url = self.get_by_url('topics.display_redirect', topic=topic)
            self.assertIsNotNone(url)
            self.assert_url(url, 0.8, 'weekly')
Example #13
0
    def test_topics_within_sitemap(self, sitemap):
        '''It should return a topic list from the sitemap.'''
        topics = TopicFactory.create_batch(3)

        sitemap.fetch()

        for topic in topics:
            url = sitemap.get_by_url('topics.display_redirect', topic=topic)
            assert url is not None
            # assert url is not None
            sitemap.assert_url(url, 0.8, 'weekly')
Example #14
0
    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)
Example #15
0
    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'])
Example #16
0
 def test_topic_api_create(self):
     '''It should create a topic from the API'''
     data = TopicFactory.as_dict()
     data['datasets'] = [str(d.id) for d in data['datasets']]
     data['reuses'] = [str(r.id) for r in data['reuses']]
     self.login(AdminFactory())
     response = self.post(url_for('api.topics'), data)
     self.assert201(response)
     self.assertEqual(Topic.objects.count(), 1)
     topic = Topic.objects.first()
     for dataset, expected in zip(topic.datasets, data['datasets']):
         self.assertEqual(str(dataset.id), expected)
     for reuse, expected in zip(topic.reuses, data['reuses']):
         self.assertEqual(str(reuse.id), expected)
Example #17
0
    def test_render_datasets(self):
        '''It should render a topic datasets page'''
        with self.autoindex():
            [VisibleDatasetFactory(tags=['tag-{0}'.format(i)])
             for i in range(3)]
        topic = TopicFactory(tags=['tag-0', 'tag-2'])

        response = self.get(url_for('topics.datasets', topic=topic))
        self.assert200(response)

        rendered_datasets = self.get_context_variable('datasets')
        self.assertEqual(len(rendered_datasets), 2)
        for dataset in rendered_datasets:
            self.assertIn(dataset.tags[0], ['tag-0', 'tag-2'])
Example #18
0
 def test_topic_api_create(self):
     '''It should create a topic from the API'''
     data = TopicFactory.as_dict()
     data['datasets'] = [str(d.id) for d in data['datasets']]
     data['reuses'] = [str(r.id) for r in data['reuses']]
     self.login(AdminFactory())
     response = self.post(url_for('api.topics'), data)
     self.assert201(response)
     self.assertEqual(Topic.objects.count(), 1)
     topic = Topic.objects.first()
     for dataset, expected in zip(topic.datasets, data['datasets']):
         self.assertEqual(str(dataset.id), expected)
     for reuse, expected in zip(topic.reuses, data['reuses']):
         self.assertEqual(str(reuse.id), expected)
Example #19
0
    def test_empty_search_with_match(self):
        '''Should only return data with at least one tag'''
        with self.autoindex():
            included = VisibleDatasetFactory.create_batch(2, tags=['in'])
            excluded = VisibleDatasetFactory.create_batch(2, tags=['out'])
        topic = TopicFactory(tags=['in', 'no-match'])

        query = topic_search_for(topic, DatasetSearch)
        result = search.query(query)

        found = [d.id for d in result]

        self.assertEqual(len(found), 2)

        for dataset in included:
            self.assertIn(dataset.id, found)
        for dataset in excluded:
            self.assertNotIn(dataset.id, found)