示例#1
0
def test_elastic_search():
    connection = Connection('username', 'password', 'https://host')
    connection._opener = MagicMock()
    # noinspection PyProtectedMember
    connection._opener.open().read.return_value = '{"hello":"world"}'

    assert connection.make_request('/uri', {'it\'s': 'alive'}) == {
        'hello': 'world'
    }

    request = urllib2.Request('https://host/uri',
                              '{"it\'s": "alive"}',
                              headers={
                                  'Content-type': 'application/json',
                                  'Accept': 'application/json',
                                  'Authorization':
                                  'Basic dXNlcm5hbWU6cGFzc3dvcmQ='
                              })
    capture = Capture()
    # noinspection PyProtectedMember
    connection._opener.open.assert_called_with(capture)
    assert request.get_full_url() == capture.value.get_full_url()
    assert request.header_items() == capture.value.header_items()
    assert request.get_method() == capture.value.get_method()
    assert request.get_data() == capture.value.get_data()
def test_elastic_search():
    connection = Connection('username', 'password', 'https://host')
    connection._opener = MagicMock()
    # noinspection PyProtectedMember
    connection._opener.open().read.return_value = '{"hello":"world"}'

    assert connection.make_request('/uri', {'it\'s': 'alive'}) == {'hello': 'world'}

    request = urllib2.Request('https://host/uri',
                              '{"it\'s":"alive"}',
                              headers={
                                  'Content-type': 'application/json',
                                  'Accept': 'application/json',
                                  'Authorization': 'Basic dXNlcm5hbWU6cGFzc3dvcmQ='
                              })
    # noinspection PyProtectedMember,PyUnresolvedReferences
    connection._opener.open.verify_called_once_with(request)