def test_do_prepare_empyt(self): mock_send = mock.Mock(return_value=Response(self.status_not_found, "")) #mock_run_cmd = mock.Mock(side_effect=[self.cipher, json.dumps({"ErrCode": CODE_SERVER_RESP_INVALID, "ErrMessage": MSG_SERVER_RESP_INVALID})]) cert_store = Client( self.apikey, #self.cert_path, self.sig_param, self.uri, True, cert=('./tls/client.pem', './tls/client.key'), cacert='./tls/ca.crt') with mock.patch('requests.Session.send', mock_send): poeid_filepart = ( "", "poe id", ) files = { "poe_id": poeid_filepart, } _, result = cert_store.do_prepare( requests.Request("POST", url=self.url, files=files).prepare(), ) self.assertEqual(MSG_SERVER_RESP_INVALID, result["ErrMessage"]) self.assertEqual(CODE_SERVER_RESP_INVALID, result["ErrCode"])
def test_do_prepare_not_found(self): mock_send = mock.Mock( return_value=Response(self.status_not_found, self.resp_not_found)) mock_run_cmd = mock.Mock(side_effect=[ self.cipher, json.dumps({ "ErrCode": CODE_DECRYPT_FAILED, "ErrMessage": MSG_DECRYPT_FAILED }) ]) cert_store = Client(self.apikey, self.cert_path, self.sig_param, self.uri, True) with mock.patch('requests.Session.send', mock_send): poeid_filepart = ( "", "poe id", ) files = { "poe_id": poeid_filepart, } _, result = cert_store.do_prepare( requests.Request("POST", url=self.url, files=files).prepare(), ) self.assertEqual(MSG_DECRYPT_FAILED, result["ErrMessage"]) self.assertEqual(CODE_DECRYPT_FAILED, result["ErrCode"])
def test_do_prepare_empyt(self): mock_send = mock.Mock(return_value=Response(self.status_not_found, "")) mock_run_cmd = mock.Mock(side_effect=[ self.cipher, json.dumps({ "ErrCode": CODE_RESP_BODY_EMPTY, "ErrMsg": MSG_RESP_BODY_EMPTY }) ]) cert_store = Client(self.apikey, self.cert_path, self.uri) with mock.patch('cryption.crypto.run_cmd', mock_run_cmd): with mock.patch('requests.Session.send', mock_send): poeid_filepart = ( "", "poe id", ) files = { "poe_id": poeid_filepart, } _, result = cert_store.do_prepare( requests.Request("POST", url=self.url, files=files).prepare(), ) self.assertEqual(MSG_RESP_BODY_EMPTY, result["ErrMsg"]) self.assertEqual(CODE_RESP_BODY_EMPTY, result["ErrCode"])
def test_do_prepare_succ(self): mock_send = mock.Mock( return_value=Response(self.status_ok, json.dumps(self.resp))) cert_store = Client(self.apikey, self.cert_path, self.sig_param, self.uri, True) with mock.patch('requests.Session.send', mock_send): poeid_filepart = ( "", "poe id", ) files = {"poe_id": poeid_filepart} _, result = cert_store.do_prepare( requests.Request("POST", url=self.url, files=files).prepare(), ) self.assertTrue(result["ErrCode"])
def test_do_prepare_succ(self): mock_send = mock.Mock( return_value=Response(self.status_ok, json.dumps(self.resp))) mock_run_cmd = mock.Mock( side_effect=[self.cipher, json.dumps(self.resp)]) cert_store = Client(self.apikey, self.cert_path, self.uri) with mock.patch('cryption.crypto.run_cmd', mock_run_cmd): with mock.patch('requests.Session.send', mock_send): poeid_filepart = ( "", "poe id", ) files = {"poe_id": poeid_filepart} _, result = cert_store.do_prepare( requests.Request("POST", url=self.url, files=files).prepare(), ) self.assertEqual(0, result["ErrCode"])