Skip to content

Commit

Permalink
reordered tests to match order of methods in git.py
Browse files Browse the repository at this point in the history
  • Loading branch information
math-foo committed Apr 29, 2015
1 parent 70ee50c commit 0e992d7
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions ide/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,6 @@
import git


@patch('ide.git.get_github')
@patch('ide.git.git_verify_tokens')
class CreateRepoTest(TestCase):
def test_expected_call(self, mock_verify_tokens, mock_get_github):
mock_user = MagicMock()
mock_github = Mock()
mock_github.get_user = Mock(return_value=mock_user)
mock_get_github.return_value = mock_github

self.assertTrue(git.create_repo("user", "repo", "description"))

mock_verify_tokens.called_once_with("user")
mock_get_github.called_once_with("user")
mock_user.create_repo.called_once_with("repo", description="description", auto_init=True)


@patch('ide.git.git_verify_tokens')
class GitAuthCheckTest(TestCase):
def setUp(self):
Expand Down Expand Up @@ -62,7 +46,6 @@ def test_successful_auth_check(self, mock_verify_tokens):
self.assertItemsEqual(self.mock_user.github.delete.call_args_list, [])



@patch('ide.git.urllib2.urlopen')
@patch('ide.git.json.loads')
@patch('ide.git.urllib2.Request')
Expand Down Expand Up @@ -131,6 +114,21 @@ def test_github_token_verified(self, request_mock, loads_mock, urlopen_mock):
urlopen_mock.called_once_with(request_mock)


class GetGithubTest(TestCase):
def setUp(self):
self.mock_user = Mock()
self.mock_user.github = Mock()
self.mock_user.github.token = "12345"

@patch('ide.git.Github')
def test_get_github_basic(self, mock_github):
test_result = git.get_github(self.mock_user)
mock_github.assert_called_once_with(
"12345",
client_id=settings.GITHUB_CLIENT_ID,
client_secret=settings.GITHUB_CLIENT_SECRET)


@patch('ide.git.get_github')
class CheckRepoAccessTest(TestCase):
def setUp(self):
Expand Down Expand Up @@ -180,19 +178,6 @@ def test_get_repo_error(self, mock_get_github):
self.mock_github.get_repo.called_once_with(self.repo_name)
self.assertItemsEqual(self.mock_repo.call_args_list, [])

class GetGithubTest(TestCase):
def setUp(self):
self.mock_user = Mock()
self.mock_user.github = Mock()
self.mock_user.github.token = "12345"

@patch('ide.git.Github')
def test_get_github_basic(self, mock_github):
test_result = git.get_github(self.mock_user)
mock_github.assert_called_once_with(
"12345",
client_id=settings.GITHUB_CLIENT_ID,
client_secret=settings.GITHUB_CLIENT_SECRET)

class UrlToReposTest(TestCase):
def test_basic_url_to_repo(self):
Expand All @@ -217,3 +202,19 @@ def test_bad_url_to_repo(self):
Tests that a entirely different url returns None.
"""
self.assertEqual(None, git.url_to_repo("http://www.cuteoverload.com"))


@patch('ide.git.get_github')
@patch('ide.git.git_verify_tokens')
class CreateRepoTest(TestCase):
def test_expected_call(self, mock_verify_tokens, mock_get_github):
mock_user = MagicMock()
mock_github = Mock()
mock_github.get_user = Mock(return_value=mock_user)
mock_get_github.return_value = mock_github

self.assertTrue(git.create_repo("user", "repo", "description"))

mock_verify_tokens.called_once_with("user")
mock_get_github.called_once_with("user")
mock_user.create_repo.called_once_with("repo", description="description", auto_init=True)

0 comments on commit 0e992d7

Please sign in to comment.