def test_should_copy_all_object_from_latest_to_tag(self): numeric_version = 0.8 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') data_key = bit_store.build_s3_key('data.csv') metadata_key = bit_store.build_s3_key('datapackage.json') s3.put_object(Bucket=bucket_name, Key=read_me_key, Body='readme') s3.put_object(Bucket=bucket_name, Key=data_key, Body='data') s3.put_object(Bucket=bucket_name, Key=metadata_key, Body='metedata') bit_store.copy_to_new_version(numeric_version) bit_store_numeric = BitStore('test_pub', 'test_package', numeric_version) objects_nu = s3.list_objects( Bucket=bucket_name, Prefix=bit_store_numeric.build_s3_versioned_prefix()) objects_old = s3.list_objects( Bucket=bucket_name, Prefix=bit_store.build_s3_versioned_prefix()) self.assertEqual(len(objects_nu['Contents']), len(objects_old['Contents']))
def test_throw_403_if_not_owner_or_member_of_publisher(self): s3 = boto3.client('s3') s3.create_bucket(Bucket=self.bucket_name) bit_store = BitStore('test_pub', 'test_package') read_me_key = bit_store.build_s3_key('test.md') data_key = bit_store.build_s3_key('data.csv') metadata_key = bit_store.build_s3_key('datapackage.json') s3.put_object(Bucket=self.bucket_name, Key=read_me_key, Body='readme') s3.put_object(Bucket=self.bucket_name, Key=data_key, Body='data') s3.put_object(Bucket=self.bucket_name, Key=metadata_key, Body='metedata') response = self.client.post(self.jwt_url, data=json.dumps({ 'username': self.user_not_allowed_name, 'secret': 'super_secret' }), content_type='application/json') data = json.loads(response.data) jwt_not_allowed = data['token'] auth_not_allowed = "bearer %s" % jwt_not_allowed response = self.client.post( self.url, data=json.dumps({'version': 'tag_one'}), content_type='application/json', headers=dict(Authorization=auth_not_allowed)) self.assertEqual(response.status_code, 403) with self.app.app_context(): data_latest = Package.query.join(Publisher). \ filter(Publisher.name == self.publisher_name, Package.name == self.package).all() self.assertEqual(1, len(data_latest)) bit_store_tagged = BitStore('test_pub', 'test_package', 'tag_one') objects_nu = s3.list_objects( Bucket=self.bucket_name, Prefix=bit_store_tagged.build_s3_versioned_prefix()) self.assertTrue('Contents' not in objects_nu)