def test_s3_bucket(self): """test s3_bucket attribute and default""" node = S3() # default assert node.s3_bucket == settings['S3_BUCKET_NAME'] # set value node = S3(s3_bucket=self.bucket) assert node.s3_bucket == self.bucket
def test_del(self): """test destructor""" # smoke test node = S3() del node assert True # should remove tmp files filepath = os.path.join(os.path.dirname(__file__), '.temp') open(filepath, 'a').close() node = S3() node._temp_file_cleanup = [filepath] del node assert ~os.path.exists(filepath)
def test_node(self): """test node attribute and defaults""" parent_node = Node() node = S3(source=self.source, node=parent_node) assert node.node_class
def test_s3_source(self): """test s3 data source""" source = r'SMAPSentinel/SMAP_L2_SM_SP_1AIWDV_20170801T000000_20170731T114719_094E21N_T15110_002.h5' s3 = S3(source=source) assert s3.s3_data s3.node_class = SMAPSentinelSource assert s3.node_class ### # Copied from main of s3Source ### # Rename files in s3 bucket s3_bucket = 'podpac-s3' # TODO: what bucket was this referring to? s3 = boto3.resource('s3').Bucket(s3_bucket) s3.Bucket(name=s3_bucket) obs = list(s3.objects.all()) obs2 = [o for o in obs if 'SMAP_L2_SM_SP' in o.key] rootpath = obs2[0].key.split('/')[0] + '/' for o in obs2: newkey = rootpath + os.path.split(o.key)[1] s3.Object(newkey).copy_from(CopySource=s3_bucket + '/' + o.key) obs3 = list(s3.objects.all()) obsD = [o for o in obs3 if 'ASOwusu' in o.key] for o in obsD: o.delete()
def test_get_data(self): """test get_data method""" # TODO: figure out how to mock S3 response with pytest.raises(botocore.auth.NoCredentialsError): node = S3(source=self.source, native_coordinates=self.coordinates, s3_bucket=self.bucket) output = node.eval(self.coordinates) assert isinstance(output, UnitsDataArray)
def test_s3_data(self): """test s3_data attribute and default""" # requires s3 bucket to be set with pytest.raises(ValueError): node = S3(source=self.source, return_type='file_handle') node.s3_data # path node = S3(source=self.source, s3_bucket=self.bucket) # TODO: figure out how to mock S3 response with pytest.raises(botocore.auth.NoCredentialsError): node.s3_data # file handle node = S3(source=self.source, s3_bucket=self.bucket, return_type='file_handle') # TODO: figure out how to mock S3 response with pytest.raises(botocore.auth.NoCredentialsError): node.s3_data
def test_traits(self): """ check each of the s3 traits """ S3(source=self.source, s3_bucket=self.bucket) with pytest.raises(TraitError): S3(source=self.source, s3_bucket=5) S3(source=self.source, node=Node()) with pytest.raises(TraitError): S3(source=self.source, node='not a node') S3(source=self.source, node_kwargs={}) with pytest.raises(TraitError): S3(source=self.source, node_kwargs=5) S3(source=self.source, node_class=DataSource) with pytest.raises(TraitError): S3(source=self.source, node_class=5) S3(source=self.source, s3_bucket='testbucket') with pytest.raises(TraitError): S3(source=self.source, s3_bucket=5) S3(source=self.source, return_type='path') with pytest.raises(TraitError): S3(source=self.source, return_type='notpath')
def test_init(self): """test basic init of class""" node = S3(source=self.source) assert isinstance(node, S3)