def test_find_by_account_id(session): """Assert that the account search history list first item contains all expected elements.""" history = SearchClient.find_all_by_account_id('PS12345') # print(history) assert history assert history[0]['searchId'] assert history[0]['searchDateTime'] assert history[0]['totalResultsSize'] assert history[0]['returnedResultsSize'] assert history[0]['exactResultsSize'] assert history[0]['selectedResultsSize'] assert history[0]['searchQuery'] assert len(history) >= 1
def get(): """Get account search history.""" try: # Quick check: must have an account ID. account_id = resource_utils.get_account_id(request) if account_id is None: return resource_utils.account_required_response() # Verify request JWT and account ID if not authorized(account_id, jwt): return resource_utils.unauthorized_error_response(account_id) # Try to fetch search history by account id. # No results throws a not found business exception. current_app.logger.info( f'Fetching search history for {account_id}.') history = SearchClient.find_all_by_account_id(account_id) return jsonify(history), HTTPStatus.OK except BusinessException as exception: return resource_utils.business_exception_response(exception) except Exception as default_exception: # noqa: B902; return nicer default error return resource_utils.default_exception_response(default_exception)
def test_find_by_account_id_no_result(session): """Assert that the find search history by invalid account ID returns the expected result.""" history = SearchClient.find_all_by_account_id('XXXX345') # check assert len(history) == 0