aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3/tests
diff options
context:
space:
mode:
authorDavid Medina <davidmedina9@gmail.com>2012-05-27 21:39:03 +0200
committerDavid Medina <davidmedina9@gmail.com>2012-05-27 21:39:31 +0200
commitac2b75a6527e8ce916b7675dac247d37276a3aa2 (patch)
tree4a3ead072bcdee6f17fdac88e836f30ad435fd7f /pygithub3/tests
parentMerge pull request #11 from dsc/patch-1 (diff)
parentAuthors updated (diff)
downloadpython-github3-ac2b75a6527e8ce916b7675dac247d37276a3aa2.tar.xz
python-github3-ac2b75a6527e8ce916b7675dac247d37276a3aa2.zip
Merge 'services/orgs'
Diffstat (limited to 'pygithub3/tests')
-rw-r--r--pygithub3/tests/services/test_core.py2
-rw-r--r--pygithub3/tests/services/test_orgs.py172
2 files changed, 173 insertions, 1 deletions
diff --git a/pygithub3/tests/services/test_core.py b/pygithub3/tests/services/test_core.py
index bd95b34..8a2bbbe 100644
--- a/pygithub3/tests/services/test_core.py
+++ b/pygithub3/tests/services/test_core.py
@@ -27,7 +27,7 @@ class TestServiceCalls(TestCase):
def test_PUT(self, request_method):
self.s._put(self.r, **self.args)
- data = '' # See _put
+ data = 'PLACEHOLDER' # See _put
request_method.assert_called_with('put', _('dummyrequest'),
data=data, params=self.args)
diff --git a/pygithub3/tests/services/test_orgs.py b/pygithub3/tests/services/test_orgs.py
new file mode 100644
index 0000000..7f5f7af
--- /dev/null
+++ b/pygithub3/tests/services/test_orgs.py
@@ -0,0 +1,172 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+import requests
+from mock import patch, Mock
+
+from pygithub3.tests.utils.core import TestCase
+from pygithub3.resources.base import json
+from pygithub3.services.orgs import Org, Members, Teams
+from pygithub3.tests.utils.base import (mock_response, mock_response_result,
+ mock_json)
+from pygithub3.tests.utils.services import _
+
+json.dumps = Mock(side_effect=mock_json)
+json.loads = Mock(side_effect=mock_json)
+
+
+@patch.object(requests.sessions.Session, 'request')
+class TestOrgService(TestCase):
+ def setUp(self):
+ self.org = Org()
+
+ def test_LIST_without_user(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.org.list().all()
+ self.assertEqual(request_method.call_args[0], ('get', _('user/orgs')))
+
+ def test_LIST_with_user(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.org.list('octocat').all()
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('users/octocat/orgs')))
+
+ def test_GET(self, request_method):
+ request_method.return_value = mock_response()
+ self.org.get('acme')
+ self.assertEqual(request_method.call_args[0], ('get', _('orgs/acme')))
+
+ def test_UPDATE(self, request_method):
+ request_method.return_value = mock_response('patch')
+ self.org.update('acme', {'company': 'ACME Widgets'})
+ self.assertEqual(request_method.call_args[0],
+ ('patch', _('orgs/acme')))
+
+
+@patch.object(requests.sessions.Session, 'request')
+class TestMemberService(TestCase):
+ def setUp(self):
+ self.ms = Members()
+
+ def test_LIST(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.ms.list('acme').all()
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('orgs/acme/members')))
+
+ def test_IS_MEMBER(self, request_method):
+ request_method.return_value = mock_response()
+ self.ms.is_member('acme', 'octocat')
+ self.assertEqual(request_method.call_args[0],
+ ('head', _('orgs/acme/members/octocat')))
+
+ def test_REMOVE_MEMBER(self, request_method):
+ request_method.return_value = mock_response('delete')
+ self.ms.remove_member('acme', 'octocat')
+ self.assertEqual(request_method.call_args[0],
+ ('delete', _('orgs/acme/members/octocat')))
+
+ def test_LIST_PUBLIC(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.ms.list_public('acme').all()
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('orgs/acme/public_members')))
+
+ def test_IS_PUBLIC_MEMBER(self, request_method):
+ request_method.return_value = mock_response()
+ self.ms.is_public_member('acme', 'octocat')
+ self.assertEqual(request_method.call_args[0],
+ ('head', _('orgs/acme/public_members/octocat')))
+
+ def test_PUBLICIZE_MEMBERSHIP(self, request_method):
+ request_method.return_value = mock_response()
+ self.ms.publicize_membership('acme', 'octocat')
+ self.assertEqual(request_method.call_args[0],
+ ('put', _('orgs/acme/public_members/octocat')))
+
+ def test_CONCEAL_MEMBERSHIP(self, request_method):
+ request_method.return_value = mock_response('delete')
+ self.ms.conceal_membership('acme', 'octocat')
+ self.assertEqual(request_method.call_args[0],
+ ('delete', _('orgs/acme/public_members/octocat')))
+
+
+@patch.object(requests.sessions.Session, 'request')
+class TestTeamsService(TestCase):
+ def setUp(self):
+ self.ts = Teams()
+
+ def test_LIST(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.ts.list('acme').all()
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('orgs/acme/teams')))
+
+ def test_GET(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.ts.get(1)
+ self.assertEqual(request_method.call_args[0], ('get', _('teams/1')))
+
+ def test_CREATE(self, request_method):
+ request_method.return_value = mock_response_result('post')
+ self.ts.create('acme', dict(name='new'))
+ self.assertEqual(request_method.call_args[0],
+ ('post', _('orgs/acme/teams')))
+
+ def test_UPDATE(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.ts.update(1, dict(name='edited'))
+ self.assertEqual(request_method.call_args[0], ('patch', _('teams/1')))
+
+ def test_DELETE(self, request_method):
+ request_method.return_value = mock_response_result('delete')
+ self.ts.delete(1)
+ self.assertEqual(request_method.call_args[0], ('delete', _('teams/1')))
+
+ def test_LIST_MEMBERS(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.ts.list_members(1).all()
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('teams/1/members')))
+
+ def test_IS_MEMBER(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.ts.is_member(1, 'octocat')
+ self.assertEqual(request_method.call_args[0],
+ ('head', _('teams/1/members/octocat')))
+
+ def test_ADD_MEMBER(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.ts.add_member(1, 'octocat')
+ self.assertEqual(request_method.call_args[0],
+ ('put', _('teams/1/members/octocat')))
+
+ def test_REMOVE_MEMBER(self, request_method):
+ request_method.return_value = mock_response_result('delete')
+ self.ts.remove_member(1, 'octocat')
+ self.assertEqual(request_method.call_args[0],
+ ('delete', _('teams/1/members/octocat')))
+
+ def test_LIST_REPOS(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.ts.list_repos(1).all()
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('teams/1/repos')))
+
+ def test_CONTAINS_REPO(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.ts.contains_repo(1, 'octocat', 're_oct')
+ self.assertEqual(request_method.call_args[0],
+ ('head', _('teams/1/repos/octocat/re_oct')))
+
+ def test_ADD_TEAM_REPO(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.ts.add_repo(1, 'octocat', 're_oct')
+ self.assertEqual(request_method.call_args[0],
+ ('put', _('teams/1/repos/octocat/re_oct')))
+
+ def test_REMOVE_TEAM_REPO(self, request_method):
+ request_method.return_value = mock_response_result('delete')
+ self.ts.remove_repo(1, 'octocat', 're_oct')
+ self.assertEqual(request_method.call_args[0],
+ ('delete', _('teams/1/repos/octocat/re_oct')))