def test_update_api_stats(self): """ python -m unittest -v tests.test_api_stats.api_stats_tests.test_update_api_stats """ # Arrange from modules.api_stats import get_api_stats, update_api_stats # Act prev_count = get_api_stats("TEST_STAT_NAME") update_api_stats("TEST_STAT_NAME") count = get_api_stats("TEST_STAT_NAME") # Assert self.assertEqual(prev_count, 0) self.assertEqual(count, prev_count + 1)
def negative_json_response(method_name): json_data = { 'name' : method_name, 'result': 'NG', 'jwt' : None } update_api_stats(method_name) logging.debug(get_api_stats(method_name)) return json.dumps(json_data)
def test_get_api_stats(self): """ python -m unittest -v tests.test_api_stats.api_stats_tests.test_get_api_stats """ # Arrange from modules.api_stats import get_api_stats # Act count = get_api_stats("TEST_STAT_NAME") # Assert self.assertEqual(count, 0)
def json_response(request, json_data=None, ex=None): request_path = request.path if json_data is None: json_data = { 'request.path' : request_path, 'result': 'NG', 'exception' : "Unknown error." if ex is None else ex.description } update_api_stats(request_path) logging.debug(get_api_stats(request_path)) return json.dumps(json_data)
def test_have_api_stats(self): """ python -m unittest -v tests.test_api_stats.api_stats_tests.test_have_api_stats """ # Arrange from modules.api_stats import have_api_stats, get_api_stats, update_api_stats # Act stat_exists = have_api_stats("TEST_NEW_STAT_NAME") update_api_stats("TEST_NEW_STAT_NAME") count = get_api_stats("TEST_NEW_STAT_NAME") # Assert self.assertEqual(stat_exists, False) self.assertEqual(count, 1)
def api_common_utc_get(errorMessages=None): ''' API to return server time in UTC ''' logging.debug("[BEGIN] api_common_utc_get()") json_data = { 'name': '/api/common/utc', 'result': 'success', 'datetime': str(datetime.utcnow()) } update_api_stats('/api/common/utc') logging.debug(get_api_stats('/api/common/utc')) logging.debug("[END] api_common_utc_get()") return json.dumps(json_data)