Ejemplo n.º 1
0
    def test_feeds(self):
        # Anonymous user with one public dataset
        response = self.client.get(url_for('home.feed_rss'))
        assert 'application/xml' in response.content_type
        assert '<title>Recently Created Datasets</title>' in response.data
        assert '<item><title>Country Regional Analysis v2009' in response.data, response.data
        cra = Dataset.by_name('cra')
        cra.private = True
        db.session.add(cra)
        db.session.commit()

        # Anonymous user with one private dataset
        response = self.client.get(url_for('home.feed_rss'))
        assert 'application/xml' in response.content_type
        assert '<title>Recently Created Datasets</title>' in response.data
        assert '<item><title>Country Regional Analysis v2009' not in response.data

        # Logged in user with one public dataset
        cra.private = False
        db.session.add(cra)
        db.session.commit()
        response = self.client.get(url_for('home.feed_rss'),
                                   query_string={'api_key': self.user.api_key})
        assert 'application/xml' in response.content_type
        assert '<title>Recently Created Datasets</title>' in response.data
        assert '<item><title>Country Regional Analysis v2009' in response.data

        # Logged in user with one private dataset
        cra.private = True
        db.session.add(cra)
        db.session.commit()
        response = self.client.get(url_for('home.feed_rss'),
                                   query_string={'api_key': self.user.api_key})
        assert 'application/xml' in response.content_type
        assert '<title>Recently Created Datasets</title>' in response.data
        assert '<item><title>Country Regional Analysis v2009' not in response.data

        # Logged in admin user with one private dataset
        admin_user = make_account('admin')
        admin_user.admin = True
        db.session.add(admin_user)
        db.session.commit()
        response = self.client.get(url_for('home.feed_rss'),
                                   query_string={'api_key': admin_user.api_key})
        assert '<title>Recently Created Datasets</title>' in response.data
        assert '<item><title>Country Regional Analysis v2009' in response.data
        assert 'application/xml' in response.content_type

        response = self.client.get('/')
        norm = re.sub('\s+', ' ', response.data)
        assert ('<link rel="alternate" type="application/rss+xml" title="'
                'Latest Datasets on SpenDB"' in
                norm)
Ejemplo n.º 2
0
 def get_cube(self, name):
     dataset = Dataset.by_name(name)
     if dataset is None or dataset.model is None:
         return None
     return dataset.cube
Ejemplo n.º 3
0
 def has_cube(self, name):
     dataset = Dataset.by_name(name)
     if dataset is None:
         return False
     return dataset.model is not None