Esempio n. 1
0
def populate_data(publisher_name):
    data = json.loads(open('fixtures/datapackage.json').read())
    data_csv = open('fixtures/data/demo-resource.csv').read()
    readme = open('fixtures/README.md').read()
    package = models.Package.query.join(models.Publisher)\
        .filter(models.Package.name == "demo-package",
                models.Publisher.name == publisher_name).first()
    if package:
        db.session.delete(models.Package.query.get(package.id))
        db.session.commit()
    publisher = models.Publisher.query.filter_by(name=publisher_name).first()
    metadata = models.Package(name="demo-package",
                              descriptor=data,
                              readme=readme)
    metadata.status, metadata.private \
        = 'active', False

    publisher.packages.append(metadata)
    db.session.add(publisher)
    db.session.commit()
    bitstore = BitStore(publisher_name,
                        package='demo-package',
                        body=json.dumps(data))
    bitstore.save_metadata()
    key = bitstore.build_s3_key('demo-resource.csv')
    bucket_name = app.config['S3_BUCKET_NAME']
    s3_client = app.config['S3']
    s3_client.put_object(Bucket=bucket_name,
                         Key=key,
                         Body=data_csv,
                         ACL='public-read')
Esempio n. 2
0
    def create_or_update(cls, name, publisher_name, **kwargs):
        pub_id = models.Publisher.query.filter_by(name=publisher_name).one().id
        instance = models.Package.get_by_publisher(publisher_name, name)

        if instance is None:
            instance = models.Package(name=name)
            instance.publisher_id = pub_id

        for key, value in kwargs.items():
            setattr(instance, key, value)

        db.session.add(instance)
        db.session.commit()
Esempio n. 3
0
    def create_or_update(cls, name, publisher_name, **kwargs):
        pub_id = models.Publisher.query.filter_by(name=publisher_name).one().id
        instance = models.Package.get_by_publisher(publisher_name, name)

        if instance is None:
            instance = models.Package(name=name)
            instance.publisher_id = pub_id
            tag_instance = models.PackageTag()
            instance.tags.append(tag_instance)
        else:
            tag_instance = models.PackageTag.query.join(models.Package) \
                .filter(models.Package.id == instance.id,
                        models.PackageTag.tag == 'latest').one()
        for key, value in kwargs.items():
            if key not in ['descriptor', 'readme']:
                setattr(instance, key, value)
            else:
                setattr(tag_instance, key, value)
        db.session.add(instance)
        db.session.commit()
Esempio n. 4
0
    def setUp(self):
        self.publisher_name = 'demo'
        self.package_name = 'demo-package'
        self.app = create_app()
        self.app.app_context().push()
        with self.app.app_context():
            db.drop_all()
            db.create_all()
            self.user = models.User()
            self.user.email, self.user.name, self.user.secret = \
                '*****@*****.**', self.publisher_name, 'super_secret'
            self.publisher = models.Publisher(name=self.publisher_name)
            self.association = models.PublisherUser(
                role=models.UserRoleEnum.owner)
            self.metadata = models.Package(name=self.package_name)
            self.metadata.tags.append(models.PackageTag(descriptor={}))
            self.publisher.packages.append(self.metadata)
            self.association.publisher = self.publisher
            self.user.publishers.append(self.association)

            db.session.add(self.user)
            db.session.commit()