Esempio n. 1
0
 def test_return_none_if_object_found(self):
     with self.app.app_context():
         bit_store = BitStore('test_pub', 'test_package')
         s3 = boto3.client('s3')
         bucket_name = self.app.config['S3_BUCKET_NAME']
         s3.create_bucket(Bucket=bucket_name)
         read_me_key = bit_store.build_s3_key('test.md')
         s3.put_object(Bucket=bucket_name, Key=read_me_key, Body='')
         self.assertEqual(bit_store.get_s3_object(read_me_key + "testing"), None)
         self.assertEqual(bit_store.get_s3_object('None'), None)
Esempio n. 2
0
    def finalize_publish(cls, user_id, datapackage_url):
        '''
        Gets the datapackage.json and README from S3 and imports into database.
        Returns status "queued" if ok, else - None
        '''
        publisher, package, version = BitStore.extract_information_from_s3_url(
            datapackage_url)
        if Package.exists(publisher, package):
            status = check_is_authorized('Package::Update', publisher, package,
                                         user_id)
        else:
            status = check_is_authorized('Package::Create', publisher, package,
                                         user_id)

        if not status:
            raise InvalidUsage('Not authorized to upload data', 400)

        bit_store = BitStore(publisher, package)
        b = bit_store.get_metadata_body()
        body = json.loads(b)
        bit_store.change_acl('public-read')
        readme = bit_store.get_s3_object(bit_store.get_readme_object_key())
        Package.create_or_update(name=package,
                                 publisher_name=publisher,
                                 descriptor=body,
                                 readme=readme)
        return "queued"