Projet

Général

Profil

0001-vivaticket-add-func-tests-29890.patch

Serghei Mihai (congés, retour 15/05), 23 janvier 2019 16:06

Télécharger (3,41 ko)

Voir les différences:

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
functests/vivaticket/README
1
Functional tests for the passerelle Vivaticket connector
2

  
3
Description
4
===========
5

  
6
This test suite will use the web API of a passerelle Vivaticket connector
7
to list available events, rooms, theme and create a booking.
8

  
9

  
10
Usage
11
=====
12

  
13
You will need a running passerelle instance, with a Vivaticket connector instance configured.
14
Suppose that the Vivaticket connector instance is listening here :
15

  
16
    http://127.0.0.1:8000/vivaticket/test
17

  
18
Then you would start the test suite with the following command:
19

  
20
    $ py.test -s --url=http://127.0.0.1:8000/vivaticket/test test_vivaticket.py
functests/vivaticket/conftest.py
1
import pytest
2

  
3

  
4
def pytest_addoption(parser):
5
    parser.addoption(
6
        "--url", help="Url of a passerelle Vivaticket connector instance")
7

  
8

  
9
@pytest.fixture(scope='session')
10
def conn(request):
11
    return request.config.getoption("--url")
functests/vivaticket/test_vivaticket.py
1
import pprint
2
import datetime
3
import requests
4
import random
5

  
6
def call_generic(conn, endpoint):
7
    print("%s \n" % endpoint)
8
    url = conn + '/%s' % endpoint
9
    resp = requests.get(url)
10
    resp.raise_for_status()
11
    res = resp.json()
12
    assert res['err'] == 0
13
    data = res['data']
14
    print('%s \n' % endpoint)
15
    pprint.pprint(data)
16
    print('\n')
17
    return data
18

  
19

  
20
def test_get_events(conn):
21
    call_generic(conn, 'events')
22

  
23
def test_get_rooms(conn):
24
    call_generic(conn, 'rooms')
25

  
26
def test_get_themes(conn):
27
    call_generic(conn, 'themes')
28

  
29
def test_book_event(conn):
30
    url = conn + '/book'
31
    payload = {'id': 'formid', 'email': 'foo@example.com',
32
               'datetime': datetime.datetime.now().strftime('%Y-%m-%dT%H:%M'),
33
               'room': '001', 'theme': 'A0001', 'quantity': 1
34
    }
35
    events = call_generic(conn, 'events')
36
    random.shuffle(events)
37
    payload['event'] = events[0]['id']
38
    rooms = call_generic(conn, 'rooms')
39
    random.shuffle(rooms)
40
    payload['room'] = rooms[0]['id']
41
    themes = call_generic(conn, 'themes')
42
    random.shuffle(themes)
43
    payload['theme'] = themes[0]['id']
44
    print "Creating booking with the following payload:\n%s" %  payload
45
    resp = requests.post(url, json=payload)
46
    resp.raise_for_status()
47
    res = resp.json()
48
    assert res['err'] == 0
49
    data = res['data']
50
    pprint.pprint(data)
51
    print('\n')
0
-