|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- encoding: utf-8 -*- |
| 3 | + |
| 4 | +import requests |
| 5 | +from mock import patch, Mock |
| 6 | + |
| 7 | +from pygithub3.tests.utils.core import TestCase |
| 8 | +from pygithub3.resources.base import json |
| 9 | +from pygithub3.services.orgs import Org |
| 10 | +from pygithub3.tests.utils.base import (mock_response, mock_response_result, |
| 11 | + mock_json) |
| 12 | +from pygithub3.tests.utils.services import _ |
| 13 | + |
| 14 | +json.dumps = Mock(side_effect=mock_json) |
| 15 | +json.loads = Mock(side_effect=mock_json) |
| 16 | + |
| 17 | + |
| 18 | +@patch.object(requests.sessions.Session, 'request') |
| 19 | +class TestOrgService(TestCase): |
| 20 | + |
| 21 | + def setUp(self): |
| 22 | + self.org = Org() |
| 23 | + |
| 24 | + def test_LIST_without_user(self, request_method): |
| 25 | + request_method.return_value = mock_response_result() |
| 26 | + self.org.list().all() |
| 27 | + self.assertEqual(request_method.call_args[0], ('get', _('user/orgs'))) |
| 28 | + |
| 29 | + def test_LIST_with_user(self, request_method): |
| 30 | + request_method.return_value = mock_response_result() |
| 31 | + self.org.list('octocat').all() |
| 32 | + self.assertEqual(request_method.call_args[0], |
| 33 | + ('get', _('users/octocat/orgs'))) |
| 34 | + |
| 35 | + def test_GET(self, request_method): |
| 36 | + request_method.return_value = mock_response() |
| 37 | + self.org.get('acme') |
| 38 | + self.assertEqual(request_method.call_args[0], ('get', _('orgs/acme'))) |
| 39 | + |
| 40 | + def test_UPDATE(self, request_method): |
| 41 | + request_method.return_value = mock_response('patch') |
| 42 | + self.org.update('acme', {'company': 'ACME Widgets'}) |
| 43 | + self.assertEqual(request_method.call_args[0], |
| 44 | + ('patch', _('orgs/acme'))) |
0 commit comments