From a57cb9e615d73767b1cb70b892292ace774b41da Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Fri, 18 Jan 2019 15:11:59 +0100 Subject: [PATCH] vivaticket: add func tests (#29890) --- functests/vivaticket/README | 20 ++++++++++ functests/vivaticket/conftest.py | 11 ++++++ functests/vivaticket/test_vivaticket.py | 51 +++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 functests/vivaticket/README create mode 100644 functests/vivaticket/conftest.py create mode 100644 functests/vivaticket/test_vivaticket.py diff --git a/functests/vivaticket/README b/functests/vivaticket/README new file mode 100644 index 00000000..5d3644ab --- /dev/null +++ b/functests/vivaticket/README @@ -0,0 +1,20 @@ +Functional tests for the passerelle Vivaticket connector + +Description +=========== + +This test suite will use the web API of a passerelle Vivaticket connector +to list available events, rooms, theme and create a booking. + + +Usage +===== + +You will need a running passerelle instance, with a Vivaticket connector instance configured. +Suppose that the Vivaticket connector instance is listening here : + + http://127.0.0.1:8000/vivaticket/test + +Then you would start the test suite with the following command: + + $ py.test -s --url=http://127.0.0.1:8000/vivaticket/test test_vivaticket.py diff --git a/functests/vivaticket/conftest.py b/functests/vivaticket/conftest.py new file mode 100644 index 00000000..bf260bed --- /dev/null +++ b/functests/vivaticket/conftest.py @@ -0,0 +1,11 @@ +import pytest + + +def pytest_addoption(parser): + parser.addoption( + "--url", help="Url of a passerelle Vivaticket connector instance") + + +@pytest.fixture(scope='session') +def conn(request): + return request.config.getoption("--url") diff --git a/functests/vivaticket/test_vivaticket.py b/functests/vivaticket/test_vivaticket.py new file mode 100644 index 00000000..63adbeba --- /dev/null +++ b/functests/vivaticket/test_vivaticket.py @@ -0,0 +1,51 @@ +import pprint +import datetime +import requests +import random + +def call_generic(conn, endpoint): + print("%s \n" % endpoint) + url = conn + '/%s' % endpoint + resp = requests.get(url) + resp.raise_for_status() + res = resp.json() + assert res['err'] == 0 + data = res['data'] + print('%s \n' % endpoint) + pprint.pprint(data) + print('\n') + return data + + +def test_get_events(conn): + call_generic(conn, 'events') + +def test_get_rooms(conn): + call_generic(conn, 'rooms') + +def test_get_themes(conn): + call_generic(conn, 'themes') + +def test_book_event(conn): + url = conn + '/book' + payload = {'id': 'formid', 'email': 'foo@example.com', + 'datetime': datetime.datetime.now().strftime('%Y-%m-%dT%H:%M'), + 'room': '001', 'theme': 'A0001', 'quantity': 1 + } + events = call_generic(conn, 'events') + random.shuffle(events) + payload['event'] = events[0]['id'] + rooms = call_generic(conn, 'rooms') + random.shuffle(rooms) + payload['room'] = rooms[0]['id'] + themes = call_generic(conn, 'themes') + random.shuffle(themes) + payload['theme'] = themes[0]['id'] + print "Creating booking with the following payload:\n%s" % payload + resp = requests.post(url, json=payload) + resp.raise_for_status() + res = resp.json() + assert res['err'] == 0 + data = res['data'] + pprint.pprint(data) + print('\n')