@@ -72,6 +72,18 @@ def test_basic_login(self):
7272 s .basic_auth ('username' , 'password' )
7373 assert s .auth == ('username' , 'password' )
7474
75+ def test_basic_login_disables_token_auth (self ):
76+ """Test that basic auth will remove the Authorization header.
77+
78+ Token and basic authentication will conflict so remove the token
79+ authentication.
80+ """
81+ s = self .build_session ()
82+ s .token_auth ('token goes here' )
83+ assert 'Authorization' in s .headers
84+ s .basic_auth ('username' , 'password' )
85+ assert 'Authorization' not in s .headers
86+
7587 @patch .object (requests .Session , 'request' )
7688 def test_handle_two_factor_auth (self , request_mock ):
7789 """Test the method that handles getting the 2fa code"""
@@ -121,6 +133,16 @@ def test_token_auth(self):
121133 s .token_auth ('token goes here' )
122134 assert s .headers ['Authorization' ] == 'token token goes here'
123135
136+ def test_token_auth_disables_basic_auth (self ):
137+ """Test that using token auth removes the value of the auth attribute.
138+
139+ If `GitHubSession.auth` is set then it conflicts with the token value.
140+ """
141+ s = self .build_session ()
142+ s .auth = ('foo' , 'bar' )
143+ s .token_auth ('token goes here' )
144+ assert s .auth is None
145+
124146 def test_token_auth_does_not_use_falsey_values (self ):
125147 """Test that token auth will not authenticate with falsey values"""
126148 bad_tokens = [None , '' ]
0 commit comments