Exemple #1
0
 def post(self):
     """
     Creates a new event.
     """
     data = request.json
     auth_header = request.headers.get('Authtoken')
     user_id = get_id_form_token(auth_header)
     try:
         result_event = add_event(data, user_id)
     except Exception as e:
         api.abort(code=400, message="We had an error with your request, " + str(e))
     return result_event, 201
Exemple #2
0
def test_add_event_exception3():
    """
    GIVEN a JSON File with the start funding date being after end funding date
    WHEN trying to create an event
    THEN the system raises an exception which is catched
    """

    x = {
        "name": "Joan",
        "description": "description",
        "funding_start_date": "2030-11-14T18:21:35.433Z",
        "funding_end_date": "2021-11-14T18:21:35.433Z",
        "goal": 40,
        "event_start_date": "2040-11-14T18:21:35.433Z",
        "telephone": "612123123",
        "event_end_date": "2050-11-14T18:21:35.433Z",
        "location": "barcelona",
        "user_creator": 1
    }
    y = json.dumps(x)
    z = json.loads(y)
    with pytest.raises(Exception) as e:
        assert add_event(z)
    assert str(e.value) == "Start funding date  is after end funding date"
Exemple #3
0
def test_add_event_exception5():
    """
    GIVEN a JSON File with the event ending in the past
    WHEN trying to create an event
    THEN the system raises an exception which is catched
    """

    x = {
        "name": "Joan",
        "description": "description",
        "funding_start_date": "2022-11-14T18:21:35.433Z",
        "funding_end_date": "2023-11-14T18:21:35.433Z",
        "goal": 40,
        "event_start_date": "2025-11-14T18:21:35.433Z",
        "telephone": "612123123",
        "event_end_date": "2010-11-14T18:21:35.433Z",
        "location": "barcelona",
        "user_creator": 1
    }
    y = json.dumps(x)
    z = json.loads(y)
    with pytest.raises(Exception) as e:
        assert add_event(z)
    assert str(e.value) == "The event can not end in the past"