def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2/payment') # TODO: update order_id when do separately testing self.order_id = '60ee8c056fdd17b16bb5b4c2' self.transaction_id = '280a24034bfb241c31b5a73c792c9d05df2b1f79bb98733c5358aeb909c27010'
class BackupTestCase(unittest.TestCase): def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2') @staticmethod def _subscribe(): HttpClient(f'/api/v2').put('/subscription/vault') @classmethod def setUpClass(cls): cls._subscribe() def test01_get_state(self): r = self.cli.get('/vault-deprecated/content') self.assertEqual(r.status_code, 200) @unittest.skip def test02_backup(self): self.backup(self.cli.get_backup_credential()) @unittest.skip def test03_restore(self): self.restore(self.cli.get_backup_credential()) def backup(self, credential): r = self.cli.post('/vault-deprecated/content?to=hive_node', body={'credential': credential}) self.assertEqual(r.status_code, 201) def restore(self, credential): r = self.cli.post('/vault-deprecated/content?from=hive_node', body={'credential': credential}) self.assertEqual(r.status_code, 201)
def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2/vault') self.folder_name = '' # root self.src_file_content = 'File Content: 12345678' self.dst_file_content = self.src_file_content self.src_file_name = 'src_file.txt' self.src_file_name2 = r'children/src_file2.txt' self.dst_file_name = 'dst_file'
def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2/vault') self.cli2 = HttpClient(f'/api/v2/vault', is_did2=True) self.file_name = 'ipfs-scripting/test.txt' self.file_content = 'File Content: 1234567890' # Owner's did and application did. self.did = self.cli.get_current_did() self.app_did = test_common.app_id
def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2/vault') self.folder_name = 'ipfs_children' self.src_file_content = 'File Content: 12345678' self.dst_file_content = self.src_file_content self.src_file_name = 'ipfs_src_file.txt' self.src_file_cache = f'{BASE_DIR}/cache/test.txt' self.src_file_name2 = r'ipfs_children/ipfs_src_file2.txt' self.dst_file_name = 'ipfs_dst_file.txt'
class PaymentTestCase(unittest.TestCase): def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2/payment') # TODO: update order_id when do separately testing self.order_id = '60ee8c056fdd17b16bb5b4c2' self.transaction_id = '280a24034bfb241c31b5a73c792c9d05df2b1f79bb98733c5358aeb909c27010' @staticmethod def _subscribe(): HttpClient(f'/api/v2').put('/subscription/vault') @classmethod def setUpClass(cls): cls._subscribe() def test01_get_version(self): response = self.cli.get('/version') self.assertEqual(response.status_code, 200) self.assertTrue('version' in response.json()) @unittest.skip def test02_place_order(self): response = self.cli.put('/order', body={ 'subscription': 'vault', 'pricing_name': 'Rookie' }) self.assertEqual(response.status_code, 200) self.assertTrue('order_id' in response.json()) self.order_id = response.json().get('order_id') @unittest.skip def test03_pay_order(self): response = self.cli.post(f'/order/{self.order_id}', body={'transaction_id': self.transaction_id}) self.assertEqual(response.status_code, 201) self.assertTrue('receipt_id' in response.json()) self.assertTrue('order_id' in response.json()) @unittest.skip def test04_get_orders(self): response = self.cli.get('/order?subscription=vault') self.assertEqual(response.status_code, 200) self.assertTrue('orders' in response.json()) @unittest.skip def test05_get_receipt(self): response = self.cli.get(f'/receipt?order_id={self.order_id}') self.assertEqual(response.status_code, 200) self.assertTrue('order_id' in response.json()) self.assertTrue('receipt_id' in response.json())
class AuthTestCase(unittest.TestCase): def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2') def test01_signin_invalid_parameter(self): response = self.cli.post(f'/did/signin', body=dict(), need_token=False) self.assertEqual(response.status_code, 400) def test02_auth_invalid_parameter(self): response = self.cli.post(f'/did/auth', body=dict(), need_token=False) self.assertEqual(response.status_code, 400)
class AboutTestCase(unittest.TestCase): def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2/about') def test01_get_version(self): response = self.cli.get(f'/version', need_token=False) self.assertEqual(response.status_code, 200) self.assertTrue('major' in response.json()) def test02_get_commit_id(self): response = self.cli.get(f'/commit_id', need_token=False) self.assertEqual(response.status_code, 200) self.assertTrue('commit_id' in response.json())
class IpfsScriptingTestCase(unittest.TestCase): collection_name = 'script_database' def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2/vault') self.cli2 = HttpClient(f'/api/v2/vault', is_did2=True) self.file_name = 'ipfs-scripting/test.txt' self.file_content = 'File Content: 1234567890' # Owner's did and application did. self.did = self.cli.get_current_did() self.app_did = test_common.app_id @staticmethod def _subscribe(): HttpClient(f'/api/v2').put('/subscription/vault') HttpClient(f'/api/v2', is_did2=True).put('/subscription/vault') def _delete_collection(self): HttpClient(f'/api/v2/vault').delete(f'/db/{self.collection_name}') @classmethod def setUpClass(cls): cls._subscribe() HttpClient(f'/api/v2/vault').put(f'/db/collections/{cls.collection_name}') @classmethod def tearDownClass(cls): pass def __register_script(self, script_name, body): response = self.cli.put(f'/scripting/{script_name}', body) self.assertEqual(response.status_code, 200) return json.loads(response.text) def __call_script(self, script_name, body=None, is_raw=False): if body is None: body = dict() body['context'] = { 'target_did': self.did, 'target_app_did': self.app_did, } response = self.cli2.patch(f'/scripting/{script_name}', body) self.assertEqual(response.status_code, 200) return response.text if is_raw else json.loads(response.text) def __set_and_call_script(self, name, set_data, run_data): self.__register_script(name, set_data) return self.__call_script(name, run_data) def __call_script_for_transaction_id(self, script_name, check_anonymous=False): response_body = self.__call_script(script_name, { "params": { "path": self.file_name } }) self.assertEqual(type(response_body), dict) self.assertTrue(script_name in response_body) self.assertEqual(type(response_body[script_name]), dict) self.assertTrue('transaction_id' in response_body[script_name]) if check_anonymous: self.assertTrue('anonymous_url' in response_body[script_name]) self.assertTrue(response_body[script_name]['anonymous_url']) return response_body[script_name]['transaction_id'] def test01_register_script_insert(self): self.__register_script('ipfs_database_insert', {"executable": { "output": True, "name": "database_insert", "type": "insert", "body": { "collection": self.collection_name, "document": { "author": "$params.author", "content": "$params.content" }, "options": { "ordered": True, "bypass_document_validation": False } } }}) def test02_call_script_insert(self): self.__call_script('ipfs_database_insert', { "params": { "author": "John", "content": "message" } }) def test03_call_script_url_insert(self): response = self.cli2.get(f'/scripting/ipfs_database_insert/{self.did}@{self.app_did}' '/%7B%22author%22%3A%22John2%22%2C%22content%22%3A%22message2%22%7D') self.assertEqual(response.status_code, 200) def test04_find_with_default_output_find(self): name = 'ipfs_database_find' col_filter = {'author': '$params.author'} body = self.__set_and_call_script(name, {'condition': { 'name': 'verify_user_permission', 'type': 'queryHasResults', 'body': { 'collection': self.collection_name, 'filter': col_filter } }, 'executable': { 'name': name, 'type': 'find', 'body': { 'collection': self.collection_name, 'filter': col_filter } }}, {'params': {'author': 'John'}}) self.assertIsNotNone(body) def test04_find_with_anonymous(self): name = 'ipfs_database_find2' col_filter = {'author': '$params.author'} script_body = { 'condition': { 'name': 'verify_user_permission', 'type': 'queryHasResults', 'body': { 'collection': self.collection_name, 'filter': col_filter } }, 'executable': { 'name': name, 'type': 'find', 'body': { 'collection': self.collection_name, 'filter': col_filter } }, "allowAnonymousUser": True, "allowAnonymousApp": True } run_body = {'params': { 'author': 'John' }} body = self.__set_and_call_script(name, script_body, run_body) self.assertIsNotNone(body) def test05_update(self): name = 'ipfs_database_update' col_filter = {'author': '$params.author'} body = self.__set_and_call_script(name, {'executable': { 'name': name, 'type': 'update', 'output': True, 'body': { 'collection': self.collection_name, 'filter': col_filter, 'update': { '$set': { 'author': '$params.author', 'content': '$params.content' } }, 'options': { 'bypass_document_validation': False, 'upsert': True } }}}, {'params': { 'author': 'John', 'content': 'message2' }}) self.assertIsNotNone(body) def test06_file_upload(self): name = 'ipfs_file_upload' self.__register_script(name, {"executable": { "output": True, "name": name, "type": "fileUpload", "body": { "path": "$params.path" } } }) response = self.cli2.put(f'/scripting/stream/{self.__call_script_for_transaction_id(name)}', self.file_content.encode(), is_json=False) self.assertEqual(response.status_code, 200) def test07_file_download(self): name = 'ipfs_file_download' self.__register_script(name, {"executable": { "output": True, "name": name, "type": "fileDownload", "body": { "path": "$params.path" } } }) response = self.cli2.get(f'/scripting/stream/{self.__call_script_for_transaction_id(name)}') self.assertEqual(response.status_code, 200) self.assertEqual(response.text, self.file_content) def test08_file_properties_without_params(self): name = 'ipfs_file_properties' body = self.__set_and_call_script(name, {'executable': { 'name': name, 'type': 'fileProperties', 'output': True, 'body': { 'path': self.file_name }}}, None) self.assertTrue(name in body) self.assertEqual(body[name]['size'], len(self.file_content)) def test09_file_hash(self): name = 'ipfs_file_hash' body = self.__set_and_call_script(name, {'executable': { 'name': name, 'type': 'fileHash', 'output': True, 'body': { 'path': '$params.path' }}}, {'params': { 'path': self.file_name}}) self.assertIsNotNone(body) def test10_get_anonymous_file(self): name = 'ipfs_get_anonymous_file' self.__register_script(name, {"executable": { "output": True, "name": name, "type": "fileDownload", "body": { "path": "$params.path" } }, "allowAnonymousUser": True, "allowAnonymousApp": True }) # This will keep transaction for anyone accessing the file by 'anonymous_url'. trans_id = self.__call_script_for_transaction_id(name, check_anonymous=True) # Execute normal download to remove the transaction. response = self.cli2.get(f'/scripting/stream/{trans_id}') self.assertEqual(response.status_code, 200) self.assertEqual(response.text, self.file_content) def test10_delete(self): name = 'ipfs_database_delete' col_filter = {'author': '$params.author'} body = self.__set_and_call_script(name, {'executable': { 'name': name, 'type': 'delete', 'output': True, 'body': { 'collection': self.collection_name, 'filter': col_filter }}}, {'params': {'author': 'John'}}) self.assertIsNotNone(body) def test11_delete_script(self): response = self.cli.delete('/scripting/ipfs_database_insert') self.assertEqual(response.status_code, 204) response = self.cli.delete('/scripting/ipfs_database_find') response = self.cli.delete('/scripting/ipfs_database_find2') response = self.cli.delete('/scripting/ipfs_database_update') response = self.cli.delete('/scripting/ipfs_database_delete') response = self.cli.delete('/scripting/ipfs_file_upload') response = self.cli.delete('/scripting/ipfs_file_download') response = self.cli.delete('/scripting/ipfs_file_properties') response = self.cli.delete('/scripting/ipfs_file_hash') response = self.cli.delete('/scripting/ipfs_get_anonymous_file') response = self.cli.delete(f'/files/{self.file_name}') self._delete_collection()
def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2/about')
def _subscribe_vault(): HttpClient(f'/api/v2').put('/subscription/vault')
class IpfsBackupTestCase(unittest.TestCase): def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2') self.backup_cli = HttpClient(f'/api/v2', is_backup_node=True) @staticmethod def _subscribe_vault(): HttpClient(f'/api/v2').put('/subscription/vault') @staticmethod def _unsubscribe_vault_on_backup_node(): HttpClient(f'/api/v2', is_backup_node=True).delete('/subscription/vault') @classmethod def setUpClass(cls): cls._subscribe_vault() def test01_subscribe(self): response = self.backup_cli.put('/subscription/backup') self.assertTrue(response.status_code in [200, 455]) def test02_get_info(self): response = self.backup_cli.get('/subscription/backup') self.assertEqual(response.status_code, 200) def test03_backup(self): r = self.cli.post('/vault/content?to=hive_node', body={'credential': self.cli.get_backup_credential()}) self.assertEqual(r.status_code, 201) time.sleep(10) def test03_backup_invalid_parameter(self): r = self.cli.post('/vault/content?to=hive_node') self.assertEqual(r.status_code, 400) @unittest.skip def test03_backup_force(self): r = self.cli.post('/vault/content?to=hive_node&is_force=true', body={'credential': self.cli.get_backup_credential()}) self.assertEqual(r.status_code, 201) def test04_state(self): r = self.cli.get('/vault/content') self.assertEqual(r.status_code, 200) def test05_restore(self): r = self.cli.post('/vault/content?from=hive_node', body={'credential': self.cli.get_backup_credential()}) self.assertEqual(r.status_code, 201) time.sleep(10) def test05_restore_invalid_parameter(self): r = self.cli.post('/vault/content?from=hive_node') self.assertEqual(r.status_code, 400) @unittest.skip def test05_restore_force(self): r = self.cli.post('/vault/content?from=hive_node&is_force=true', body={'credential': self.cli.get_backup_credential()}) self.assertEqual(r.status_code, 201) @unittest.skip def test06_promotion(self): # PREPARE: backup and remove the vault for local test. self.__class__._unsubscribe_vault_on_backup_node() # do promotion. r = self.backup_cli.post('/backup/promotion') self.assertEqual(r.status_code, 201) # check the vault state. response = self.backup_cli.get('/subscription/vault') self.assertEqual(response.status_code, 200) @unittest.skip def test07_unsubscribe(self): response = self.backup_cli.delete('/subscription/backup') self.assertEqual(response.status_code, 204) self.__class__._unsubscribe_vault_on_backup_node()
def _delete_collection(self): HttpClient(f'/api/v2/vault').delete(f'/db/{self.collection_name}')
class FilesTestCase(unittest.TestCase): def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2/vault') self.folder_name = '' # root self.src_file_content = 'File Content: 12345678' self.dst_file_content = self.src_file_content self.src_file_name = 'src_file.txt' self.src_file_name2 = r'children/src_file2.txt' self.dst_file_name = 'dst_file' @staticmethod def _subscribe(): HttpClient(f'/api/v2').put('/subscription/vault') @classmethod def setUpClass(cls): cls._subscribe() def test01_upload_file(self): response = self.cli.put(f'/files-deprecated/{self.src_file_name}', self.src_file_content.encode(), is_json=False) self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('name'), self.src_file_name) self.__check_remote_file_exist(self.src_file_name) def test01_upload_file2(self): response = self.cli.put(f'/files-deprecated/{self.src_file_name2}', self.src_file_content.encode(), is_json=False) self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('name'), self.src_file_name2) self.__check_remote_file_exist(self.src_file_name2) def test02_download_file(self): response = self.cli.get(f'/files-deprecated/{self.src_file_name}') self.assertEqual(response.status_code, 200) self.assertEqual(response.text, self.src_file_content) def test03_move_file(self): response = self.cli.patch( f'/files-deprecated/{self.src_file_name}?to={self.dst_file_name}') self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('name'), self.dst_file_name) self.__check_remote_file_exist(self.dst_file_name) def test04_copy_file(self): response = self.cli.put( f'/files-deprecated/{self.dst_file_name}?dest={self.src_file_name}' ) self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('name'), self.src_file_name) self.__check_remote_file_exist(self.dst_file_name) self.__check_remote_file_exist(self.src_file_name) def test05_list_folder(self): response = self.cli.get( f'/files-deprecated/{self.folder_name}?comp=children') self.assertEqual(response.status_code, 200) self.assertTrue('value' in response.json()) self.assertEqual(type(response.json()['value']), list) def test06_get_properties(self): self.__check_remote_file_exist(self.src_file_name) def test07_get_hash(self): response = self.cli.get( f'/files-deprecated/{self.src_file_name}?comp=hash') self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('name'), self.src_file_name) def test08_delete_file(self): self.__delete_file(self.src_file_name) self.__delete_file(self.src_file_name2) self.__delete_file(self.dst_file_name) def __check_remote_file_exist(self, file_name): response = self.cli.get(f'/files-deprecated/{file_name}?comp=metadata') self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('name'), file_name) return response.json() def __delete_file(self, file_name): response = self.cli.delete(f'/files-deprecated/{file_name}') self.assertEqual(response.status_code, 204)
def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2/vault') self.collection_name = 'test_collection'
class DatabaseTestCase(unittest.TestCase): def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2/vault') self.collection_name = 'test_collection' @staticmethod def _subscribe(): HttpClient(f'/api/v2').put('/subscription/vault') @classmethod def setUpClass(cls): cls._subscribe() def test01_create_collection(self): response = self.cli.put(f'/db/collections/{self.collection_name}') self.assertTrue(response.status_code in [200, 455]) if response.status_code == 200: self.assertEqual(response.json().get('name'), self.collection_name) def test02_insert_document(self): response = self.cli.post(f'/db/collection/{self.collection_name}', body={ "document": [{ "author": "john doe1", "title": "Eve for Dummies1" }, { "author": "john doe1", "title": "Eve for Dummies1" }, { "author": "john doe2", "title": "Eve for Dummies2" }, { "author": "john doe2", "title": "Eve for Dummies2" }], "options": { "bypass_document_validation": False, "ordered": True } }) self.assertEqual(response.status_code, 201) self.assertEqual(len(response.json().get('inserted_ids')), 4) def test02_insert_document_invalid_parameter(self): response = self.cli.post(f'/db/collection/{self.collection_name}') self.assertEqual(response.status_code, 400) def test03_update_document(self): response = self.cli.patch(f'/db/collection/{self.collection_name}', body={ "filter": { "author": "john doe1", }, "update": { "$set": { "author": "john doe1_1", "title": "Eve for Dummies1_1" } }, "options": { "upsert": True, "bypass_document_validation": False } }) self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('matched_count'), 2) def test03_update_document_invalid_parameter(self): response = self.cli.patch(f'/db/collection/{self.collection_name}') self.assertEqual(response.status_code, 400) def test03_update_one_document(self): response = self.cli.patch( f'/db/collection/{self.collection_name}?updateone=true', body={ "filter": { "author": "john doe1_1", }, "update": { "$set": { "author": "john doe1_2", "title": "Eve for Dummies1_2" } }, "options": { "upsert": True, "bypass_document_validation": False } }) self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('matched_count'), 1) def test04_count_document(self): response = self.cli.post( f'/db/collection/{self.collection_name}?op=count', body={ "filter": { "author": "john doe2", }, "options": { "skip": 0, "limit": 10, "maxTimeMS": 1000000000 } }) self.assertEqual(response.status_code, 201) self.assertEqual(response.json().get('count'), 2) def test04_count_document_invalid_parameter(self): response = self.cli.post( f'/db/collection/{self.collection_name}?op=count') self.assertEqual(response.status_code, 400) def test05_find_document(self): response = self.cli.get(f'/db/{self.collection_name}' + '?filter={"author":"john doe2"}&skip=0') self.assertEqual(response.status_code, 200) self.assertTrue('items' in response.json()) def test05_find_document_invalid_parameter(self): response = self.cli.get(f'/db/{self.collection_name}' + '?filter=&skip=') self.assertEqual(response.status_code, 400) def test06_query_document(self): response = self.cli.post(f'/db/query', body={ "collection": self.collection_name, "filter": { "author": "john doe2", }, "options": { "skip": 0, "limit": 3, "projection": { "_id": False }, 'sort': [('_id', pymongo.DESCENDING)], "allow_partial_results": False, "return_key": False, "show_record_id": False, "batch_size": 0 } }) self.assertEqual(response.status_code, 201) self.assertTrue('items' in response.json()) def test06_query_document_invalid_parameter(self): response = self.cli.post(f'/db/query') self.assertEqual(response.status_code, 400) def test07_delete_one_document(self): response = self.cli.delete( f'/db/collection/{self.collection_name}?deleteone=true', body={"filter": { "author": "john doe1_2", }}, is_json=True) self.assertEqual(response.status_code, 204) def test07_delete_one_document_invalid_parameter(self): response = self.cli.delete( f'/db/collection/{self.collection_name}?deleteone=true') self.assertEqual(response.status_code, 400) def test07_delete_document(self): response = self.cli.delete(f'/db/collection/{self.collection_name}', body={"filter": { "author": "john doe2", }}, is_json=True) self.assertEqual(response.status_code, 204) def test08_delete_collection(self): self.__delete_collection() def __delete_collection(self): response = self.cli.delete(f'/db/{self.collection_name}') self.assertEqual(response.status_code, 204)
def _subscribe(): HttpClient(f'/api/v2').put('/subscription/vault') HttpClient(f'/api/v2', is_did2=True).put('/subscription/vault')
# -*- coding: utf-8 -*- from tests.utils.http_client import HttpClient bk_app_code = 'esb_test' bk_app_secret = 'xxx' host = 'http://127.0.0.1:8000/' http_client = HttpClient( host=host, bk_app_code=bk_app_code, bk_app_secret=bk_app_secret, )
def setUpClass(cls): cls._subscribe() HttpClient(f'/api/v2/vault').put(f'/db/collections/{cls.collection_name}')
def _create_collection(): HttpClient(f'/api/v2/vault').put(f'/db/collections/{ScriptingTestCase.collection_name}')
def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2') self.backup_cli = HttpClient(f'/api/v2', is_backup_node=True)
def _delete_collection(): HttpClient(f'/api/v2/vault').delete(f'/db/{ScriptingTestCase.collection_name}')
def _unsubscribe_vault_on_backup_node(): HttpClient(f'/api/v2', is_backup_node=True).delete('/subscription/vault')
class IpfsFilesTestCase(unittest.TestCase): def __init__(self, method_name='runTest'): super().__init__(method_name) init_test() self.cli = HttpClient(f'/api/v2/vault') self.folder_name = 'ipfs_children' self.src_file_content = 'File Content: 12345678' self.dst_file_content = self.src_file_content self.src_file_name = 'ipfs_src_file.txt' self.src_file_cache = f'{BASE_DIR}/cache/test.txt' self.src_file_name2 = r'ipfs_children/ipfs_src_file2.txt' self.dst_file_name = 'ipfs_dst_file.txt' @staticmethod def _subscribe(): HttpClient(f'/api/v2').put('/subscription/vault') @classmethod def setUpClass(cls): cls._subscribe() def test01_upload_file(self): with open(self.src_file_cache, 'rb') as f: response = self.cli.put(f'/files/{self.src_file_name}', f.read(), is_json=False) self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('name'), self.src_file_name) self.__check_remote_file_exist(self.src_file_name) def test01_upload_file2(self): response = self.cli.put(f'/files/{self.src_file_name2}', self.src_file_content.encode(), is_json=False) self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('name'), self.src_file_name2) self.__check_remote_file_exist(self.src_file_name2) def test01_upload_file_invalid_parameter(self): response = self.cli.put(f'/files/', self.src_file_content.encode(), is_json=False) self.assertEqual(response.status_code, 405) def test02_download_file(self): response = self.cli.get(f'/files/{self.src_file_name}') self.assertEqual(response.status_code, 200) self.assertEqual(response.text, self.src_file_content) def test02_download_file_invalid_parameter(self): response = self.cli.get(f'/files/') self.assertEqual(response.status_code, 400) def test03_move_file(self): response = self.cli.patch(f'/files/{self.src_file_name}?to={self.dst_file_name}') self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('name'), self.dst_file_name) self.__check_remote_file_exist(self.dst_file_name) def test03_move_file_invalid_parameter(self): response = self.cli.patch(f'/files/{self.src_file_name}?to=') self.assertEqual(response.status_code, 400) def test04_copy_file(self): response = self.cli.put(f'/files/{self.dst_file_name}?dest={self.src_file_name}') self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('name'), self.src_file_name) self.__check_remote_file_exist(self.dst_file_name) self.__check_remote_file_exist(self.src_file_name) def test04_copy_file_invalid_parameter(self): response = self.cli.put(f'/files/{self.dst_file_name}?dest={self.dst_file_name}') self.assertEqual(response.status_code, 400) def test05_list_folder(self): response = self.cli.get(f'/files/{self.folder_name}?comp=children') self.assertEqual(response.status_code, 200) self.assertTrue('value' in response.json()) self.assertEqual(type(response.json()['value']), list) self.assertEqual(len(response.json()['value']), 1) self.assertEqual(response.json()['value'][0]['name'], self.src_file_name2) def test06_get_properties(self): self.__check_remote_file_exist(self.src_file_name) def test06_get_properties_invalid_parameter(self): response = self.cli.get(f'/files/?comp=metadata') self.assertEqual(response.status_code, 400) def test07_get_hash(self): response = self.cli.get(f'/files/{self.src_file_name}?comp=hash') self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('name'), self.src_file_name) def test07_get_hash_invalid_parameter(self): response = self.cli.get(f'/files/?comp=hash') self.assertEqual(response.status_code, 400) def test08_delete_file(self): self.__delete_file(self.src_file_name) self.__delete_file(self.src_file_name2) self.__delete_file(self.dst_file_name) def test08_delete_file_invalid_parameter(self): response = self.cli.delete(f'/files/') self.assertEqual(response.status_code, 405) def __check_remote_file_exist(self, file_name): response = self.cli.get(f'/files/{file_name}?comp=metadata') self.assertEqual(response.status_code, 200) self.assertEqual(response.json().get('name'), file_name) return response.json() def __delete_file(self, file_name): response = self.cli.delete(f'/files/{file_name}') self.assertEqual(response.status_code, 204)