From 8b193521f425bfee99da693ef33ac1d1b1eee9e1 Mon Sep 17 00:00:00 2001 From: David Waring Date: Thu, 26 Jan 2023 16:01:54 +0000 Subject: [PATCH] Update test M3 client to handle number of purged entries in cache purge response. --- tests/m3_client_cli.py | 9 ++++++++- tests/test_m3_client/client.py | 8 +++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/m3_client_cli.py b/tests/m3_client_cli.py index eedba15..ab3c11a 100755 --- a/tests/m3_client_cli.py +++ b/tests/m3_client_cli.py @@ -63,6 +63,13 @@ def bool_result(result: bool) -> int: print("No change") return 0 +def purge_result(result: int) -> int: + if result == 1: + print('Purged 1 cache entry') + else: + print('Purged %i cache entries'%result) + return 0 + def certificates_list_result(result: list) -> int: print('Known certificates:\n '+'\n '.join(result)) return 0 @@ -90,7 +97,7 @@ def main(): {'flags': ['--content-hosting-configuration','add'], 'fn': m3_client.addContentHostingConfigurationFromJsonFile, 'args': ['', ''], 'format': bool_result}, {'flags': ['--content-hosting-configuration','update'], 'fn': m3_client.updateContentHostingConfigurationFromJsonFile, 'args': ['', ''], 'format': bool_result}, {'flags': ['--content-hosting-configuration','delete'], 'fn': m3_client.deleteContentHostingConfiguration, 'args': [''], 'format': bool_result}, - {'flags': ['--content-hosting-configuration','purge'], 'fn': m3_client.purgeContentHostingCache, 'args': [''], 'kwargs': [('pattern','')], 'format': bool_result}, + {'flags': ['--content-hosting-configuration','purge'], 'fn': m3_client.purgeContentHostingCache, 'args': [''], 'kwargs': [('pattern','')], 'format': purge_result}, {'flags': ['--content-hosting-configuration'], 'fn': m3_client.listContentHostingConfigurations, 'args': [], 'format': chc_list_result}, ] diff --git a/tests/test_m3_client/client.py b/tests/test_m3_client/client.py index a7831ba..9471d72 100755 --- a/tests/test_m3_client/client.py +++ b/tests/test_m3_client/client.py @@ -406,13 +406,15 @@ async def listContentHostingConfigurations(self) -> List[str]: else: raise M3ServerException(msg, status_code=result['status_code'], problem_detail=pd) - async def purgeContentHostingCache(self, provisioning_session_id: str, pattern: Optional[str] = None) -> bool: + async def purgeContentHostingCache(self, provisioning_session_id: str, pattern: Optional[str] = None) -> int: body = None if pattern is not None: body = bytes('pattern=%s'%pattern, 'utf-8') result = await self.__do_request('POST', '/content-hosting-configurations/'+provisioning_session_id+'/purge', body, 'application/x-www-form-urlencoded') - if result['status_code'] == 204: - return True + if result['status_code'] == 200: + return int(result['body']) + elif result['status_code'] == 204: + return 0 elif result['status_code'] == 404: raise M3ClientException('ContentHostingConfiguration not found!', status_code=result['status_code']) elif result['status_code'] == 413: