def metrics(): LOGGER.info('Metrics...') metrics = {} try: metrics = to_json(app_context().metrics_service.metrics()) except: e = sys.exc_info()[0] LOGGER.exception('Could not get metrics...') print(e) return response({'body': metrics, 'status_code': '200'})
def get_all(): LOGGER.debug('Get all data...') result = app_context().symptom_service.get() return response({ "status_code": '200', 'body': to_json({ "items": result['items'], "total": result['total'] }) })
def save(): LOGGER.info('Adding data...') _request = from_json(request.data.decode('utf-8')) result = app_context().symptom_service.save(_request) return response({ "status_code": '200', 'body': to_json({ "items": result['items'], "total": result['total'] }) })
def get(event, context=None): LOGGER.info(f'event = {event}') LOGGER.info(f'context={context}') query_params = event.get('queryStringParameters') id = None if query_params is not None and query_params.get('id') is not None: id = query_params['id'] result = app_context().symptom_service.get(id) return response({ "status_code": '200', 'body': to_json({ "items": result['items'], "total": result['total'] }) })
def add(event, context=None): LOGGER.info(f'event = {event}') LOGGER.info(f'context={context}') data = app_context().symptom_service.save(from_json(event['body'])) return response({"status_code": '200', 'body': to_json(data)})
def symptom_valid_request(symptom_valid): # from flask import request with mock.patch('flask.request'): flask.request.data.return_value = to_json(symptom_valid) yield ''
def test_symptom_add(self, symptom_valid, config_valid): response = app_aws.add({'body': to_json(symptom_valid)}) assert not from_json(response['body'])['contact'] assert '200' == response['statusCode']
def test_symptom_list_count(self, config_valid): response = app_aws.get({'body': to_json({})}) symptoms = json.loads(response['body']) print(symptoms) assert symptoms['total'] assert '200' == response['statusCode']