def test_login_without_settings_params(): with pytest.raises(slack.slackApiError) as e, \ patch("taiga_contrib_slack_auth.connector.requests") as m_requests: m_requests.post.return_value = m_response = Mock() m_response.status_code = 200 m_response.json.return_value = {"access_token": "xxxxxxxx"} auth_info = slack.login("*access-code*", "**client-id**", "*ient-secret*", slack.HEADERS) assert e.value.status_code == 400 assert "error_message" in e.value.detail
def test_login_whit_errors(): with pytest.raises(slack.slackApiError) as e, \ patch("taiga_contrib_slack_auth.connector.requests") as m_requests, \ patch("taiga_contrib_slack_auth.connector.CLIENT_ID") as CLIENT_ID, \ patch("taiga_contrib_slack_auth.connector.CLIENT_SECRET") as CLIENT_SECRET: CLIENT_ID = "*CLIENT_ID*" CLIENT_SECRET = "*CLIENT_SECRET*" m_requests.post.return_value = m_response = Mock() m_response.status_code = 200 m_response.json.return_value = {"error": "Invalid credentials"} auth_info = slack.login("*access-code*", "**client-id**", "*ient-secret*", slack.HEADERS) assert e.value.status_code == 400 assert e.value.detail["status_code"] == 200 assert e.value.detail["error"] == "Invalid credentials"
def test_login_success(): with patch("taiga_contrib_slack_auth.connector.requests") as m_requests, \ patch("taiga_contrib_slack_auth.connector.CLIENT_ID") as CLIENT_ID, \ patch("taiga_contrib_slack_auth.connector.CLIENT_SECRET") as CLIENT_SECRET: CLIENT_ID = "*CLIENT_ID*" CLIENT_SECRET = "*CLIENT_SECRET*" m_requests.post.return_value = m_response = Mock() m_response.status_code = 200 m_response.json.return_value = {"access_token": "xxxxxxxx"} auth_info = slack.login("*access-code*", "**client-id**", "*client-secret*", slack.HEADERS) assert auth_info.access_token == "xxxxxxxx" m_requests.post.assert_called_once_with("https://slack.com/login/oauth/access_token", headers=slack.HEADERS, params={'code': '*access-code*', 'scope': 'user:emails', 'client_id': '**client-id**', 'client_secret': '*client-secret*'})