Exemple #1
0
def load_fixture(name, manager=None):
    """ Load fixture data into the database. """
    meta = meta_fixture(name)
    dataset = Dataset(meta)
    dataset.updated_at = datetime.utcnow()
    if manager is not None:
        dataset.managers.append(manager)
    fields, rows = csvimport_table(name)
    dataset.fields = fields
    db.session.add(dataset)
    db.session.commit()
    dataset.fact_table.create()
    dataset.fact_table.load_iter(rows)
    return dataset
Exemple #2
0
def load_fixture(name, manager=None):
    """ Load fixture data into the database. """
    meta = meta_fixture(name)
    dataset = Dataset(meta)
    dataset.updated_at = datetime.utcnow()
    if manager is not None:
        dataset.managers.append(manager)
    fields, rows = csvimport_table(name)
    dataset.fields = fields
    db.session.add(dataset)
    db.session.commit()
    dataset.fact_table.create()
    dataset.fact_table.load_iter(rows)
    return dataset
Exemple #3
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)
Exemple #4
0
 def list_cubes(self):
     # TODO: authz, failing conservatively for now.
     for dataset in Dataset.all_by_account(None):
         if dataset.model is not None:
             yield dataset.name
Exemple #5
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
Exemple #6
0
 def has_cube(self, name):
     dataset = Dataset.by_name(name)
     if dataset is None:
         return False
     return dataset.model is not None