def test_get_user_emails_whit_errors(): with pytest.raises(exc.GitHubApiError) as e, \ patch("taiga.base.connectors.github.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"} emails = github.get_user_emails(github.HEADERS) assert e.value.status_code == 400 assert e.value.detail["status_code"] == 401 assert e.value.detail["error"] == "Invalid credentials"
def test_get_user_emails_success(): with patch("taiga.base.connectors.github.requests") as m_requests: m_requests.get.return_value = m_response = Mock() m_response.status_code = 200 m_response.json.return_value = [{"email": "*****@*****.**", "primary": False}, {"email": "*****@*****.**", "primary": True}] emails = github.get_user_emails(github.HEADERS) assert len(emails) == 2 assert emails[0].email == "*****@*****.**" assert not emails[0].is_primary assert emails[1].email == "*****@*****.**" assert emails[1].is_primary m_requests.get.assert_called_once_with("https://api.github.com/user/emails", headers=github.HEADERS)