def test_failed_login_error_str_repr(self): expected = "INVALID_LOGIN: Invalid username, password, security token; or user locked out." with mock_post: try: soap_login("*****@*****.**", "pass", "XXX") except AuthenticationError as error: self.assertEqual(str(error), expected)
def test_failed_login(mock_failed_login): with pytest.raises(AuthenticationError) as err: soap_login(USERNAME, PASSWORD, TOKEN) expected = ("INVALID_LOGIN: Invalid username, password, " "security token; or user locked out.") assert str(err.value) == expected
def test_post_request_call(mock_success_login): """Test if POST request is called with expected parameters.""" soap_login(USERNAME, PASSWORD, TOKEN) mock_success_login.assert_called_with( EXPECTED_URL, headers=EXPECTED_HEADERS, data=BODY_TEMPLATE.format(USERNAME, PASSWORD, TOKEN), )
def test_authentication_with_getpass(mock_success_login, mocker): mocker.patch("reportforce.login.input", return_value=USERNAME) mocker.patch("reportforce.login.getpass", side_effect=[PASSWORD, "token<>&"]) soap_login() mock_success_login.assert_called_with( EXPECTED_URL, headers=EXPECTED_HEADERS, data=BODY_TEMPLATE.format(USERNAME, PASSWORD, "token<>&"), )
def test_escape_xml_body(mock_success_login): """ Test if POST request is called with expected parameters, when there are special XML characters in the credentials. """ soap_login("<>&", "<>&", "<>&") mock_success_login.assert_called_with( EXPECTED_URL, headers=EXPECTED_HEADERS, data=BODY_TEMPLATE.format("<>&", "<>&", "<>&"), )
def test_failed_login(requests_mock): requests_mock.post( "https://login.salesforce.com/services/Soap/u/47.0", text=FAILURE, status_code=500, ) with pytest.raises(login.AuthenticationError) as err: login.soap_login("*****@*****.**", "pass", "token") expected = ("INVALID_LOGIN: Invalid username, password, " "security token; or user locked out.") assert str(err.value) == expected
def test_xml_response_parser(mock_success_login): """ Test if function correctly get session id and instance URL from the XML response body. """ test = soap_login(USERNAME, PASSWORD, TOKEN) expected = ("sessionId", "www.salesforce.com") assert test == expected
def test_xml_response_parser(requests_mock, mocker): """Test readin session ID and instance URL from XML response.""" requests_mock.post("https://login.salesforce.com/services/Soap/u/47.0", text=SUCCESS) assert login.soap_login("*****@*****.**", "pass", "token") == ( "sessionId", "www.salesforce.com", )
def test_successful_login(self, post): post.return_value = Mock(status_code=200, text=get_login("successful.xml")) test = soap_login("*****@*****.**", "pass", "XXX") expected = ("sessionId", "dummy.salesforce.com") self.assertEqual(test, expected) post.assert_called_with(expected_url, headers=expected_headers, data=expected_body)
def test_failed_login(self): with mock_post, self.assertRaises(AuthenticationError): soap_login("*****@*****.**", "pass", "XXX")