How to use test_index1 method in Slash

Best Python code snippet using slash

cortx_s3_kv_api_tests.py

Source:cortx_s3_kv_api_tests.py Github

copy

Full Screen

1#2# Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15#16# For any questions about this software or licensing,17# please email opensource@seagate.com or cortx-questions@seagate.com.18#19"""20Unit Test for CORTXS3KVAPI.21"""22from http.client import HTTPConnection23from http.client import HTTPResponse24from unittest.mock import Mock25from s3backgrounddelete.cortx_s3_kv_api import CORTXS3KVApi26from s3backgrounddelete.cortx_s3_config import CORTXS3Config27def test_get_no_index_id():28 """Test GET api without index_id should return response as "None"."""29 config = CORTXS3Config(use_cipher = False)30 response = CORTXS3KVApi(config).get(None, "test_key1")31 if (response is not None):32 assert response[0] is False33 assert response[1] is None34def test_get_no_object_key_name():35 """Test GET api without object_key_name should return response as "None"."""36 config = CORTXS3Config(use_cipher = False)37 response = CORTXS3KVApi(config).get("test_index1", None)38 if (response is not None):39 assert response[0] is False40def test_get_success():41 """Test GET api, it should return success response."""42 result = b'{"Key": "test_key1", "Value": "testValue1"}'43 httpconnection = Mock(spec=HTTPConnection)44 httpresponse = Mock(spec=HTTPResponse)45 httpresponse.status = 20046 httpresponse.getheaders.return_value = \47 'Content-Type:text/html;Content-Length:14'48 httpresponse.read.return_value = result49 httpresponse.reason = 'OK'50 httpconnection.getresponse.return_value = httpresponse51 config = CORTXS3Config(use_cipher = False)52 response = CORTXS3KVApi(config, connection=httpconnection).get("test_index1", "test_key1")53 if (response is not None):54 assert response[0] is True55def test_get_failure():56 """57 Test if index or key is not present then58 GET should return failure response.59 """60 httpconnection = Mock(spec=HTTPConnection)61 httpresponse = Mock(spec=HTTPResponse)62 httpresponse.status = 40463 httpresponse.getheaders.return_value = \64 'Content-Type:text/html;Content-Length:14'65 httpresponse.read.return_value = b'{}'66 httpresponse.reason = 'NOT FOUND'67 httpconnection.getresponse.return_value = httpresponse68 config = CORTXS3Config(use_cipher = False)69 response = CORTXS3KVApi(config, connection=httpconnection).get("test_index2", "test_key2")70 if (response is not None):71 assert response[0] is False72def test_delete_no_index_id():73 """Test DELETE api without index should return response as "None"."""74 config = CORTXS3Config(use_cipher = False)75 response = CORTXS3KVApi(config).delete(None, "test_key1")76 if (response is not None):77 assert response[0] is False78 assert response[1] is None79def test_delete_no_object_key_name():80 """Test DELETE api without object key name should return response as "None"."""81 config = CORTXS3Config(use_cipher = False)82 response = CORTXS3KVApi(config).delete("test_index1", None)83 if (response is not None):84 assert response[0] is False85 assert response[1] is None86def test_delete_success():87 """Test DELETE api, it should return success response."""88 httpconnection = Mock(spec=HTTPConnection)89 httpresponse = Mock(spec=HTTPResponse)90 httpresponse.status = 20491 httpresponse.getheaders.return_value = \92 'Content-Type:text/html;Content-Length:14'93 httpresponse.read.return_value = b'{}'94 httpresponse.reason = 'NO CONTENT'95 httpconnection.getresponse.return_value = httpresponse96 config = CORTXS3Config(use_cipher = False)97 response = CORTXS3KVApi(config, connection=httpconnection).delete("test_index1", "test_key1")98 if (response is not None):99 assert response[0] is True100def test_delete_failure():101 """102 Test if index or key is not present then103 DELETE should return failure response.104 """105 httpconnection = Mock(spec=HTTPConnection)106 httpresponse = Mock(spec=HTTPResponse)107 httpresponse.status = 404108 httpresponse.getheaders.return_value = \109 'Content-Type:text/html;Content-Length:14'110 httpresponse.read.return_value = b'{}'111 httpresponse.reason = 'NO CONTENT'112 httpconnection.getresponse.return_value = httpresponse113 config = CORTXS3Config(use_cipher = False)114 response = CORTXS3KVApi(config, connection=httpconnection).delete("test_index1", "test_key1")115 if (response is not None):116 assert response[0] is False117def test_put_no_index_id():118 """Test PUT api without index_id should return response as "None"."""119 config = CORTXS3Config(use_cipher = False)120 response = CORTXS3KVApi(config).put(None, "test_key1")121 if (response is not None):122 assert response[0] is False123 assert response[1] is None124def test_put_no_object_key_name():125 """Test PUT api without key should return response as "None"."""126 config = CORTXS3Config(use_cipher = False)127 response = CORTXS3KVApi(config).put("test_index1", None)128 if (response is not None):129 assert response[0] is False130 assert response[1] is None131def test_put_success():132 """Test PUT api, it should return success response."""133 httpconnection = Mock(spec=HTTPConnection)134 httpresponse = Mock(spec=HTTPResponse)135 httpresponse.status = 200136 httpresponse.getheaders.return_value = \137 'Content-Type:text/html;Content-Length:14'138 httpresponse.read.return_value = b'{}'139 httpresponse.reason = 'CREATED'140 httpconnection.getresponse.return_value = httpresponse141 config = CORTXS3Config(use_cipher = False)142 response = CORTXS3KVApi(config, connection=httpconnection).put("test_index1", "test_key1")143 if (response is not None):144 assert response[0] is True145def test_put_failure():146 """147 Test if index_id and object key name is already present then148 PUT should return failure response.149 """150 httpconnection = Mock(spec=HTTPConnection)151 httpresponse = Mock(spec=HTTPResponse)152 httpresponse.status = 409153 httpresponse.getheaders.return_value = \154 'Content-Type:text/html;Content-Length:14'155 httpresponse.read.return_value = b'{}'156 httpresponse.reason = 'CONFLICT'157 httpconnection.getresponse.return_value = httpresponse158 config = CORTXS3Config(use_cipher = False)159 response = CORTXS3KVApi(config, connection=httpconnection).put("test_index2", "test_key2")160 if (response is not None):...

Full Screen

Full Screen

cortx_s3_client_tests.py

Source:cortx_s3_client_tests.py Github

copy

Full Screen

1#2# Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15#16# For any questions about this software or licensing,17# please email opensource@seagate.com or cortx-questions@seagate.com.18#19"""20Unit Test for CORTXS3Client API.21"""22from http.client import HTTPConnection23from http.client import HTTPResponse24from unittest.mock import Mock25import pytest26from s3backgrounddelete.cortx_s3_client import CORTXS3Client27from s3backgrounddelete.cortx_s3_config import CORTXS3Config28def test_get_connection_success():29 """Test if HTTPConnection object is returned"""30 config = CORTXS3Config(use_cipher = False)31 response = CORTXS3Client(config)._get_connection()32 assert isinstance(response, HTTPConnection)33def test_get_connection_as_none():34 """35 Test if get_connection does not has endpoint configured then36 it should return "None"37 """38 config = Mock(spec=CORTXS3Config)39 config.get_cortx_s3_endpoint = Mock(side_effect=KeyError())40 assert CORTXS3Client(config)._get_connection() is None41def test_get_failure():42 """43 Test if connection object is "None" then GET method should throw TypeError.44 """45 with pytest.raises(TypeError):46 config = Mock(spec=CORTXS3Config)47 config.get_cortx_s3_endpoint = Mock(side_effect=KeyError())48 assert CORTXS3Client(config).get('/indexes/test_index1')49def test_get_success():50 """Test GET request should return success response."""51 result = b'{"Key": "test_key1", "Value": "testValue1"}'52 httpconnection = Mock(spec=HTTPConnection)53 httpresponse = Mock(spec=HTTPResponse)54 httpresponse.status = 20055 httpresponse.getheaders.return_value = \56 'Content-Type:text/html;Content-Length:14'57 httpresponse.read.return_value = result58 httpresponse.reason = 'OK'59 httpconnection.getresponse.return_value = httpresponse60 config = CORTXS3Config(use_cipher = False)61 response = CORTXS3Client(config, connection=httpconnection).get(62 '/indexes/test_index1')63 assert response['status'] == 20064def test_put_failure():65 """66 Test if connection object is "None" then PUT method should throw TypeError.67 """68 with pytest.raises(TypeError):69 config = Mock(spec=CORTXS3Config)70 config.get_cortx_s3_endpoint = Mock(side_effect=KeyError())71 assert CORTXS3Client(config).put('/indexes/test_index1')72def test_put_success():73 """Test PUT request should return success response."""74 httpconnection = Mock(spec=HTTPConnection)75 httpresponse = Mock(spec=HTTPResponse)76 httpresponse.status = 20177 httpresponse.getheaders.return_value = \78 'Content-Type:text/html;Content-Length:14'79 httpresponse.read.return_value = b'{}'80 httpresponse.reason = 'CREATED'81 httpconnection.getresponse.return_value = httpresponse82 config = CORTXS3Config(use_cipher = False)83 request_uri = '/indexes/test_index1'84 response = CORTXS3Client(config, connection=httpconnection).put(request_uri)85 assert response['status'] == 20186def test_delete_failure():87 """88 Test if connection object is "None" then DELETE should throw TypeError.89 """90 with pytest.raises(TypeError):91 config = Mock(spec=CORTXS3Config)92 config.get_cortx_s3_endpoint = Mock(side_effect=KeyError())93 assert CORTXS3Client(config).delete('/indexes/test_index1')94def test_delete_success():95 """Test DELETE request should return success response."""96 httpconnection = Mock(spec=HTTPConnection)97 httpresponse = Mock(spec=HTTPResponse)98 httpresponse.status = 20499 httpresponse.getheaders.return_value = \100 'Content-Type:text/html;Content-Length:14'101 httpresponse.read.return_value = b'test body'102 httpresponse.reason = 'OK'103 httpconnection.getresponse.return_value = httpresponse104 config = CORTXS3Config(use_cipher = False)105 response = CORTXS3Client(config, connection=httpconnection).delete(106 '/indexes/test_index1')107 assert response['status'] == 204108def test_head_failure():109 """110 Test if connection object is "None" then HEAD should throw TypeError.111 """112 with pytest.raises(TypeError):113 config = Mock(spec=CORTXS3Config)114 config.get_cortx_s3_endpoint = Mock(side_effect=KeyError())115 assert CORTXS3Client(config).head('/indexes/test_index1')116def test_head_success():117 """Test HEAD request should return success response."""118 httpconnection = Mock(spec=HTTPConnection)119 httpresponse = Mock(spec=HTTPResponse)120 httpresponse.status = 200121 httpresponse.getheaders.return_value = \122 'Content-Type:text/html;Content-Length:14'123 httpresponse.read.return_value = b'test body'124 httpresponse.reason = 'OK'125 httpconnection.getresponse.return_value = httpresponse126 config = CORTXS3Config(use_cipher = False)127 response = CORTXS3Client(config, connection=httpconnection).head(128 '/indexes/test_index1')...

Full Screen

Full Screen

cortx_s3_index_api_tests.py

Source:cortx_s3_index_api_tests.py Github

copy

Full Screen

1#2# Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15#16# For any questions about this software or licensing,17# please email opensource@seagate.com or cortx-questions@seagate.com.18#19"""20Unit Test for CORTXS3Index API.21"""22from http.client import HTTPConnection23from http.client import HTTPResponse24from unittest.mock import Mock25from s3backgrounddelete.cortx_s3_index_api import CORTXS3IndexApi26from s3backgrounddelete.cortx_s3_config import CORTXS3Config27def test_list_no_index_id():28 """Test List api without index_id should return response as "None"."""29 config = CORTXS3Config(use_cipher = False)30 response = CORTXS3IndexApi(config).list(None)31 if (response is not None):32 assert response[0] is False33 assert response[1] is None34def test_list_success():35 """Test List api, it should return success response."""36 result = b'{"index_id":"test_index1","object_layout_id":1,"object_metadata_path":"test_index1"}'37 httpconnection = Mock(spec=HTTPConnection)38 httpresponse = Mock(spec=HTTPResponse)39 httpresponse.status = 20040 httpresponse.getheaders.return_value = \41 'Content-Type:text/html;Content-Length:14'42 httpresponse.read.return_value = result43 httpresponse.reason = 'OK'44 httpconnection.getresponse.return_value = httpresponse45 config = CORTXS3Config(use_cipher = False)46 response = CORTXS3IndexApi(config, connection=httpconnection).list("test_index1")47 if (response is not None):48 assert response[0] is True49 assert response[1] is not None50def test_list_failure():51 """Test if index is not present then List should return failure response."""52 httpconnection = Mock(spec=HTTPConnection)53 httpresponse = Mock(spec=HTTPResponse)54 httpresponse.status = 40455 httpresponse.getheaders.return_value = \56 'Content-Type:text/html;Content-Length:14'57 httpresponse.read.return_value = b'{}'58 httpresponse.reason = 'NOT FOUND'59 httpconnection.getresponse.return_value = httpresponse60 config = CORTXS3Config(use_cipher = False)61 response = CORTXS3IndexApi(config, connection=httpconnection).list("test_index2")62 if (response is not None):63 assert response[0] is False64 assert response[1] is not None65def test_put_success():66 """Test PUT api, it should return success response."""67 httpconnection = Mock(spec=HTTPConnection)68 httpresponse = Mock(spec=HTTPResponse)69 httpresponse.status = 20170 httpresponse.getheaders.return_value = \71 'Content-Type:text/html;Content-Length:14'72 httpresponse.read.return_value = b'{}'73 httpresponse.reason = 'CREATED'74 httpconnection.getresponse.return_value = httpresponse75 config = CORTXS3Config(use_cipher = False)76 response = CORTXS3IndexApi(config, connection=httpconnection).put("test_index1")77 if (response is not None):78 assert response[0] is True79def test_put_failure():80 """Test if index is already present then PUT should return failure response."""81 httpconnection = Mock(spec=HTTPConnection)82 httpresponse = Mock(spec=HTTPResponse)83 httpresponse.status = 40984 httpresponse.getheaders.return_value = \85 'Content-Type:text/html;Content-Length:14'86 httpresponse.read.return_value = b'{}'87 httpresponse.reason = 'CONFLICT'88 httpconnection.getresponse.return_value = httpresponse89 config = CORTXS3Config(use_cipher = False)90 response = CORTXS3IndexApi(config, connection=httpconnection).put("test_index1")91 if (response is not None):92 assert response[0] is False93def test_put_no_index_id():94 """Test PUT request without index_id, it should return response as "None"."""95 config = CORTXS3Config(use_cipher = False)96 response = CORTXS3IndexApi(config).put(None)97 if (response is not None):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful