88import git
99
1010
11- @patch ('ide.git.get_github' )
12- @patch ('ide.git.git_verify_tokens' )
13- class CreateRepoTest (TestCase ):
14- def test_expected_call (self , mock_verify_tokens , mock_get_github ):
15- mock_user = MagicMock ()
16- mock_github = Mock ()
17- mock_github .get_user = Mock (return_value = mock_user )
18- mock_get_github .return_value = mock_github
19-
20- self .assertTrue (git .create_repo ("user" , "repo" , "description" ))
21-
22- mock_verify_tokens .called_once_with ("user" )
23- mock_get_github .called_once_with ("user" )
24- mock_user .create_repo .called_once_with ("repo" , description = "description" , auto_init = True )
25-
26-
2711@patch ('ide.git.git_verify_tokens' )
2812class GitAuthCheckTest (TestCase ):
2913 def setUp (self ):
@@ -62,7 +46,6 @@ def test_successful_auth_check(self, mock_verify_tokens):
6246 self .assertItemsEqual (self .mock_user .github .delete .call_args_list , [])
6347
6448
65-
6649@patch ('ide.git.urllib2.urlopen' )
6750@patch ('ide.git.json.loads' )
6851@patch ('ide.git.urllib2.Request' )
@@ -131,6 +114,21 @@ def test_github_token_verified(self, request_mock, loads_mock, urlopen_mock):
131114 urlopen_mock .called_once_with (request_mock )
132115
133116
117+ class GetGithubTest (TestCase ):
118+ def setUp (self ):
119+ self .mock_user = Mock ()
120+ self .mock_user .github = Mock ()
121+ self .mock_user .github .token = "12345"
122+
123+ @patch ('ide.git.Github' )
124+ def test_get_github_basic (self , mock_github ):
125+ test_result = git .get_github (self .mock_user )
126+ mock_github .assert_called_once_with (
127+ "12345" ,
128+ client_id = settings .GITHUB_CLIENT_ID ,
129+ client_secret = settings .GITHUB_CLIENT_SECRET )
130+
131+
134132@patch ('ide.git.get_github' )
135133class CheckRepoAccessTest (TestCase ):
136134 def setUp (self ):
@@ -180,19 +178,6 @@ def test_get_repo_error(self, mock_get_github):
180178 self .mock_github .get_repo .called_once_with (self .repo_name )
181179 self .assertItemsEqual (self .mock_repo .call_args_list , [])
182180
183- class GetGithubTest (TestCase ):
184- def setUp (self ):
185- self .mock_user = Mock ()
186- self .mock_user .github = Mock ()
187- self .mock_user .github .token = "12345"
188-
189- @patch ('ide.git.Github' )
190- def test_get_github_basic (self , mock_github ):
191- test_result = git .get_github (self .mock_user )
192- mock_github .assert_called_once_with (
193- "12345" ,
194- client_id = settings .GITHUB_CLIENT_ID ,
195- client_secret = settings .GITHUB_CLIENT_SECRET )
196181
197182class UrlToReposTest (TestCase ):
198183 def test_basic_url_to_repo (self ):
@@ -217,3 +202,19 @@ def test_bad_url_to_repo(self):
217202 Tests that a entirely different url returns None.
218203 """
219204 self .assertEqual (None , git .url_to_repo ("http://www.cuteoverload.com" ))
205+
206+
207+ @patch ('ide.git.get_github' )
208+ @patch ('ide.git.git_verify_tokens' )
209+ class CreateRepoTest (TestCase ):
210+ def test_expected_call (self , mock_verify_tokens , mock_get_github ):
211+ mock_user = MagicMock ()
212+ mock_github = Mock ()
213+ mock_github .get_user = Mock (return_value = mock_user )
214+ mock_get_github .return_value = mock_github
215+
216+ self .assertTrue (git .create_repo ("user" , "repo" , "description" ))
217+
218+ mock_verify_tokens .called_once_with ("user" )
219+ mock_get_github .called_once_with ("user" )
220+ mock_user .create_repo .called_once_with ("repo" , description = "description" , auto_init = True )
0 commit comments