Exemplo n.º 1
0
def test_call_response():
    call = FirstCall('Testing Call contractor', url='/id: 1', query='a=1')
    call.conclude(wsgi_application)
    assert call.response is not None
    assert call.response.body is not None
    assert call.response.status == '200 OK'
    assert call.response.status == 200
    assert call.response.encoding == 'utf-8'
    assert call.response.content_type == 'application/json'
    assert call.response.text is not None
    assert call.response.json == {'query': 'a=1', 'url': '/1'}
    assert call.response.headers == [('Content-Type',
                                      'application/json;charset=utf-8')]
Exemplo n.º 2
0
def test_call_constructor():
    call = FirstCall('Testing Call contractor', url='/id: 1')
    assert call.url == '/:id'
    assert call.url_parameters == dict(id='1')

    call = FirstCall('Testing Call contractor',
                     url='/id: 1/:name',
                     url_parameters=dict(name='foo', id=2))
    call.validate()
    assert call.url == '/:id/:name'
    assert call.url_parameters == dict(id='2', name='foo')
    call.conclude(wsgi_application)
    assert '/2/foo' == call.response.json['url']
Exemplo n.º 3
0
def test_call_to_dict():
    call = FirstCall(title='Testing Call to_dict', url='/id: 1', query='a=1')
    call.conclude(wsgi_application)
    call_dict = call.to_dict()
    assert call_dict == dict(
        title='Testing Call to_dict',
        query=dict(a='1'),
        url='/:id',
        url_parameters={'id': '1'},
        verb='GET',
        response=dict(
            json={'query': 'a=1', 'url': '/1'},
            headers=['Content-Type: application/json;charset=utf-8'],
            status='200 OK',
        )
    )
Exemplo n.º 4
0
def test_call_verify():
    call = FirstCall('Testing FirstCall contractor',
                     url='/id: 1',
                     query=dict(a=1))

    call.conclude(wsgi_application)
    call.verify(wsgi_application)

    altered_call = AlteredCall(call, 'Altering a call', query=dict(b=2))
    altered_call.conclude(wsgi_application)
    altered_call.verify(wsgi_application)

    altered_call.response.body = '{"a": 1}'
    with pytest.raises(CallVerifyError):
        altered_call.verify(wsgi_application)

    altered_call.response.status = '400 Bad Request'
    with pytest.raises(CallVerifyError):
        altered_call.verify(wsgi_application)
Exemplo n.º 5
0
def test_call_invoke():
    call = FirstCall('Testing Call contractor', url='/id: 1')
    call.conclude(wsgi_application)
    assert call.response is not None