mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Endpoint for recording events in api.
An event has an id, a type and a blob of json attached.
This commit is contained in:
19
tests/app/dao/test_events_dao.py
Normal file
19
tests/app/dao/test_events_dao.py
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
from app.dao.events_dao import dao_create_event
|
||||
|
||||
from app.models import Event
|
||||
|
||||
|
||||
def test_create_event(notify_db, notify_db_session):
|
||||
assert Event.query.count() == 0
|
||||
data = {
|
||||
'event_type': 'sucessful_login',
|
||||
'data': {'something': 'random', 'in_fact': 'could be anything'}
|
||||
}
|
||||
|
||||
event = Event(**data)
|
||||
dao_create_event(event)
|
||||
|
||||
assert Event.query.count() == 1
|
||||
event_from_db = Event.query.first()
|
||||
assert event == event_from_db
|
||||
0
tests/app/events/__init__.py
Normal file
0
tests/app/events/__init__.py
Normal file
26
tests/app/events/test_rest.py
Normal file
26
tests/app/events/test_rest.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import json
|
||||
from tests import create_authorization_header
|
||||
|
||||
|
||||
def test_create_event(notify_api):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = {
|
||||
'event_type': 'sucessful_login',
|
||||
'data': {'something': 'random', 'in_fact': 'could be anything'}
|
||||
}
|
||||
path = '/events'
|
||||
auth_header = create_authorization_header(
|
||||
path=path,
|
||||
method='POST',
|
||||
request_body=json.dumps(data))
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
response = client.post(
|
||||
path,
|
||||
data=json.dumps(data),
|
||||
headers=headers)
|
||||
assert response.status_code == 201
|
||||
resp_json = json.loads(response.get_data(as_text=True))['data']
|
||||
assert resp_json['event_type'] == data['event_type']
|
||||
assert resp_json['data']['something'] == data['data']['something']
|
||||
assert resp_json['data']['in_fact'] == data['data']['in_fact']
|
||||
Reference in New Issue
Block a user