def setup_class(self): start = datetime.datetime.now() end = start + datetime.timedelta(hours=1) period_args = {'start': start, 'end': end} period = domain.Period(**period_args) event_args = { 'id': 1, 'name': 'test_name', 'period': period, 'description': 'test_desc', 'items': [] } event = domain.Event(**event_args) events.append(event)
def post(self): try: period_args = { # datetime.datetime parse 'start': dateutil.parser.parse(request.json['start']), 'end': dateutil.parser.parse(request.json['end']), } period = domain.Period(**period_args) event_args = { 'name': request.json['name'], 'period': period, } event_args['id'] = len(events) + 1 event_args['items'] = [] # non-required parameter keys event_option_keys = [ 'description', 'anonymous', 'created_at', 'updated_at', 'deleted_at' ] # set non-required parameter to event_args. for key in event_option_keys: if key in request.json: event_args[key] = request.json[key] event = domain.Event(**event_args) events.append(event) except Exception as e: error_message = 'create_event fail' logger.error('%s %s' % (error_message, e)) response = {'error_message': error_message} return make_response(jsonify(response), 400) response = { 'id': event.id, 'name': event.name, 'start': event.period.start, 'end': event.period.end, 'description': event.description } return make_response(jsonify(response), 201)
import datetime import json import pytest from savoten import domain from savoten.app import app from savoten.handler.event_api import event_repository start = datetime.datetime.now() end = start + datetime.timedelta(hours=1) period_args = {'start': start, 'end': end} period = domain.Period(**period_args) event_args = { 'name': 'test_name', 'period': period, 'description': 'test_desc', 'items': [] } class TestGetEvents: def setup_method(self): self.client = app.test_client() @pytest.mark.parametrize('uri, expect_status_code', [('/api/v1/events', 200)]) def test_success_case(self, uri, expect_status_code): response = self.client.get(uri) assert (response.status_code == expect_status_code)