Skip to content

Commit

Permalink
Update test M3 client to handle number of purged entries in cache pur…
Browse files Browse the repository at this point in the history
…ge response.
  • Loading branch information
davidjwbbc committed Jan 26, 2023
1 parent b15e2b8 commit 8b19352
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 8 additions & 1 deletion tests/m3_client_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,7 +97,7 @@ def main():
{'flags': ['--content-hosting-configuration','add'], 'fn': m3_client.addContentHostingConfigurationFromJsonFile, 'args': ['<provisioning-session-id>', '<content-hosting-configuration-json-file>'], 'format': bool_result},
{'flags': ['--content-hosting-configuration','update'], 'fn': m3_client.updateContentHostingConfigurationFromJsonFile, 'args': ['<provisioning-session-id>', '<content-hosting-configuration-json-file>'], 'format': bool_result},
{'flags': ['--content-hosting-configuration','delete'], 'fn': m3_client.deleteContentHostingConfiguration, 'args': ['<provisioning-session-id>'], 'format': bool_result},
{'flags': ['--content-hosting-configuration','purge'], 'fn': m3_client.purgeContentHostingCache, 'args': ['<provisioning-session-id>'], 'kwargs': [('pattern','<pattern>')], 'format': bool_result},
{'flags': ['--content-hosting-configuration','purge'], 'fn': m3_client.purgeContentHostingCache, 'args': ['<provisioning-session-id>'], 'kwargs': [('pattern','<pattern>')], 'format': purge_result},
{'flags': ['--content-hosting-configuration'], 'fn': m3_client.listContentHostingConfigurations, 'args': [], 'format': chc_list_result},
]

Expand Down
8 changes: 5 additions & 3 deletions tests/test_m3_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8b19352

Please sign in to comment.