diff options
author | 2012-02-12 17:53:07 +0100 | |
---|---|---|
committer | 2012-02-12 18:37:02 +0100 | |
commit | 3371f0aabc61dfc8549f0752ccc83aef06df61e8 (patch) | |
tree | 1fa6291a13ca8f3acdf2eed459be2ea08b7602d0 /pygithub3/tests | |
parent | Support to map `self` in resources. (diff) | |
download | python-github3-3371f0aabc61dfc8549f0752ccc83aef06df61e8.tar.xz python-github3-3371f0aabc61dfc8549f0752ccc83aef06df61e8.zip |
Repos service initialized
+service.repos.repo
Diffstat (limited to 'pygithub3/tests')
-rw-r--r-- | pygithub3/tests/services/test_repos.py | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/pygithub3/tests/services/test_repos.py b/pygithub3/tests/services/test_repos.py new file mode 100644 index 0000000..af7c0b0 --- /dev/null +++ b/pygithub3/tests/services/test_repos.py @@ -0,0 +1,140 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +from unittest import TestCase + +import requests +from mock import patch, Mock + +from pygithub3.services.repos import Repo +from pygithub3.resources.base import json +from pygithub3.tests.utils.base import mock_response, mock_response_result +from pygithub3.tests.utils.services import _, mock_json + +json.dumps = Mock(side_effect=mock_json) +json.loads = Mock(side_effect=mock_json) + + +@patch.object(requests.sessions.Session, 'request') +class TestRepoService(TestCase): + + def setUp(self): + self.rs = Repo() + self.rs.set_user('octocat') + self.rs.set_repo('octocat_repo') + + def test_LIST_without_user(self, request_method): + request_method.return_value = mock_response_result() + self.rs.set_user('') + self.rs.list().all() + self.assertEqual(request_method.call_args[0], ('get', _('user/repos'))) + + def test_LIST_with_user_in_args(self, request_method): + request_method.return_value = mock_response_result() + self.rs.list('octoc').all() + self.assertEqual(request_method.call_args[0], + ('get', _('users/octoc/repos'))) + + def test_LIST_with_user_in_service(self, request_method): + request_method.return_value = mock_response_result() + self.rs.list().all() + self.assertEqual(request_method.call_args[0], + ('get', _('users/octocat/repos'))) + + def test_LIST_filters(self, request_method): + request_method.return_value = mock_response_result() + self.rs.list('octoc', type='public').all() + self.assertEqual(request_method.call_args[0], + ('get', _('users/octoc/repos'))) + self.assertEqual(request_method.call_args[1]['params']['type'], + 'public') + + def test_LIST_BY_ORG(self, request_method): + request_method.return_value = mock_response_result() + self.rs.list_by_org('org_name').all() + self.assertEqual(request_method.call_args[0], + ('get', _('orgs/org_name/repos'))) + + def test_LIST_BY_ORG_filters(self, request_method): + request_method.return_value = mock_response_result() + self.rs.list_by_org('org_name', type='public').all() + self.assertEqual(request_method.call_args[0], + ('get', _('orgs/org_name/repos'))) + self.assertEqual(request_method.call_args[1]['params']['type'], + 'public') + + def test_CREATE(self, request_method): + request_method.return_value = mock_response('post') + self.rs.create({'name': 'test'}) + self.assertEqual(request_method.call_args[0], + ('post', _('user/repos'))) + + def test_CREATE_in_org(self, request_method): + request_method.return_value = mock_response('post') + self.rs.create({'name': 'test'}, in_org='org_name') + self.assertEqual(request_method.call_args[0], + ('post', _('orgs/org_name/repos'))) + + def test_GET_with_repo_in_args(self, request_method): + request_method.return_value = mock_response() + self.rs.get(user='user', repo='repo') + self.assertEqual(request_method.call_args[0], + ('get', _('repos/user/repo'))) + + def test_GET_with_repo_in_service(self, request_method): + request_method.return_value = mock_response() + self.rs.get() + self.assertEqual(request_method.call_args[0], + ('get', _('repos/octocat/octocat_repo'))) + + def test_UPDATE_with_repo_in_args(self, request_method): + request_method.return_value = mock_response('patch') + self.rs.update({'name': 'test'}, user='user', repo='repo') + self.assertEqual(request_method.call_args[0], + ('patch', _('repos/user/repo'))) + + def test_UPDATE_with_repo_in_service(self, request_method): + request_method.return_value = mock_response('patch') + self.rs.update({'name': 'test'}) + self.assertEqual(request_method.call_args[0], + ('patch', _('repos/octocat/octocat_repo'))) + + """ From here I stop to do '*in_args' and '*filter' tests, I consider + that I tested it enough... """ + + def test_LIST_contributors(self, request_method): + request_method.return_value = mock_response_result() + self.rs.list_contributors().all() + self.assertEqual(request_method.call_args[0], + ('get', _('repos/octocat/octocat_repo/contributors'))) + + def test_LIST_contributors_with_anonymous(self, request_method): + request_method.return_value = mock_response_result() + self.rs.list_contributors_with_anonymous().all() + self.assertEqual(request_method.call_args[0], + ('get', _('repos/octocat/octocat_repo/contributors'))) + self.assertEqual(request_method.call_args[1]['params']['anom'], True) + + def test_LIST_languages(self, request_method): + request_method.return_value = mock_response() + self.rs.list_languages() + self.assertEqual(request_method.call_args[0], + ('get', _('repos/octocat/octocat_repo/languages'))) + + def test_LIST_teams(self, request_method): + request_method.return_value = mock_response_result() + self.rs.list_teams().all() + self.assertEqual(request_method.call_args[0], + ('get', _('repos/octocat/octocat_repo/teams'))) + + def test_LIST_tags(self, request_method): + request_method.return_value = mock_response_result() + self.rs.list_tags().all() + self.assertEqual(request_method.call_args[0], + ('get', _('repos/octocat/octocat_repo/tags'))) + + def test_LIST_branches(self, request_method): + request_method.return_value = mock_response_result() + self.rs.list_branches().all() + self.assertEqual(request_method.call_args[0], + ('get', _('repos/octocat/octocat_repo/branches'))) |