Ejemplo n.º 1
0
 def test_unauthorized_download(self):
     """Test a download to the wrong token ID."""
     token_id = 'url:user:name'
     cache_id = str(uuid4())
     minio.create_placeholder(cache_id, token_id)
     tmp_dir = tempfile.mkdtemp()
     with self.assertRaises(exceptions.UnauthorizedAccess):
         minio.download_cache(cache_id, token_id + 'x', tmp_dir)
     shutil.rmtree(tmp_dir)
Ejemplo n.º 2
0
 def test_missing_cache_download(self):
     """Test a download to a missing cache ID."""
     token_id = 'url:user:name'
     cache_id = str(uuid4())
     minio.create_placeholder(cache_id, token_id)
     tmp_dir = tempfile.mkdtemp()
     with self.assertRaises(NoSuchKey):
         minio.download_cache(cache_id + 'x', token_id, tmp_dir)
     shutil.rmtree(tmp_dir)
Ejemplo n.º 3
0
 def test_cache_delete(self):
     """Test a valid file deletion."""
     token_id = 'url:user:name'
     cache_id = str(uuid4())
     minio.create_placeholder(cache_id, token_id)
     minio.delete_cache(cache_id, token_id)
     tmp_dir = tempfile.mkdtemp()
     with self.assertRaises(NoSuchKey):
         minio.download_cache(cache_id, token_id, tmp_dir)
     shutil.rmtree(tmp_dir)
Ejemplo n.º 4
0
 def test_placeholder_creation(self):
     """Test the creation of a cache file placeholder."""
     token_id = 'url:user:name'
     cache_id = str(uuid4())
     minio.create_placeholder(cache_id, token_id)
     minio.authorize_access(cache_id, token_id)
     tmp_dir = tempfile.mkdtemp()
     with self.assertRaises(exceptions.MissingCache):
         minio.download_cache(cache_id, token_id, tmp_dir)
     save_path = os.path.join(tmp_dir, 'x')
     minio.minio_client.fget_object(minio.Config.minio_bucket_name,
                                    cache_id, save_path)
     with open(save_path, 'rb') as fd:
         contents = fd.read()
         self.assertEqual(contents, b'')
     shutil.rmtree(tmp_dir)
     metadata = minio.get_metadata(cache_id)
     self.assertTrue(int(metadata['expiration']) > time.time())
     self.assertEqual(metadata['filename'], 'placeholder')
     self.assertEqual(metadata['token_id'], token_id)
Ejemplo n.º 5
0
 def test_cache_upload(self):
     """Test a valid file upload to a cache ID."""
     token_id = 'url:user:name'
     cache_id = str(uuid4())
     minio.create_placeholder(cache_id, token_id)
     file_storage = self.make_test_file_storage(cache_id, token_id)
     minio.upload_cache(cache_id, token_id, file_storage)
     file_storage.stream.close()
     metadata = minio.get_metadata(cache_id)
     self.assertTrue(
         int(metadata['expiration']) > time.time(),
         'Expiration is in the future')
     self.assertEqual(metadata['filename'], file_storage.filename,
                      'Correct filename is saved in the metadata')
     self.assertEqual(metadata['token_id'], token_id,
                      'Correct token ID is saved in the metadata')
     tmp_dir = tempfile.mkdtemp()
     save_path = minio.download_cache(cache_id, token_id, tmp_dir)
     with open(save_path, 'rb') as fd:
         saved_contents = fd.read().decode('utf-8')
         self.assertEqual(saved_contents, 'contents',
                          'Correct file contents uploaded')