vivaticket: add func tests (#29890)

This commit is contained in:
Serghei Mihai 2019-01-18 15:11:59 +01:00
parent ef7850a5dd
commit a57cb9e615
3 changed files with 82 additions and 0 deletions

View File

@ -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

View File

@ -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")

View File

@ -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')