aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3/tests/services/test_orgs.py
blob: 7f5f7af3aace60782c4ce06a23c46f66a9d5571c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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')))