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

Commitff9e4ff

Browse files
committed
Unit tests!
1 parent451a815 commitff9e4ff

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

‎tests/unit/test_github_session.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
importpytest
22

33
importrequests
4+
45
fromgithub3importsession
6+
frommockimportpatch,Mock
57

68

79
classTestGitHubSession:
@@ -70,6 +72,49 @@ def test_basic_login(self):
7072
s.basic_auth('username','password')
7173
asserts.auth== ('username','password')
7274

75+
@patch.object(requests.Session,'request')
76+
deftest_handle_two_factor_auth(self,request_mock):
77+
"""Test the method that handles getting the 2fa code"""
78+
s=self.build_session()
79+
s.two_factor_auth_callback(lambda:'fake')
80+
args= ('GET','http://example.com')
81+
s.handle_two_factor_auth(args, {})
82+
request_mock.assert_called_once_with(
83+
*args,
84+
headers={'X-GitHub-OTP':'fake'}
85+
)
86+
87+
@patch.object(requests.Session,'request')
88+
deftest_request_ignores_responses_that_do_not_require_2fa(self,
89+
request_mock):
90+
"""Test that request does not try to handle 2fa when it should not"""
91+
response=Mock()
92+
response.configure_mock(status_code=200,headers={})
93+
request_mock.return_value=response
94+
s=self.build_session()
95+
s.two_factor_auth_callback(lambda:'fake')
96+
r=s.get('http://example.com')
97+
assertrisresponse
98+
request_mock.assert_called_once_with(
99+
'GET','http://example.com',allow_redirects=True
100+
)
101+
102+
@patch.object(requests.Session,'request')
103+
deftest_creates_history_while_handling_2fa(self,request_mock):
104+
"""Test that the overridden request method will create history"""
105+
response=Mock()
106+
response.configure_mock(
107+
status_code=401,
108+
headers={'X-GitHub-OTP':'required;2fa'},
109+
history=[]
110+
)
111+
request_mock.return_value=response
112+
s=self.build_session()
113+
s.two_factor_auth_callback(lambda:'fake')
114+
r=s.get('http://example.com')
115+
assertlen(r.history)!=0
116+
assertrequest_mock.call_count==2
117+
73118
deftest_token_auth(self):
74119
"""Test that token auth will work with a valid token"""
75120
s=self.build_session()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp