Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1cb25f5

Browse files
committed
Add unit tests around GitHubSession
1 parent790bae7 commit1cb25f5

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

‎tests/unit/test_github_session.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
importpytest
2+
3+
fromgithub3importsession
4+
5+
6+
classTestGitHubSession:
7+
defbuild_session(self,base_url=None):
8+
s=session.GitHubSession()
9+
ifbase_url:
10+
s.base_url=base_url
11+
returns
12+
13+
deftest_has_default_headers(self):
14+
"""Assert the default headers are there upon initialization"""
15+
s=self.build_session()
16+
assert'Accept'ins.headers
17+
asserts.headers['Accept']=='application/vnd.github.v3.full+json'
18+
assert'Accept-Charset'ins.headers
19+
asserts.headers['Accept-Charset']=='utf-8'
20+
assert'Content-Type'ins.headers
21+
asserts.headers['Content-Type']=='application/json'
22+
assert'User-Agent'ins.headers
23+
asserts.headers['User-Agent'].startswith('github3.py/')
24+
25+
deftest_build_url(self):
26+
"""Test that GitHubSessions build basic URLs"""
27+
s=self.build_session()
28+
url=s.build_url('gists','123456','history')
29+
asserturl=='https://api.github.com/gists/123456/history'
30+
31+
deftest_build_url_caches_built_urls(self):
32+
"""Test that building a URL caches it"""
33+
s=self.build_session()
34+
url=s.build_url('gists','123456','history')
35+
url_parts= ('https://api.github.com','gists','123456','history')
36+
asserturl_partsinsession.__url_cache__
37+
asserturlinsession.__url_cache__.values()
38+
39+
deftest_build_url_uses_a_different_base(self):
40+
"""Test that you can pass in a different base URL to build_url"""
41+
s=self.build_session()
42+
url=s.build_url('gists','123456','history',
43+
base_url='https://status.github.com')
44+
asserturl=='https://status.github.com/gists/123456/history'
45+
46+
deftest_build_url_respects_the_session_base_url(self):
47+
"""Test that build_url uses the session's base_url"""
48+
s=self.build_session('https://enterprise.customer.com')
49+
url=s.build_url('gists')
50+
asserturl=='https://enterprise.customer.com/gists'
51+
52+
deftest_basic_login_does_not_use_falsey_values(self):
53+
"""Test that basic auth will not authenticate with falsey values"""
54+
bad_auths= [
55+
(None,'password'),
56+
('username',None),
57+
('','password'),
58+
('username',''),
59+
]
60+
forauthinbad_auths:
61+
# Make sure we have a clean session to test with
62+
s=self.build_session()
63+
s.basic_auth(*auth)
64+
asserts.auth!=auth
65+
66+
deftest_basic_login(self):
67+
"""Test that basic auth will work with a valid combination"""
68+
s=self.build_session()
69+
s.basic_auth('username','password')
70+
asserts.auth== ('username','password')
71+
72+
deftest_token_auth(self):
73+
"""Test that token auth will work with a valid token"""
74+
s=self.build_session()
75+
s.token_auth('token goes here')
76+
asserts.headers['Authorization']=='token token goes here'
77+
78+
deftest_token_auth_does_not_use_falsey_values(self):
79+
"""Test that token auth will not authenticate with falsey values"""
80+
bad_tokens= [None,'']
81+
fortokeninbad_tokens:
82+
s=self.build_session()
83+
s.token_auth(token)
84+
assert'Authorization'notins.headers
85+
86+
deftest_oauth2_auth(self):
87+
"""Test that oauth2 authentication works
88+
89+
For now though, it doesn't because it isn't implemented.
90+
"""
91+
s=self.build_session()
92+
withpytest.raises(NotImplementedError):
93+
s.oauth2_auth('Foo','bar')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp