48 lines
2.1 KiB
Python
48 lines
2.1 KiB
Python
import unittest
|
|
|
|
from util.config.oauth import GithubOAuthConfig
|
|
|
|
class TestGithub(unittest.TestCase):
|
|
def test_basic_enterprise_config(self):
|
|
config = {
|
|
'GITHUB_TRIGGER_CONFIG': {
|
|
'GITHUB_ENDPOINT': 'https://github.somedomain.com/',
|
|
'CLIENT_ID': 'someclientid',
|
|
'CLIENT_SECRET': 'someclientsecret',
|
|
}
|
|
}
|
|
|
|
github_trigger = GithubOAuthConfig(config, 'GITHUB_TRIGGER_CONFIG')
|
|
self.assertTrue(github_trigger.is_enterprise())
|
|
self.assertEquals('https://github.somedomain.com/login/oauth/authorize?', github_trigger.authorize_endpoint())
|
|
self.assertEquals('https://github.somedomain.com/login/oauth/access_token', github_trigger.token_endpoint())
|
|
|
|
self.assertEquals('https://github.somedomain.com/api/v3', github_trigger.api_endpoint())
|
|
|
|
self.assertEquals('https://github.somedomain.com/api/v3/user', github_trigger.user_endpoint())
|
|
self.assertEquals('https://github.somedomain.com/api/v3/user/emails', github_trigger.email_endpoint())
|
|
self.assertEquals('https://github.somedomain.com/api/v3/user/orgs', github_trigger.orgs_endpoint())
|
|
|
|
def test_custom_enterprise_config(self):
|
|
config = {
|
|
'GITHUB_TRIGGER_CONFIG': {
|
|
'GITHUB_ENDPOINT': 'https://github.somedomain.com/',
|
|
'API_ENDPOINT': 'http://somedomain.com/api',
|
|
'CLIENT_ID': 'someclientid',
|
|
'CLIENT_SECRET': 'someclientsecret',
|
|
}
|
|
}
|
|
|
|
github_trigger = GithubOAuthConfig(config, 'GITHUB_TRIGGER_CONFIG')
|
|
self.assertTrue(github_trigger.is_enterprise())
|
|
self.assertEquals('https://github.somedomain.com/login/oauth/authorize?', github_trigger.authorize_endpoint())
|
|
self.assertEquals('https://github.somedomain.com/login/oauth/access_token', github_trigger.token_endpoint())
|
|
|
|
self.assertEquals('http://somedomain.com/api', github_trigger.api_endpoint())
|
|
|
|
self.assertEquals('http://somedomain.com/api/user', github_trigger.user_endpoint())
|
|
self.assertEquals('http://somedomain.com/api/user/emails', github_trigger.email_endpoint())
|
|
self.assertEquals('http://somedomain.com/api/user/orgs', github_trigger.orgs_endpoint())
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|