Project

General

Profile

0007-tests-fix-vivaticket-tests-inconsistencies-30458.patch

Benjamin Dauvergne, 08 Feb 2019 08:43 AM

Download (5.43 KB)

View differences:

Subject: [PATCH 07/13] tests: fix vivaticket tests inconsistencies (#30458)

 tests/test_vivaticket.py | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
tests/test_vivaticket.py
219 219
    assert mocked_post.call_count == 3
220 220

  
221 221

  
222
@mock.patch('passerelle.utils.Request.post')
222 223
@mock.patch('passerelle.utils.Request.get')
223
def test_get_events(mocked_get, app, connector):
224
def test_get_events(mocked_get, mocked_post, app, connector):
224 225
    mocked_get.return_value = utils.FakedResponse(content=EVENTS_RESPONSE, status_code=200)
226
    mocked_post.return_value = utils.FakedResponse(content=KEY_RESPONSE, status_code=200)
225 227
    result = utils.endpoint_get('/vivaticket/test/events', app, connector, 'events')
228
    assert mocked_post.call_count == 1
226 229
    assert mocked_get.call_args[1]['params']['key'] == "86569D0CA1B1CBEF8D77DD5BDC9F5CBAE5C99074"
227 230
    assert 'data' in result.json
228 231
    for item in result.json['data']:
......
236 239
    mocked_get.return_value = utils.FakedResponse(content=EVENTS_RESPONSE, status_code=401)
237 240
    mocked_post.return_value = utils.FakedResponse(content=KEY_RESPONSE, status_code=200)
238 241
    utils.endpoint_get('/vivaticket/test/events', app, connector, 'events')
239
    assert mocked_post.call_count == 1
242
    assert mocked_post.call_count == 2
240 243

  
241 244

  
245
@mock.patch('passerelle.utils.Request.post')
242 246
@mock.patch('passerelle.utils.Request.get')
243
def test_get_rooms(mocked_get, app, connector):
247
def test_get_rooms(mocked_get, mocked_post, app, connector):
244 248
    mocked_get.return_value = utils.FakedResponse(content=ROOMS_RESPONSE, status_code=200)
249
    mocked_post.return_value = utils.FakedResponse(content=KEY_RESPONSE, status_code=200)
245 250
    result = utils.endpoint_get('/vivaticket/test/rooms', app, connector, 'rooms')
246 251
    assert mocked_get.call_args[1]['params']['key'] == '86569D0CA1B1CBEF8D77DD5BDC9F5CBAE5C99074'
247 252
    assert 'data' in result.json
......
252 257
    assert mocked_get.call_args[1]['params']['eventCategory'] == '02'
253 258

  
254 259

  
260
@mock.patch('passerelle.utils.Request.post')
255 261
@mock.patch('passerelle.utils.Request.get')
256
def test_get_themes(mocked_get, app, connector):
262
def test_get_themes(mocked_get, mocked_post, app, connector):
257 263
    mocked_get.return_value = utils.FakedResponse(content=ROOMS_RESPONSE, status_code=200)
264
    mocked_post.return_value = utils.FakedResponse(content=KEY_RESPONSE, status_code=200)
258 265
    result = utils.endpoint_get('/vivaticket/test/themes', app, connector, 'themes')
259 266
    assert mocked_get.call_args[1]['params']['key'] == '86569D0CA1B1CBEF8D77DD5BDC9F5CBAE5C99074'
260 267
    assert 'data' in result.json
......
269 276
@mock.patch('passerelle.utils.Request.get')
270 277
def test_get_or_create_contact(mocked_get, mocked_post, app, connector):
271 278
    mocked_get.return_value = utils.FakedResponse(content=CONTACT_RESPONSE, ok=True)
279
    mocked_post.return_value = utils.FakedResponse(content=KEY_RESPONSE, status_code=200)
272 280
    assert connector.get_or_create_contact('foo@example.com') == {'InternalCode': '0000000273'}
273 281
    mocked_get.return_value = utils.FakedResponse(content=CONTACT_RESPONSE, ok=False)
274 282
    mocked_post.return_value = utils.FakedResponse(
......
280 288
    assert mocked_post.call_args[1]['json']['Contact']['ExternalCode'] == 'b48def645758b95537d4'
281 289

  
282 290

  
291
@mock.patch('passerelle.utils.Request.post')
283 292
@mock.patch('passerelle.utils.Request.put')
284 293
@mock.patch('passerelle.utils.Request.get')
285
def test_get_and_update_contact(mocked_get, mocked_put, app, connector):
294
def test_get_and_update_contact(mocked_get, mocked_put, mocked_post, app, connector):
286 295
    mocked_get.return_value = utils.FakedResponse(content=CONTACT_RESPONSE, ok=True)
296
    mocked_post.return_value = utils.FakedResponse(content=KEY_RESPONSE, status_code=200)
287 297
    assert connector.get_or_create_contact('foo@example.com') == {'InternalCode': '0000000273'}
288 298
    mocked_put.return_value = utils.FakedResponse(
289 299
        content='{"InternalCode": "0000000277", "ReturnCode": 0, "Error": null}',
......
309 319
    response = app.post_json(url, params=payload, status=400)
310 320
    assert "does not match '^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}$" in response.json['err_desc']
311 321
    payload['datetime'] = '2019-01-15T10:00'
312
    mocked_post.return_value = utils.FakedResponse(content=BOOKING_RESPONSE,
313
                                                   status_code=200)
322
    # first return the API key, then the result of the booking creation
323
    mocked_post.side_effect = [
324
        utils.FakedResponse(content=KEY_RESPONSE, status_code=200),
325
        utils.FakedResponse(content=BOOKING_RESPONSE),
326
        Exception(),
327
    ]
314 328
    response = app.post_json(url, params=payload)
315 329
    assert mocked_post.call_args[1]['json']['Key'] == '86569D0CA1B1CBEF8D77DD5BDC9F5CBAE5C99074'
316 330
    assert mocked_post.call_args[1]['json']['Booking']['externalCode'] == 'formid'
317
-