8000 Migrated test cases for GitHubEnterprise · runt18/github3.py@7abe2a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7abe2a6

Browse files
Migrated test cases for GitHubEnterprise
Add fixture for enterprise_url - https://enterprise.github3.com Added integration test for admin_stats
1 parent b22a3a0 commit 7abe2a6

File tree

7 files changed

+72
-55
lines changed

7 files changed

+72
-55
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions": [{"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "User-Agent": "github3.py/1.0.0a2", "Accept-Charset": "utf-8", "Connection": "keep-alive", "Content-Type": "application/json", "Authorization": "token <AUTH_TOKEN>"}, "method": "GET", "uri": "https://enterprise.github3.com/api/v3/enterprise/stats/all"}, "response": {"body": {"string": "{\"repos\":{\"total_repos\":0,\"root_repos\":0,\"fork_repos\":0,\"org_repos\":0,\"total_pushes\":0,\"total_wikis\":0},\"hooks\":{\"total_hooks\":0,\"active_hooks\":0,\"inactive_hooks\":0},\"pages\":{\"total_pages\":0},\"orgs\":{\"total_orgs\":1,\"disabled_orgs\":0,\"total_teams\":0,\"total_team_members\":0},\"users\":{\"total_users\":2,\"admin_users\":2,\"suspended_users\":0},\"pulls\":{\"total_pulls\":0,\"merged_pulls\":0,\"mergeable_pulls\":0,\"unmergeable_pulls\":0},\"issues\":{\"total_issues\":0,\"open_issues\":0,\"closed_issues\":0},\"milestones\":{\"total_milestones\":0,\"open_milestones\":0,\"closed_milestones\":0},\"gists\":{\"total_gists\":0,\"private_gists\":0,\"public_gists\":0},\"comments\":{\"total_commit_comments\":0,\"total_gist_comments\":0,\"total_issue_comments\":0,\"total_pull_request_comments\":0}}", "encoding": "utf-8"}, "headers": {"status": "200 OK", "content-length": "741", "x-github-media-type": "github.v3; param=full; format=json", "x-content-type-options": "nosniff", "content-security-policy": "default-src 'none'", "access-control-expose-headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "x-github-request-id": "721c8ffc-58a8-4701-a1ee-27f4c4d57484", "strict-transport-security": "max-age=31536000; includeSubdomains; preload", "vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "x-accepted-oauth-scopes": "", "server": "GitHub.com", "cache-control": "private, max-age=60, s-maxage=60", "etag": "\"90d27a5ed3bddd8b471b01390ab05c64\"", "x-oauth-scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user", "access-control-allow-credentials": "true", "date": "Sat, 09 Jan 2016 14:29:23 GMT", "x-frame-options": "deny", "access-control-allow-origin": "*", "content-type": "application/json; charset=utf-8", "x-xss-protection": "1; mode=block"}, "status": {"message": "OK", "code": 200}, "url": "https://enterprise.github3.com/api/v3/enterprise/stats/all"}, "recorded_at": "2016-01-09T14:29:24"}], "recorded_with": "betamax/0.5.0"}

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ def betamax_simple_body(request):
3636
request.cls.betamax_simple_body = {
3737
'match_requests_on': ['uri', 'method', 'body']
3838
}
39+
40+
41+
@pytest.fixture
42+
def enterprise_url(request):
43+
"""Configure class with enterprise url."""
44+
request.cls.enterprise_url = 'https://enterprise.github3.com'

tests/integration/helper.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,10 @@ def match(self, request, recorded_request):
5454

5555

5656
betamax.Betamax.register_request_matcher(CustomHeadersMatcher)
57+
58+
59+
@pytest.mark.usefixtures('enterprise_url')
60+
class GitHubEnterpriseHelper(IntegrationHelper):
61+
62+
def get_client(self):
63+
return github3.GitHubEnterprise(self.enterprise_url)

tests/integration/test_github.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import github3
44
import uritemplate
55

6-
from .helper import IntegrationHelper
6+
from .helper import GitHubEnterpriseHelper, IntegrationHelper
77

88

99
SSH_KEY = (
@@ -569,3 +569,14 @@ def test_zen(self):
569569

570570
assert z is not None
571571
assert z != ''
572+
573+
574+
class TestGitHubEnterprise(GitHubEnterpriseHelper):
575+
576+
def test_admin_stats(self):
577+
cassette_name = self.cassette_name('admin_stats')
578+
self.token_login()
8000 579+
with self.recorder.use_cassette(cassette_name):
580+
stats = self.gh.admin_stats('all')
581+
582+
assert isinstance(stats, dict)

tests/test_github.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,6 @@
33
from tests.utils import BaseCase
44

55

6-
def merge(first, second=None, **kwargs):
7-
copy = first.copy()
8-
copy.update(second or {})
9-
copy.update(kwargs)
10-
return copy
11-
12-
13-
class TestGitHubEnterprise(BaseCase):
14-
def setUp(self):
15-
super(TestGitHubEnterprise, self).setUp()
16-
self.g = github3.GitHubEnterprise('https://github.example.com:8080/')
17-
18-
def test_admin_stats(self):
19-
self.response('user')
20-
self.get('https://github.example.com:8080/api/v3/enterprise/stats/all')
21-
22-
self.assertRaises(github3.GitHubError, self.g.admin_stats, None)
23-
24-
self.not_called()
25-
self.login()
26-
assert isinstance(self.g.admin_stats('all'), dict)
27-
self.mock_assertions()
28-
29-
def test_repr(self):
30-
assert repr(self.g).startswith('<GitHub Enterprise')
31-
32-
def test_pubsubhubbub(self):
33-
self.response('', 204)
34-
self.post('https://github.example.com:8080/api/v3/hub')
35-
body = [('hub.mode', 'subscribe'),
36-
('hub.topic',
37-
'https://github.example.com:8080/foo/bar/events/push'),
38-
('hub.callback', 'https://localhost/post')]
39-
self.conf = {}
40-
41-
self.login()
42-
43-
d = dict([(k[4:], v) for k, v in body])
44-
assert self.g.pubsubhubbub(**d)
45-
_, kwargs = self.request.call_args
46-
assert 'data' in kwargs
47-
assert body == kwargs['data']
48-
self.mock_assertions()
49-
50-
d['secret'] = 'secret'
51-
body.append(('hub.secret', 'secret'))
52-
assert self.g.pubsubhubbub(**d)
53-
_, kwargs = self.request.call_args
54-
assert 'data' in kwargs
55-
assert body == kwargs['data']
56-
self.mock_assertions()
57-
58-
596
class TestUnsecureGitHubEnterprise(BaseCase):
607
def setUp(self):
618
super(TestUnsecureGitHubEnterprise, self).setUp()

tests/unit/helper.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import github3
77
import json
88
import os.path
9+
import pytest
910
import unittest
1011

1112

@@ -230,3 +231,27 @@ def setUp(self):
230231
self.described_class._build_url = build_url
231232
self.after_setup()
232233
pass
234+
235+
236+
@pytest.mark.usefixtures('enterprise_url')
237+
class UnitGitHubEnterpriseHelper(UnitHelper):
238+
239+
def build_url(self, *args, **kwargs):
240+
"""A function to proxy to the actual GitHubSession#build_url method."""
241+
# We want to assert what is happening with the actual calls to the
242+
# Internet. We can proxy this.
243+
return github3.session.GitHubSession().build_url(
244+
*args,
245+
base_url=self.enterprise_url,
246+
**kwargs
247+
)
248+
249+
def setUp(self):
250+
self.session = self.create_session_mock()
251+
self.instance = github3.GitHubEnterprise(self.enterprise_url)
252+
self.instance.session = self.session
253+
# Proxy the build_url method to the class so it can build the URL and
254+
# we can assert things about the call that will be attempted to the
255+
# internet
256+
self.instance._build_url = self.build_url
257+
self.after_setup()

tests/unit/test_github.py

Expand all lines: tests/unit/test_github.py
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from github3 import AuthenticationFailed, GitHubError
3+
from github3 import AuthenticationFailed, GitHubEnterprise, GitHubError
44
from github3.github import GitHub
55

66
from . import helper
@@ -10,6 +10,8 @@ def url_for(path=''):
1010
"""Simple function to generate URLs with the base GitHub URL."""
1111
return 'https://api.github.com/' + path.strip('/')
1212

13+
enterprise_url_for = helper.create_url_helper('https://enterprise.github3.com')
14+
1315

1416
class TestGitHub(helper.UnitHelper):
1517
described_class = GitHub
@@ -1360,3 +1362,21 @@ def test_revoke_authorizations(self):
13601362
self.session.temporary_basic_auth.assert_called_once_with(
13611363
'id', 'secret'
13621364
)
1365+
1366+
1367+
class TestGitHubEnterprise(helper.UnitGitHubEnterpriseHelper):
1368+
1369+
described_class = GitHubEnterprise
1370+
1371+
def test_admin_stats(self):
1372+
"""Verify the request for checking admin stats."""
1373+
self.instance.admin_stats(option='all')
1374+
self.session.get.assert_called_once_with(
1375+
enterprise_url_for('enterprise/stats/all')
1376+
)
1377+
1378+
def test_str(self):
1379+
"""Show that instance string is formatted correctly."""
1380+
assert str(self.instance) == '<GitHub Enterprise [{0}]>'.format(
1381+
enterprise_url_for()
1382+
)

0 commit comments

Comments
 (0)
0