Projet

Général

Profil

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

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

Télécharger (3,04 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 | 41 +++++++++++++++++++++++++
 3 files changed, 72 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

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

  
18

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

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

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

  
28
def test_book_event(conn):
29
    url = conn + '/book'
30
    payload = {'id': 'formid', 'email': 'foo@example.com',
31
               'datetime': datetime.datetime.now().strftime('%Y-%m-%dT%H:%M'),
32
               'event': '01', 'room': '001', 'theme': 'A0001', 'quantity': 1
33
    }
34
    resp = requests.post(url, json=payload)
35
    resp.raise_for_status()
36
    res = resp.json()
37
    assert res['err'] == 0
38
    data = res['data']
39
    pprint.pprint(data)
40
    print('\n')
41
    return data
0
-