Best Python code snippet using tempest_python
test_bnp_credential.py
Source:test_bnp_credential.py  
...46                                                         "user_name":47                                                         "FakeUserName",48                                                         "password":49                                                         "FakePassword"}}}50    def _test_update_credential(self, update_data, credential_id):51        update_request = self.new_update_request(52            'bnp-credentials', update_data, credential_id)53        return self.bnp_wsgi_controller.update(update_request, credential_id)54    def _test_update_credential_for_netconf_ssh(self, update_data,55                                                credential_id):56        update_request = self.new_update_request(57            'bnp-credentials', update_data, credential_id)58        with contextlib.nested(59                mock.patch.object(os.path, 'isfile', return_value=True)):60            result = self.bnp_wsgi_controller.update(61                update_request, credential_id)62            os.path.isfile.called63        return result64    def _test_raised_exception_message(self, update_data, credential_id,65                                       error_string):66        test_status = False67        try:68            self._test_update_credential(update_data, credential_id)69        except Exception as raised_exception:70            test_status = True71            self.assertEqual(error_string, raised_exception.message)72        self.assertTrue(test_status)73    def _test_create_credential_for_snmp(self, body):74        create_req = self.new_create_request('bnp-credentials', body,75                                             'json')76        return self.bnp_wsgi_controller.create(create_req)77    def _test_create_credential_for_netconf(self, body):78        create_req = self.new_create_request('bnp-credentials', body,79                                             'json')80        with contextlib.nested(81                mock.patch.object(os.path, 'isfile', return_value=True)):82            result = self.bnp_wsgi_controller.create(create_req)83            os.path.isfile.called84            return result85    def test_create_valid_cred_for_snmp(self):86        body_snmpv3 = {"bnp_credential":87                       {"name": "CRED1",88                        "snmpv3":89                        {"security_name": "xyz",90                         "auth_protocol": "md5",91                         "auth_key": "abcd1234",92                         "priv_protocol": "des",93                         "priv_key": "dummy_key"}}}94        body_snmpv1 = {"bnp_credential":95                       {"name": "CRED2",96                        "snmpv1":97                        {"write_community": "public"}}}98        body_snmpv2c = {"bnp_credential":99                        {"name": "CRED3",100                         "snmpv2c":101                         {"write_community": "public"}}}102        result_snmpv3 = self._test_create_credential_for_snmp(body_snmpv3)103        result_snmpv1 = self._test_create_credential_for_snmp(body_snmpv1)104        result_snmpv2c = self._test_create_credential_for_snmp(body_snmpv2c)105        self.assertEqual(result_snmpv3['bnp_credential']['name'],106                         body_snmpv3['bnp_credential']['name'])107        self.assertEqual(result_snmpv1['bnp_credential']['name'],108                         body_snmpv1['bnp_credential']['name'])109        self.assertEqual(result_snmpv2c['bnp_credential']['name'],110                         body_snmpv2c['bnp_credential']['name'])111    def test_create_valid_cred_for_netconf(self):112        body_netssh = {"bnp_credential":113                       {"name": "CRED1",114                        "netconf_ssh":115                        {"key_path": "/home/fakedir/key1.rsa"}}}116        body_netsoap = {"bnp_credential":117                        {"name": "CRED2",118                         "netconf_soap":119                         {"user_name": "fake_user",120                          "password": "fake_password"}}}121        result_netssh = self._test_create_credential_for_netconf(body_netssh)122        result_netsoap = self._test_create_credential_for_netconf(body_netsoap)123        self.assertEqual(result_netssh['bnp_credential']['name'],124                         body_netssh['bnp_credential']['name'])125        self.assertEqual(result_netsoap['bnp_credential']['name'],126                         body_netsoap['bnp_credential']['name'])127    def test_create_cred_with_invalid_protocol(self):128        body_snmp = {"bnp_credential":129                     {"name": "CRED1",130                      "snmpv4":131                      {"write_community": "public"}}}132        body_netconf = {"bnp_credential":133                        {"name": "CRED2",134                         "netconf-abc":135                         {"key_path": "/home/fakedir/key1.rsa"}}}136        self.assertRaises(webob.exc.HTTPBadRequest,137                          self._test_create_credential_for_snmp,138                          body_snmp)139        self.assertRaises(webob.exc.HTTPBadRequest,140                          self._test_create_credential_for_netconf,141                          body_netconf)142    def test_create_cred_with_no_name(self):143        body_snmp = {"bnp_credential":144                     {"snmpv2c":145                      {"write_community": "public"}}}146        body_netconf = {"bnp_credential":147                        {"netconf-ssh":148                         {"key_path": "/home/fakedir/key1.rsa"}}}149        self.assertRaises(webob.exc.HTTPBadRequest,150                          self._test_create_credential_for_snmp,151                          body_snmp)152        self.assertRaises(webob.exc.HTTPBadRequest,153                          self._test_create_credential_for_netconf,154                          body_netconf)155    def test_create_cred_with_invalid_parameters(self):156        body_snmpv2 = {"bnp_credential":157                       {"name": "CRED1",158                        "snmpv2c":159                        {"write_community": "public",160                         "fake_key": "/home/fakedir/key1.rsa"}}}161        body_snmpv3 = {"bnp_credential":162                       {"name": "CRED2",163                        "snmpv3":164                        {"security_name": "xyz",165                         "auth_protocol": "md5",166                         "priv_protocol": "des",167                         "priv_key": "dummy_key"}}}168        body_netssh = {"bnp_credential":169                       {"name": "CRED3",170                        "fake_key": "fake_value",171                        "netconf-ssh":172                        {"key_path": "/home/fakedir/key1.rsa"}}}173        body_netsoap = {"bnp_credential":174                        {"name": "CRED4",175                         "netconf-soap":176                         {"user_name": "fake_user"}}}177        self.assertRaises(webob.exc.HTTPBadRequest,178                          self._test_create_credential_for_snmp,179                          body_snmpv2)180        self.assertRaises(webob.exc.HTTPBadRequest,181                          self._test_create_credential_for_snmp,182                          body_snmpv3)183        self.assertRaises(webob.exc.HTTPBadRequest,184                          self._test_create_credential_for_netconf,185                          body_netssh)186        self.assertRaises(webob.exc.HTTPBadRequest,187                          self._test_create_credential_for_netconf,188                          body_netsoap)189    def test_update_credential_snmpv1(self):190        credential = self._test_create_credential_for_snmp(self.snmpv1_data)191        credential_id = credential["bnp_credential"]["id"]192        update_data = {"bnp_credential": {"snmpv1": {193            "write_community": "private"}, "name": "NewCredName"}}194        updated_dict = self._test_update_credential(update_data, credential_id)195        expected_dict = {"id": credential_id, "protocol_type": "snmpv1",196                         "write_community": "private", "name": "NewCredName",197                         "security_name": None, "auth_protocol": None,198                         "auth_key": None, "priv_protocol": None,199                         "priv_key": None, "security_level": None}200        self.assertDictEqual(updated_dict, expected_dict)201    def test_update_credential_snmpv2c(self):202        credential = self._test_create_credential_for_snmp(self.snmpv2c_data)203        credential_id = credential["bnp_credential"]["id"]204        update_data = {"bnp_credential": {"snmpv2c": {205            "write_community": "private"}, "name": "NewCredName"}}206        updated_dict = self._test_update_credential(update_data, credential_id)207        expected_dict = {"id": credential_id, "protocol_type": "snmpv2c",208                         "write_community": "private", "name": "NewCredName",209                         "security_name": None, "auth_protocol": None,210                         "auth_key": None, "priv_protocol": None,211                         "priv_key": None, "security_level": None}212        self.assertDictEqual(updated_dict, expected_dict)213    def test_update_credential_snmpv3(self):214        credential = self._test_create_credential_for_snmp(self.snmpv3_data)215        credential_id = credential["bnp_credential"]["id"]216        update_data = {"bnp_credential": {"snmpv3": {"security_name":217                                                     "NewFakeSecurityName",218                                                     "auth_protocol": "md5",219                                                     "auth_key": "FakeAuthKey",220                                                     "priv_protocol": "aes192",221                                                     "priv_key": "FakePrivKey"222                                                     }, "name": "NewCredName"}}223        updated_dict = self._test_update_credential(update_data, credential_id)224        expected_dict = {"id": credential_id, "protocol_type": "snmpv3",225                         "write_community": None, "name": "NewCredName",226                         "security_name": "NewFakeSecurityName",227                         "auth_protocol": "md5", "auth_key": "FakeAuthKey",228                         "priv_protocol": "aes192", "priv_key": "FakePrivKey",229                         "security_level": None}230        self.assertDictEqual(updated_dict, expected_dict)231    def test_update_credential_netconf_ssh(self):232        credential = self._test_create_credential_for_netconf(233            self.netconf_ssh_data)234        credential_id = credential["bnp_credential"]["id"]235        update_data = {"bnp_credential": {"netconf_ssh": {"user_name":236                                                          "NewFakeUserName",237                                                          "password":238                                                          "NewFakePassword",239                                                          "key_path": ("/home/"240                                                                       "faked"241                                                                       "ir/key"242                                                                       "1.rsa")243                                                          }, "name":244                                                             "NewCredName"}}245        updated_dict = self._test_update_credential_for_netconf_ssh(246            update_data, credential_id)247        expected_dict = {"id": credential_id, "protocol_type": "netconf_ssh",248                         "user_name": "NewFakeUserName",249                         "password": "NewFakePassword", "key_path":250                         "/home/fakedir/key1.rsa", "name": "NewCredName"}251        self.assertDictEqual(updated_dict, expected_dict)252    def test_update_credential_netconf_soap(self):253        credential = self._test_create_credential_for_netconf(254            self.netconf_soap_data)255        credential_id = credential["bnp_credential"]["id"]256        update_data = {"bnp_credential": {"netconf_soap": {257            "user_name": "NewFakeUserName", "password": "NewFakePassword"},258            "name": "NewCredName"}}259        updated_dict = self._test_update_credential(update_data, credential_id)260        expected_dict = {"id": credential_id, "protocol_type": "netconf_soap",261                         "user_name": "NewFakeUserName",262                         "password": "NewFakePassword", "key_path": None,263                         "name": "NewCredName"}264        self.assertDictEqual(updated_dict, expected_dict)265    def test_update_credential_snmpv1_only_name(self):266        credential = self._test_create_credential_for_snmp(self.snmpv1_data)267        credential_id = credential["bnp_credential"]["id"]268        update_data = {"bnp_credential": {"name": "NewCredName"}}269        updated_dict = self._test_update_credential(update_data, credential_id)270        expected_dict = {"id": credential_id, "protocol_type": "snmpv1",271                         "write_community": "public", "name": "NewCredName",272                         "security_name": None, "auth_protocol": None,273                         "auth_key": None, "priv_protocol": None,274                         "priv_key": None, "security_level": None}275        self.assertDictEqual(updated_dict, expected_dict)276    def test_update_credential_snmpv2c_only_name(self):277        credential = self._test_create_credential_for_snmp(self.snmpv2c_data)278        credential_id = credential["bnp_credential"]["id"]279        update_data = {"bnp_credential": {"name": "NewCredName"}}280        updated_dict = self._test_update_credential(update_data, credential_id)281        expected_dict = {"id": credential_id, "protocol_type": "snmpv2c",282                         "write_community": "public", "name": "NewCredName",283                         "security_name": None, "auth_protocol": None,284                         "auth_key": None, "priv_protocol": None,285                         "priv_key": None, "security_level": None}286        self.assertDictEqual(updated_dict, expected_dict)287    def test_update_credential_snmpv3_only_name(self):288        credential = self._test_create_credential_for_snmp(self.snmpv3_data)289        credential_id = credential["bnp_credential"]["id"]290        update_data = {"bnp_credential": {"name": "NewCredName"}}291        updated_dict = self._test_update_credential(update_data, credential_id)292        expected_dict = {"id": credential_id, "protocol_type": "snmpv3",293                         "write_community": None, "name": "NewCredName",294                         "security_name": "FakeSecName", "auth_protocol": None,295                         "auth_key": None, "priv_protocol": None,296                         "priv_key": None, "security_level": None}297        self.assertDictEqual(updated_dict, expected_dict)298    def test_update_credential_netconf_ssh_only_name(self):299        credential = self._test_create_credential_for_netconf(300            self.netconf_ssh_data)301        credential_id = credential["bnp_credential"]["id"]302        update_data = {"bnp_credential": {"name": "NewCredName"}}303        updated_dict = self._test_update_credential_for_netconf_ssh(304            update_data, credential_id)305        expected_dict = {"id": credential_id, "protocol_type": "netconf_ssh",306                         "user_name": "FakeUserName",307                         "password": "FakePassword", "key_path":308                         "/home/fakedir/key1.rsa", "name": "NewCredName"}309        self.assertDictEqual(updated_dict, expected_dict)310    def test_update_credential_netconf_soap_only_name(self):311        credential = self._test_create_credential_for_netconf(312            self.netconf_soap_data)313        credential_id = credential["bnp_credential"]["id"]314        update_data = {"bnp_credential": {"name": "NewCredName"}}315        updated_dict = self._test_update_credential(update_data, credential_id)316        expected_dict = {"id": credential_id, "protocol_type": "netconf_soap",317                         "user_name": "FakeUserName",318                         "password": "FakePassword", "key_path": None,319                         "name": "NewCredName"}320        self.assertDictEqual(updated_dict, expected_dict)321    def test_update_credential_snmpv1_proto_type(self):322        credential = self._test_create_credential_for_snmp(self.snmpv1_data)323        credential_id = credential["bnp_credential"]["id"]324        update_data = {"bnp_credential": {325            "snmpv2c": {"write_community": "private"}}}326        error_string = ("protocol type cannot be updated for the id " +327                        str(credential_id))328        self._test_raised_exception_message(329            update_data, credential_id, error_string)...test_credentials_client.py
Source:test_credentials_client.py  
...121            'tempest.lib.common.rest_client.RestClient.get',122            self.FAKE_INFO_CREDENTIAL,123            bytes_body,124            credential_id="207e9b76935efc03804d3dd6ab52d22e9b22a0711e4ada4f")125    def _test_update_credential(self, bytes_body=False):126        self.check_service_client_function(127            self.client.update_credential,128            'tempest.lib.common.rest_client.RestClient.patch',129            self.FAKE_INFO_CREDENTIAL,130            bytes_body,131            credential_id="207e9b76935efc03804d3dd6ab52d22e9b22a0711e4ada4f")132    def _test_list_credentials(self, bytes_body=False):133        self.check_service_client_function(134            self.client.list_credentials,135            'tempest.lib.common.rest_client.RestClient.get',136            self.FAKE_LIST_CREDENTIALS,137            bytes_body)138    def test_create_credential_with_str_body(self):139        self._test_create_credential()140    def test_create_credential_with_bytes_body(self):141        self._test_create_credential(bytes_body=True)142    def test_show_credential_with_str_body(self):143        self._test_show_credential()144    def test_show_credential_with_bytes_body(self):145        self._test_show_credential(bytes_body=True)146    def test_update_credential_with_str_body(self):147        self._test_update_credential()148    def test_update_credential_with_bytes_body(self):149        self._test_update_credential(bytes_body=True)150    def test_list_credentials_with_str_body(self):151        self._test_list_credentials()152    def test_list_credentials_with_bytes_body(self):153        self._test_list_credentials(bytes_body=True)154    def test_delete_credential(self):155        self.check_service_client_function(156            self.client.delete_credential,157            'tempest.lib.common.rest_client.RestClient.delete',158            {},159            credential_id="207e9b76935efc03804d3dd6ab52d22e9b22a0711e4ada4f",...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
