def test_put_failure(): """ Test if connection object is "None" then PUT method should throw TypeError. """ with pytest.raises(TypeError): config = Mock(spec=CORTXS3Config) config.get_cortx_s3_endpoint = Mock(side_effect=KeyError()) assert CORTXS3Client(config).put('/indexes/test_index1')
def test_get_connection_as_none(): """ Test if get_connection does not has endpoint configured then it should return "None" """ config = Mock(spec=CORTXS3Config) config.get_cortx_s3_endpoint = Mock(side_effect=KeyError()) assert CORTXS3Client(config)._get_connection() is None
def test_get_connection_as_none(): """ Test if get_connection does not has endpoint configured then it should return "None" """ config = Mock(spec=CORTXS3Config) config.get_cortx_s3_endpoint_for_producer = Mock(side_effect=KeyError()) assert CORTXS3Client( config, CONNECTION_TYPE_PRODUCER)._get_producer_connection() is None
def test_head_failure(): """ Test if connection object is "None" then HEAD should throw TypeError. """ with pytest.raises(TypeError): config = Mock(spec=CORTXS3Config) config.get_cortx_s3_endpoint = Mock(side_effect=KeyError()) assert CORTXS3Client( config, CONNECTION_TYPE_PRODUCER).head('/indexes/test_index1')
def test_head_success(): """Test HEAD request should return success response.""" httpconnection = Mock(spec=HTTPConnection) httpresponse = Mock(spec=HTTPResponse) httpresponse.status = 200 httpresponse.getheaders.return_value = \ 'Content-Type:text/html;Content-Length:14' httpresponse.read.return_value = b'test body' httpresponse.reason = 'OK' httpconnection.getresponse.return_value = httpresponse config = CORTXS3Config(use_cipher=False) response = CORTXS3Client( config, connection=httpconnection).head('/indexes/test_index1') assert response['status'] == 200
def test_delete_success(): """Test DELETE request should return success response.""" httpconnection = Mock(spec=HTTPConnection) httpresponse = Mock(spec=HTTPResponse) httpresponse.status = 204 httpresponse.getheaders.return_value = \ 'Content-Type:text/html;Content-Length:14' httpresponse.read.return_value = b'test body' httpresponse.reason = 'OK' httpconnection.getresponse.return_value = httpresponse config = CORTXS3Config() response = CORTXS3Client( config, CONNECTION_TYPE_PRODUCER, connection=httpconnection).delete('/indexes/test_index1') assert response['status'] == 204
def test_put_success(): """Test PUT request should return success response.""" httpconnection = Mock(spec=HTTPConnection) httpresponse = Mock(spec=HTTPResponse) httpresponse.status = 201 httpresponse.getheaders.return_value = \ 'Content-Type:text/html;Content-Length:14' httpresponse.read.return_value = b'{}' httpresponse.reason = 'CREATED' httpconnection.getresponse.return_value = httpresponse config = CORTXS3Config(use_cipher=False) request_uri = '/indexes/test_index1' response = CORTXS3Client(config, connection=httpconnection).put(request_uri) assert response['status'] == 201
def test_get_success(): """Test GET request should return success response.""" result = b'{"Key": "test_key1", "Value": "testValue1"}' httpconnection = Mock(spec=HTTPConnection) httpresponse = Mock(spec=HTTPResponse) httpresponse.status = 200 httpresponse.getheaders.return_value = \ 'Content-Type:text/html;Content-Length:14' httpresponse.read.return_value = result httpresponse.reason = 'OK' httpconnection.getresponse.return_value = httpresponse config = CORTXS3Config(use_cipher=False) response = CORTXS3Client( config, connection=httpconnection).get('/indexes/test_index1') assert response['status'] == 200
def test_get_connection_success(): """Test if HTTPConnection object is returned""" config = CORTXS3Config() response = CORTXS3Client( config, CONNECTION_TYPE_PRODUCER)._get_producer_connection() assert isinstance(response, HTTPConnection)
def test_get_connection_success(): """Test if HTTPConnection object is returned""" config = CORTXS3Config(use_cipher=False) response = CORTXS3Client(config)._get_connection() assert isinstance(response, HTTPConnection)