コード例 #1
0
def test_login_without_settings_params():
    with pytest.raises(github.GitHubApiError) as e, \
            patch("taiga_contrib_github_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 = github.login("*access-code*", "**client-id**", "*ient-secret*", github.HEADERS)
    assert e.value.status_code == 400
    assert "error_message" in e.value.detail
コード例 #2
0
def test_login_without_settings_params():
    with pytest.raises(github.GitHubApiError) as e, \
            patch("taiga_contrib_github_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 = github.login("*access-code*", "**client-id**",
                                 "*ient-secret*", github.HEADERS)
    assert e.value.status_code == 400
    assert "error_message" in e.value.detail
コード例 #3
0
def test_login_whit_errors():
    with pytest.raises(github.GitHubApiError) as e, \
            patch("taiga_contrib_github_auth.connector.requests") as m_requests, \
            patch("taiga_contrib_github_auth.connector.CLIENT_ID") as CLIENT_ID, \
            patch("taiga_contrib_github_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 = github.login("*access-code*", "**client-id**", "*ient-secret*", github.HEADERS)
    assert e.value.status_code == 400
    assert e.value.detail["status_code"] == 200
    assert e.value.detail["error"] == "Invalid credentials"
コード例 #4
0
def test_login_whit_errors():
    with pytest.raises(github.GitHubApiError) as e, \
            patch("taiga_contrib_github_auth.connector.requests") as m_requests, \
            patch("taiga_contrib_github_auth.connector.CLIENT_ID") as CLIENT_ID, \
            patch("taiga_contrib_github_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 = github.login("*access-code*", "**client-id**",
                                 "*ient-secret*", github.HEADERS)
    assert e.value.status_code == 400
    assert e.value.detail["status_code"] == 200
    assert e.value.detail["error"] == "Invalid credentials"
コード例 #5
0
def test_login_success():
    with patch("taiga_contrib_github_auth.connector.requests") as m_requests, \
            patch("taiga_contrib_github_auth.connector.CLIENT_ID") as CLIENT_ID, \
            patch("taiga_contrib_github_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 = github.login("*access-code*", "**client-id**", "*client-secret*", github.HEADERS)

        assert auth_info.access_token == "xxxxxxxx"
        m_requests.post.assert_called_once_with("https://github.com/login/oauth/access_token",
                                                headers=github.HEADERS,
                                                params={'code': '*access-code*',
                                                        'scope': 'user:emails',
                                                        'client_id': '**client-id**',
                                                        'client_secret': '*client-secret*'})
コード例 #6
0
def test_login_success():
    with patch("taiga_contrib_github_auth.connector.requests") as m_requests, \
            patch("taiga_contrib_github_auth.connector.CLIENT_ID") as CLIENT_ID, \
            patch("taiga_contrib_github_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 = github.login("*access-code*", "**client-id**",
                                 "*client-secret*", github.HEADERS)

        assert auth_info.access_token == "xxxxxxxx"
        m_requests.post.assert_called_once_with(
            "https://github.com/login/oauth/access_token",
            headers=github.HEADERS,
            params={
                'code': '*access-code*',
                'scope': 'user:emails',
                'client_id': '**client-id**',
                'client_secret': '*client-secret*'
            })