Ejemplo n.º 1
0
 def test_get_views_if_views_dont_exist(self):
     descriptor = {'name': 'test', 'resources': []}
     with self.app.app_context():
         db.drop_all()
         db.create_all()
         publisher = Publisher(name=self.publisher)
         metadata = MetaDataDB(name=self.package)
         metadata.descriptor = json.dumps(descriptor)
         publisher.packages.append(metadata)
         db.session.add(publisher)
         db.session.commit()
     response = self.client.get('/api/package/%s/%s'%\
                                (self.publisher, self.package))
     catalog = Catalog(json.loads(response.data))
     views = catalog.get_views()
     self.assertEqual(views, [])
Ejemplo n.º 2
0
def datapackage_show(publisher, package):
    """
    Loads datapackage page for given owner
    ---
    tags:
      - site
    parameters:
      - name: publisher
        in: path
        type: string
        required: true
        description: datapackage owner name
      - name: package
        in: path
        type: string
        description: datapackage name
    responses:
      404:
        description: Datapackage does not exist
      200:
        description: Succesfuly loaded
    """
    metadata = json.loads(
        app.test_client().\
        get('/api/package/{publisher}/{package}'.\
            format(publisher=publisher, package=package)).data)
    try:
        if metadata['error_code'] == 'DATA_NOT_FOUND':
            return "404 Not Found", 404
    except:
        pass
    catalog = Catalog(metadata)
    dataset = catalog.construct_dataset(request.url_root)
    dataViews = catalog.get_views()

    return render_template("dataset.html",
                           dataset=dataset,
                           showDataApi=True,
                           jsonDataPackage=dataset,
                           dataViews=dataViews,
                           zappa_env=get_zappa_prefix(),
                           s3_cdn=get_s3_cdn_prefix()), 200
Ejemplo n.º 3
0
 def test_get_views(self):
     descriptor = {
         'name': 'test',
         'resources': [],
         'views': [{"type": "graph"}]
     }
     with self.app.app_context():
         db.drop_all()
         db.create_all()
         publisher = Publisher(name=self.publisher)
         metadata = MetaDataDB(name=self.package)
         metadata.descriptor = json.dumps(descriptor)
         publisher.packages.append(metadata)
         db.session.add(publisher)
         db.session.commit()
     response = self.client.get('/api/package/%s/%s'%\
                                (self.publisher, self.package))    
     catalog = Catalog(json.loads(response.data))
     views = catalog.get_views()
     self.assertNotEqual(len(views), 0)
     self.assertEqual(views[0].get('type'), 'graph')