Ejemplo n.º 1
0
def test_get_connection():
    from datetime import datetime

    from bigchaindb_driver.connection import Connection
    from bigchaindb_driver.pool import Pool

    connections = [Connection(node_url=0)]
    pool = Pool(connections)
    for _ in range(10):
        connection = pool.get_connection()
        assert connection.node_url == 0

    connections = [Connection(node_url=0), Connection(node_url=1),
                   Connection(node_url=2)]
    pool = Pool(connections)

    for _ in range(10):
        connection = pool.get_connection()
        assert connection.node_url == 0

    connections[0].backoff_time = datetime.utcnow()
    for _ in range(10):
        connection = pool.get_connection()
        assert connection.node_url == 1

    connections[1].backoff_time = datetime.utcnow()
    for _ in range(10):
        connection = pool.get_connection()
        assert connection.node_url == 2

    connections[2].backoff_time = datetime.utcnow()
    for _ in range(10):
        connection = pool.get_connection()
        assert connection.node_url == 0
Ejemplo n.º 2
0
 def test_response_content_type_handling(self, content_type, json, data):
     from bigchaindb_driver.connection import Connection
     url = 'http://dummy'
     connection = Connection(node_url=url)
     with RequestsMock() as requests_mock:
         requests_mock.add('GET', url, json=json)
         response = connection.request('GET')
     assert response.status_code == 200
     assert response.headers['Content-Type'] == content_type
     assert response.data == data
Ejemplo n.º 3
0
 def test_request_with_headers(self, headers):
     from bigchaindb_driver.connection import Connection
     url = 'http://dummy'
     connection = Connection(node_url=url, headers=headers)
     with RequestsMock() as requests_mock:
         requests_mock.add('GET', url, adding_headers=headers)
         response = connection.request('GET')
     assert response.status_code == 200
     del response.headers['Content-type']
     assert response.headers == headers
Ejemplo n.º 4
0
 def test_init_with_custom_headers(self):
     from bigchaindb_driver.connection import Connection
     url = 'http://dummy'
     custom_headers = {'app_id': 'id_value', 'app_key': 'key_value'}
     connection = Connection(node_url=url, headers=custom_headers)
     expected_headers = default_headers()
     expected_headers.update(custom_headers)
     assert connection.session.headers == expected_headers