コード例 #1
0
def test_get_user_profile_whit_errors():
    with pytest.raises(slack.slackApiError) as e, \
            patch("taiga_contrib_slack_auth.connector.requests") as m_requests:
        m_requests.get.return_value = m_response = Mock()
        m_response.status_code = 401
        m_response.json.return_value = {"error": "Invalid credentials"}

        auth_info = slack.get_user_profile(slack.HEADERS)
    assert e.value.status_code == 400
    assert e.value.detail["status_code"] == 401
    assert e.value.detail["error"] == "Invalid credentials"
コード例 #2
0
def test_get_user_profile_success():
    with patch("taiga_contrib_slack_auth.connector.requests") as m_requests:
        m_requests.get.return_value = m_response = Mock()
        m_response.status_code = 200
        m_response.json.return_value = {"id": 1955,
                                        "login": "******",
                                        "name": "martin seamus mcfly",
                                        "bio": "time traveler"}

        user_profile = slack.get_user_profile(slack.HEADERS)

        assert user_profile.id == 1955
        assert user_profile.username == "mmcfly"
        assert user_profile.full_name == "martin seamus mcfly"
        assert user_profile.bio == "time traveler"
        m_requests.get.assert_called_once_with("https://api.slack.com/user",
                                               headers=slack.HEADERS)