forked from github/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_auth.py
44 lines (33 loc) · 1.27 KB
/
test_auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Test cases for the auth module."""
import unittest
from unittest.mock import patch
import auth
class TestAuth(unittest.TestCase):
"""
Test case for the auth module.
"""
@patch("github3.login")
def test_auth_to_github_with_token(self, mock_login):
"""
Test the auth_to_github function when the token is provided.
"""
mock_login.return_value = "Authenticated to GitHub.com"
result = auth.auth_to_github("token", "")
self.assertEqual(result, "Authenticated to GitHub.com")
def test_auth_to_github_without_token(self):
"""
Test the auth_to_github function when the token is not provided.
Expect a ValueError to be raised.
"""
with self.assertRaises(ValueError):
auth.auth_to_github("", "")
@patch("github3.github.GitHubEnterprise")
def test_auth_to_github_with_ghe(self, mock_ghe):
"""
Test the auth_to_github function when the GitHub Enterprise URL is provided.
"""
mock_ghe.return_value = "Authenticated to GitHub Enterprise"
result = auth.auth_to_github("token", "https://github.example.com")
self.assertEqual(result, "Authenticated to GitHub Enterprise")
if __name__ == "__main__":
unittest.main()