annotate rhodecode/tests/api/api_base.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl

Imported some of the GPLv3'd changes from RhodeCode v2.2.5. This imports changes between changesets 21af6c4eab3d and 6177597791c2 in RhodeCode's original repository, including only changes to Python files and HTML. RhodeCode clearly licensed its changes to these files under GPLv3 in their /LICENSE file, which states the following: The Python code and integrated HTML are licensed under the GPLv3 license. (See: https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE or http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE for an online copy of that LICENSE file) Conservancy reviewed these changes and confirmed that they can be licensed as a whole to the Kallithea project under GPLv3-only. While some of the contents committed herein are clearly licensed GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the statement above from RhodeCode indicates that they intend GPLv3-only as their license, per GPLv3ยง14 and other relevant sections of GPLv3.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:13 -0400
parents aff5dd957f35
children da3c57422ee6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1 # -*- coding: utf-8 -*-
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2 # This program is free software: you can redistribute it and/or modify
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
3 # it under the terms of the GNU General Public License as published by
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
5 # (at your option) any later version.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
6 #
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
7 # This program is distributed in the hope that it will be useful,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
10 # GNU General Public License for more details.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
11 #
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
12 # You should have received a copy of the GNU General Public License
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
14
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
15 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
16 tests for api. run with::
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
17
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
18 RC_WHOOSH_TEST_DISABLE=1 nosetests --with-coverage --cover-package=rhodecode.controllers.api.api -x rhodecode/tests/api
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
19 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
20
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
21 from __future__ import with_statement
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
22 import os
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 import random
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 import mock
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 from rhodecode.tests import *
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
27 from rhodecode.tests.fixture import Fixture
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 from rhodecode.lib.compat import json
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 from rhodecode.lib.auth import AuthUser
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 from rhodecode.model.user import UserModel
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
31 from rhodecode.model.user_group import UserGroupModel
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 from rhodecode.model.repo import RepoModel
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
33 from rhodecode.model.repo_group import RepoGroupModel
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2526
diff changeset
34 from rhodecode.model.meta import Session
2697
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
35 from rhodecode.model.scm import ScmModel
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
36 from rhodecode.model.gist import GistModel
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
37 from rhodecode.model.db import Repository, User, RhodeCodeSetting
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
38 from rhodecode.lib.utils2 import time_to_datetime
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
40
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 API_URL = '/_admin/api'
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
42 TEST_USER_GROUP = 'test_user_group'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
43 TEST_REPO_GROUP = 'test_repo_group'
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
44
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
45 fixture = Fixture()
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 def _build_data(apikey, method, **kw):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 """
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 Builds API data with given random ID
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 :param random_id:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 """
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 random_id = random.randrange(1, 9999)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 return random_id, json.dumps({
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 "id": random_id,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 "api_key": apikey,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 "method": method,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 "args": kw
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 })
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
62
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 jsonify = lambda obj: json.loads(json.dumps(obj))
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 def crash(*args, **kwargs):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 raise Exception('Total Crash !')
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
70 def api_call(test_obj, params):
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
71 response = test_obj.app.post(API_URL, content_type='application/json',
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
72 params=params)
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
73 return response
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
74
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
75
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
76 ## helpers
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
77 def make_user_group(name=TEST_USER_GROUP):
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
78 gr = fixture.create_user_group(name, cur_user=TEST_USER_ADMIN_LOGIN)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
79 UserGroupModel().add_user_to_group(user_group=gr,
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
80 user=TEST_USER_ADMIN_LOGIN)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 Session().commit()
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 return gr
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
85 def make_repo_group(name=TEST_REPO_GROUP):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
86 gr = fixture.create_repo_group(name, cur_user=TEST_USER_ADMIN_LOGIN)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 Session().commit()
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
88 return gr
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 class BaseTestApi(object):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 REPO = None
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 REPO_TYPE = None
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 @classmethod
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
96 def setup_class(cls):
3891
aff5dd957f35 classmethods should have cls as first argument
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
97 cls.usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN)
aff5dd957f35 classmethods should have cls as first argument
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
98 cls.apikey = cls.usr.api_key
aff5dd957f35 classmethods should have cls as first argument
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
99 cls.test_user = UserModel().create_or_update(
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 username='test-api',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 password='test',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 email='test@api.rhodecode.org',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 firstname='first',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 lastname='last'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 )
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 Session().commit()
3891
aff5dd957f35 classmethods should have cls as first argument
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
107 cls.TEST_USER_LOGIN = cls.test_user.username
aff5dd957f35 classmethods should have cls as first argument
Marcin Kuzminski <marcin@python-works.com>
parents: 3840
diff changeset
108 cls.apikey_regular = cls.test_user.api_key
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 @classmethod
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
111 def teardown_class(cls):
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 pass
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114 def setUp(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115 self.maxDiff = None
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
116 make_user_group()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
117 make_repo_group()
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 def tearDown(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
120 fixture.destroy_user_group(TEST_USER_GROUP)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
121 fixture.destroy_gists()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
122 fixture.destroy_repo_group(TEST_REPO_GROUP)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
123
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
124 def _compare_ok(self, id_, expected, given):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125 expected = jsonify({
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
126 'id': id_,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
127 'error': None,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
128 'result': expected
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
129 })
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
130 given = json.loads(given)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
131 self.assertEqual(expected, given)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
132
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
133 def _compare_error(self, id_, expected, given):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
134 expected = jsonify({
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 'id': id_,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136 'error': expected,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 'result': None
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138 })
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
139 given = json.loads(given)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140 self.assertEqual(expected, given)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
142 def test_Optional_object(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
143 from rhodecode.controllers.api.api import Optional
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
144
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
145 option1 = Optional(None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
146 self.assertEqual('<Optional:%s>' % None, repr(option1))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
147 self.assertEqual(option1(), None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
148
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
149 self.assertEqual(1, Optional.extract(Optional(1)))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
150 self.assertEqual('trololo', Optional.extract('trololo'))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
151
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
152 def test_Optional_OAttr(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
153 from rhodecode.controllers.api.api import Optional, OAttr
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
154
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
155 option1 = Optional(OAttr('apiuser'))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
156 self.assertEqual('apiuser', Optional.extract(option1))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
157
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
158 def test_OAttr_object(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
159 from rhodecode.controllers.api.api import OAttr
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
160
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
161 oattr1 = OAttr('apiuser')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
162 self.assertEqual('<OptionalAttr:apiuser>', repr(oattr1))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
163 self.assertEqual(oattr1(), oattr1)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
164
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
165 def test_api_wrong_key(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
166 id_, params = _build_data('trololo', 'get_user')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
167 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
168
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
169 expected = 'Invalid API KEY'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
170 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
171
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
172 def test_api_missing_non_optional_param(self):
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
173 id_, params = _build_data(self.apikey, 'get_repo')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
174 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
175
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
176 expected = 'Missing non optional `repoid` arg in JSON DATA'
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
177 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
178
3165
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
179 def test_api_missing_non_optional_param_args_null(self):
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
180 id_, params = _build_data(self.apikey, 'get_repo')
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
181 params = params.replace('"args": {}', '"args": null')
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
182 response = api_call(self, params)
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
183
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
184 expected = 'Missing non optional `repoid` arg in JSON DATA'
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
185 self._compare_error(id_, expected, given=response.body)
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
186
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
187 def test_api_missing_non_optional_param_args_bad(self):
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
188 id_, params = _build_data(self.apikey, 'get_repo')
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
189 params = params.replace('"args": {}', '"args": 1')
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
190 response = api_call(self, params)
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
191
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
192 expected = 'Missing non optional `repoid` arg in JSON DATA'
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
193 self._compare_error(id_, expected, given=response.body)
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
194
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
195 def test_api_args_is_null(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
196 id_, params = _build_data(self.apikey, 'get_users', )
3165
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
197 params = params.replace('"args": {}', '"args": null')
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
198 response = api_call(self, params)
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
199 self.assertEqual(response.status, '200 OK')
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
200
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
201 def test_api_args_is_bad(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
202 id_, params = _build_data(self.apikey, 'get_users', )
3165
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
203 params = params.replace('"args": {}', '"args": 1')
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
204 response = api_call(self, params)
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
205 self.assertEqual(response.status, '200 OK')
e1baadec6217 fixes issue #702 API methods without arguments fail when "args":null
Marcin Kuzminski <marcin@python-works.com>
parents: 3163
diff changeset
206
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
207 def test_api_args_different_args(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
208 import string
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
209 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
210 'ascii_letters': string.ascii_letters,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
211 'ws': string.whitespace,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
212 'printables': string.printable
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
213 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
214 id_, params = _build_data(self.apikey, 'test', args=expected)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
215 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
216 self.assertEqual(response.status, '200 OK')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
217 self._compare_ok(id_, expected, response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
218
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
219 def test_api_get_users(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
220 id_, params = _build_data(self.apikey, 'get_users', )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
221 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
222 ret_all = []
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
223 _users = User.query().filter(User.username != User.DEFAULT_USER) \
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
224 .order_by(User.username).all()
3803
e2ebd8808351 fixed broken API tests after excluding default user
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
225 for usr in _users:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
226 ret = usr.get_api_data()
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
227 ret_all.append(jsonify(ret))
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
228 expected = ret_all
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
229 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
230
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
231 def test_api_get_user(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
232 id_, params = _build_data(self.apikey, 'get_user',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
233 userid=TEST_USER_ADMIN_LOGIN)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
234 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
235
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
236 usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
237 ret = usr.get_api_data()
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
238 ret['permissions'] = AuthUser(usr.user_id).permissions
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
239
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
240 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
241 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
242
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
243 def test_api_get_user_that_does_not_exist(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
244 id_, params = _build_data(self.apikey, 'get_user',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
245 userid='trololo')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
246 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
247
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
248 expected = "user `%s` does not exist" % 'trololo'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
249 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
250
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
251 def test_api_get_user_without_giving_userid(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
252 id_, params = _build_data(self.apikey, 'get_user')
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
253 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
254
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
255 usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
256 ret = usr.get_api_data()
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
257 ret['permissions'] = AuthUser(usr.user_id).permissions
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
258
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
259 expected = ret
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
260 self._compare_ok(id_, expected, given=response.body)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
261
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
262 def test_api_get_user_without_giving_userid_non_admin(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
263 id_, params = _build_data(self.apikey_regular, 'get_user')
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
264 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
265
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
266 usr = UserModel().get_by_username(self.TEST_USER_LOGIN)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
267 ret = usr.get_api_data()
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
268 ret['permissions'] = AuthUser(usr.user_id).permissions
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
269
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
270 expected = ret
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
271 self._compare_ok(id_, expected, given=response.body)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
272
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
273 def test_api_get_user_with_giving_userid_non_admin(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
274 id_, params = _build_data(self.apikey_regular, 'get_user',
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
275 userid=self.TEST_USER_LOGIN)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
276 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
277
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
278 expected = 'userid is not the same as your user'
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
279 self._compare_error(id_, expected, given=response.body)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
280
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
281 def test_api_pull(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
282 repo_name = 'test_pull'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
283 r = fixture.create_repo(repo_name, repo_type=self.REPO_TYPE)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
284 r.clone_uri = os.path.join(TESTS_TMP_PATH, self.REPO)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
285 Session.add(r)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
286 Session.commit()
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
287
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
288 id_, params = _build_data(self.apikey, 'pull',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
289 repoid=repo_name,)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
290 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
291
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
292 expected = {'msg': 'Pulled from `%s`' % repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
293 'repository': repo_name}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
294 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
295
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
296 fixture.destroy_repo(repo_name)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
297
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
298 def test_api_pull_error(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
299 id_, params = _build_data(self.apikey, 'pull',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
300 repoid=self.REPO, )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
301 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
302
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
303 expected = 'Unable to pull changes from `%s`' % self.REPO
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
304 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
305
2697
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
306 def test_api_rescan_repos(self):
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
307 id_, params = _build_data(self.apikey, 'rescan_repos')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
308 response = api_call(self, params)
2697
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
309
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
310 expected = {'added': [], 'removed': []}
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
311 self._compare_ok(id_, expected, given=response.body)
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
312
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
313 @mock.patch.object(ScmModel, 'repo_scan', crash)
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
314 def test_api_rescann_error(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
315 id_, params = _build_data(self.apikey, 'rescan_repos', )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
316 response = api_call(self, params)
2697
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
317
2737
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
318 expected = 'Error occurred during rescan repositories action'
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
319 self._compare_error(id_, expected, given=response.body)
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
320
3235
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
321 def test_api_invalidate_cache(self):
3774
60335b702a00 invalidation: don't create CacheInvalidation records on startup
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
322 repo = RepoModel().get_by_repo_name(self.REPO)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
323 repo.scm_instance_cached() # seed cache
3774
60335b702a00 invalidation: don't create CacheInvalidation records on startup
Mads Kiilerich <madski@unity3d.com>
parents: 3759
diff changeset
324
3235
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
325 id_, params = _build_data(self.apikey, 'invalidate_cache',
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
326 repoid=self.REPO)
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
327 response = api_call(self, params)
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
328
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
329 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
330 'msg': "Cache for repository `%s` was invalidated" % (self.REPO,),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
331 'repository': self.REPO
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
332 }
3235
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
333 self._compare_ok(id_, expected, given=response.body)
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
334
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
335 @mock.patch.object(ScmModel, 'mark_for_invalidation', crash)
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
336 def test_api_invalidate_cache_error(self):
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
337 id_, params = _build_data(self.apikey, 'invalidate_cache',
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
338 repoid=self.REPO)
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
339 response = api_call(self, params)
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
340
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
341 expected = 'Error occurred during cache invalidation action'
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
342 self._compare_error(id_, expected, given=response.body)
d6029dacbcc4 API invalidate_cache function ref #733
Marcin Kuzminski <marcin@python-works.com>
parents: 3216
diff changeset
343
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
344 def test_api_invalidate_cache_regular_user_no_permission(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
345 repo = RepoModel().get_by_repo_name(self.REPO)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
346 repo.scm_instance_cached() # seed cache
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
347
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
348 id_, params = _build_data(self.apikey_regular, 'invalidate_cache',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
349 repoid=self.REPO)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
350 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
351
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
352 expected = "repository `%s` does not exist" % (self.REPO,)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
353 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
354
2737
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
355 def test_api_lock_repo_lock_aquire(self):
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
356 id_, params = _build_data(self.apikey, 'lock',
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
357 userid=TEST_USER_ADMIN_LOGIN,
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
358 repoid=self.REPO,
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
359 locked=True)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
360 response = api_call(self, params)
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
361 expected = {
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
362 'repo': self.REPO, 'locked': True,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
363 'locked_since': response.json['result']['locked_since'],
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
364 'locked_by': TEST_USER_ADMIN_LOGIN,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
365 'lock_state_changed': True,
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
366 'msg': ('User `%s` set lock state for repo `%s` to `%s`'
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
367 % (TEST_USER_ADMIN_LOGIN, self.REPO, True))
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
368 }
2737
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
369 self._compare_ok(id_, expected, given=response.body)
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
370
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
371 def test_api_lock_repo_lock_aquire_by_non_admin(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
372 repo_name = 'api_delete_me'
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
373 fixture.create_repo(repo_name, repo_type=self.REPO_TYPE,
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
374 cur_user=self.TEST_USER_LOGIN)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
375 try:
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
376 id_, params = _build_data(self.apikey_regular, 'lock',
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
377 repoid=repo_name,
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
378 locked=True)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
379 response = api_call(self, params)
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
380 expected = {
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
381 'repo': repo_name,
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
382 'locked': True,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
383 'locked_since': response.json['result']['locked_since'],
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
384 'locked_by': self.TEST_USER_LOGIN,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
385 'lock_state_changed': True,
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
386 'msg': ('User `%s` set lock state for repo `%s` to `%s`'
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
387 % (self.TEST_USER_LOGIN, repo_name, True))
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
388 }
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
389 self._compare_ok(id_, expected, given=response.body)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
390 finally:
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
391 fixture.destroy_repo(repo_name)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
392
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
393 def test_api_lock_repo_lock_aquire_non_admin_with_userid(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
394 repo_name = 'api_delete_me'
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
395 fixture.create_repo(repo_name, repo_type=self.REPO_TYPE,
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
396 cur_user=self.TEST_USER_LOGIN)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
397 try:
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
398 id_, params = _build_data(self.apikey_regular, 'lock',
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
399 userid=TEST_USER_ADMIN_LOGIN,
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
400 repoid=repo_name,
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
401 locked=True)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
402 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
403 expected = 'userid is not the same as your user'
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
404 self._compare_error(id_, expected, given=response.body)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
405 finally:
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
406 fixture.destroy_repo(repo_name)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
407
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
408 def test_api_lock_repo_lock_aquire_non_admin_not_his_repo(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
409 id_, params = _build_data(self.apikey_regular, 'lock',
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
410 repoid=self.REPO,
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
411 locked=True)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
412 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
413 expected = 'repository `%s` does not exist' % (self.REPO)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
414 self._compare_error(id_, expected, given=response.body)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
415
2737
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
416 def test_api_lock_repo_lock_release(self):
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
417 id_, params = _build_data(self.apikey, 'lock',
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
418 userid=TEST_USER_ADMIN_LOGIN,
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
419 repoid=self.REPO,
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
420 locked=False)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
421 response = api_call(self, params)
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
422 expected = {
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
423 'repo': self.REPO,
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
424 'locked': False,
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
425 'locked_since': None,
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
426 'locked_by': TEST_USER_ADMIN_LOGIN,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
427 'lock_state_changed': True,
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
428 'msg': ('User `%s` set lock state for repo `%s` to `%s`'
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
429 % (TEST_USER_ADMIN_LOGIN, self.REPO, False))
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
430 }
2737
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
431 self._compare_ok(id_, expected, given=response.body)
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
432
3161
3563c47e52fd Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
433 def test_api_lock_repo_lock_aquire_optional_userid(self):
3563c47e52fd Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
434 id_, params = _build_data(self.apikey, 'lock',
3563c47e52fd Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
435 repoid=self.REPO,
3563c47e52fd Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
436 locked=True)
3563c47e52fd Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
437 response = api_call(self, params)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
438 time_ = response.json['result']['locked_since']
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
439 expected = {
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
440 'repo': self.REPO,
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
441 'locked': True,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
442 'locked_since': time_,
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
443 'locked_by': TEST_USER_ADMIN_LOGIN,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
444 'lock_state_changed': True,
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
445 'msg': ('User `%s` set lock state for repo `%s` to `%s`'
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
446 % (TEST_USER_ADMIN_LOGIN, self.REPO, True))
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
447 }
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
448
3161
3563c47e52fd Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
449 self._compare_ok(id_, expected, given=response.body)
3563c47e52fd Implemented API calls for non-admin users for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 3056
diff changeset
450
3457
08e8115585bd calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
451 def test_api_lock_repo_lock_optional_locked(self):
08e8115585bd calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
452 id_, params = _build_data(self.apikey, 'lock',
08e8115585bd calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
453 repoid=self.REPO)
08e8115585bd calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
454 response = api_call(self, params)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
455 time_ = response.json['result']['locked_since']
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
456 expected = {
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
457 'repo': self.REPO,
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
458 'locked': True,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
459 'locked_since': time_,
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
460 'locked_by': TEST_USER_ADMIN_LOGIN,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
461 'lock_state_changed': False,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
462 'msg': ('Repo `%s` locked by `%s` on `%s`.'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
463 % (self.REPO, TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
464 json.dumps(time_to_datetime(time_))))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
465 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
466 self._compare_ok(id_, expected, given=response.body)
3808
2feb58495f34 locking API returns objects instead of string messages.
Marcin Kuzminski <marcin@python-works.com>
parents: 3803
diff changeset
467
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
468 def test_api_lock_repo_lock_optional_not_locked(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
469 repo_name = 'api_not_locked'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
470 repo = fixture.create_repo(repo_name, repo_type=self.REPO_TYPE,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
471 cur_user=self.TEST_USER_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
472 self.assertEqual(repo.locked, [None, None])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
473 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
474 id_, params = _build_data(self.apikey, 'lock',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
475 repoid=repo.repo_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
476 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
477 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
478 'repo': repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
479 'locked': False,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
480 'locked_since': None,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
481 'locked_by': None,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
482 'lock_state_changed': False,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
483 'msg': ('Repo `%s` not locked.' % (repo_name,))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
484 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
485 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
486 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
487 fixture.destroy_repo(repo_name)
3457
08e8115585bd calling lock function without lock attribute, will return lock state
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
488
2737
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
489 @mock.patch.object(Repository, 'lock', crash)
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
490 def test_api_lock_error(self):
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
491 id_, params = _build_data(self.apikey, 'lock',
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
492 userid=TEST_USER_ADMIN_LOGIN,
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
493 repoid=self.REPO,
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
494 locked=True)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
495 response = api_call(self, params)
2737
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
496
e21cb7b1a4a5 added API call for locking/unlocking repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2697
diff changeset
497 expected = 'Error occurred locking repository `%s`' % self.REPO
2697
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
498 self._compare_error(id_, expected, given=response.body)
4565e655ea2a API: Added option to rescann repositories via api call
Marcin Kuzminski <marcin@python-works.com>
parents: 2673
diff changeset
499
3502
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
500 def test_api_get_locks_regular_user(self):
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
501 id_, params = _build_data(self.apikey_regular, 'get_locks')
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
502 response = api_call(self, params)
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
503 expected = []
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
504 self._compare_ok(id_, expected, given=response.body)
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
505
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
506 def test_api_get_locks_with_userid_regular_user(self):
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
507 id_, params = _build_data(self.apikey_regular, 'get_locks',
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
508 userid=TEST_USER_ADMIN_LOGIN)
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
509 response = api_call(self, params)
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
510 expected = 'userid is not the same as your user'
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
511 self._compare_error(id_, expected, given=response.body)
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
512
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
513 def test_api_get_locks(self):
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
514 id_, params = _build_data(self.apikey, 'get_locks')
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
515 response = api_call(self, params)
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
516 expected = []
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
517 self._compare_ok(id_, expected, given=response.body)
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
518
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
519 def test_api_get_locks_with_one_locked_repo(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
520 repo_name = 'api_delete_me'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
521 repo = fixture.create_repo(repo_name, repo_type=self.REPO_TYPE,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
522 cur_user=self.TEST_USER_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
523 Repository.lock(repo, User.get_by_username(self.TEST_USER_LOGIN).user_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
524 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
525 id_, params = _build_data(self.apikey, 'get_locks')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
526 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
527 expected = [repo.get_api_data()]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
528 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
529 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
530 fixture.destroy_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
531
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
532 def test_api_get_locks_with_one_locked_repo_for_specific_user(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
533 repo_name = 'api_delete_me'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
534 repo = fixture.create_repo(repo_name, repo_type=self.REPO_TYPE,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
535 cur_user=self.TEST_USER_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
536 Repository.lock(repo, User.get_by_username(self.TEST_USER_LOGIN).user_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
537 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
538 id_, params = _build_data(self.apikey, 'get_locks',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
539 userid=self.TEST_USER_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
540 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
541 expected = [repo.get_api_data()]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
542 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
543 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
544 fixture.destroy_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
545
3502
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
546 def test_api_get_locks_with_userid(self):
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
547 id_, params = _build_data(self.apikey, 'get_locks',
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
548 userid=TEST_USER_REGULAR_LOGIN)
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
549 response = api_call(self, params)
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
550 expected = []
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
551 self._compare_ok(id_, expected, given=response.body)
7cde75eac0fe get_locks API function draft
Marcin Kuzminski <marcin@python-works.com>
parents: 3457
diff changeset
552
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
553 def test_api_create_existing_user(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
554 id_, params = _build_data(self.apikey, 'create_user',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
555 username=TEST_USER_ADMIN_LOGIN,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
556 email='test@foo.com',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
557 password='trololo')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
558 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
559
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
560 expected = "user `%s` already exist" % TEST_USER_ADMIN_LOGIN
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
561 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
562
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
563 def test_api_create_user_with_existing_email(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
564 id_, params = _build_data(self.apikey, 'create_user',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
565 username=TEST_USER_ADMIN_LOGIN + 'new',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
566 email=TEST_USER_REGULAR_EMAIL,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
567 password='trololo')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
568 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
569
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
570 expected = "email `%s` already exist" % TEST_USER_REGULAR_EMAIL
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
571 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
572
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
573 def test_api_create_user(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
574 username = 'test_new_api_user'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
575 email = username + "@foo.com"
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
576
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
577 id_, params = _build_data(self.apikey, 'create_user',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
578 username=username,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
579 email=email,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
580 password='trololo')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
581 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
582
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
583 usr = UserModel().get_by_username(username)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
584 ret = dict(
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
585 msg='created new user `%s`' % username,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
586 user=jsonify(usr.get_api_data())
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
587 )
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
588
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
589 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
590 expected = ret
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
591 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
592 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
593 fixture.destroy_user(usr.user_id)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
594
3809
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
595 def test_api_create_user_without_password(self):
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
596 username = 'test_new_api_user_passwordless'
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
597 email = username + "@foo.com"
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
598
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
599 id_, params = _build_data(self.apikey, 'create_user',
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
600 username=username,
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
601 email=email)
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
602 response = api_call(self, params)
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
603
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
604 usr = UserModel().get_by_username(username)
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
605 ret = dict(
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
606 msg='created new user `%s`' % username,
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
607 user=jsonify(usr.get_api_data())
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
608 )
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
609 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
610 expected = ret
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
611 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
612 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
613 fixture.destroy_user(usr.user_id)
3809
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
614
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
615 def test_api_create_user_with_extern_name(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
616 username = 'test_new_api_user_passwordless'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
617 email = username + "@foo.com"
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
618
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
619 id_, params = _build_data(self.apikey, 'create_user',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
620 username=username,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
621 email=email, extern_name='rhodecode')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
622 response = api_call(self, params)
3809
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
623
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
624 usr = UserModel().get_by_username(username)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
625 ret = dict(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
626 msg='created new user `%s`' % username,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
627 user=jsonify(usr.get_api_data())
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
628 )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
629 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
630 expected = ret
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
631 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
632 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
633 fixture.destroy_user(usr.user_id)
3809
647fb653048e make the password optional in API calls
Marcin Kuzminski <marcin@python-works.com>
parents: 3808
diff changeset
634
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
635 @mock.patch.object(UserModel, 'create_or_update', crash)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
636 def test_api_create_user_when_exception_happened(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
637
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
638 username = 'test_new_api_user'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
639 email = username + "@foo.com"
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
640
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
641 id_, params = _build_data(self.apikey, 'create_user',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
642 username=username,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
643 email=email,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
644 password='trololo')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
645 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
646 expected = 'failed to create user `%s`' % username
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
647 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
648
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
649 def test_api_delete_user(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
650 usr = UserModel().create_or_update(username=u'test_user',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
651 password=u'qweqwe',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
652 email=u'u232@rhodecode.org',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
653 firstname=u'u1', lastname=u'u1')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
654 Session().commit()
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
655 username = usr.username
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
656 email = usr.email
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
657 usr_id = usr.user_id
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
658 ## DELETE THIS USER NOW
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
659
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
660 id_, params = _build_data(self.apikey, 'delete_user',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
661 userid=username, )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
662 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
663
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
664 ret = {'msg': 'deleted user ID:%s %s' % (usr_id, username),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
665 'user': None}
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
666 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
667 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
668
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
669 @mock.patch.object(UserModel, 'delete', crash)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
670 def test_api_delete_user_when_exception_happened(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
671 usr = UserModel().create_or_update(username=u'test_user',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
672 password=u'qweqwe',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
673 email=u'u232@rhodecode.org',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
674 firstname=u'u1', lastname=u'u1')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
675 Session().commit()
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
676 username = usr.username
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
677
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
678 id_, params = _build_data(self.apikey, 'delete_user',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
679 userid=username, )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
680 response = api_call(self, params)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
681 ret = 'failed to delete user ID:%s %s' % (usr.user_id,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
682 usr.username)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
683 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
684 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
685
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
686 @parameterized.expand([('firstname', 'new_username'),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
687 ('lastname', 'new_username'),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
688 ('email', 'new_username'),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
689 ('admin', True),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
690 ('admin', False),
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
691 ('extern_type', 'ldap'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
692 ('extern_type', None),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
693 ('extern_name', 'test'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
694 ('extern_name', None),
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
695 ('active', False),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
696 ('active', True),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
697 ('password', 'newpass')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
698 ])
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
699 def test_api_update_user(self, name, expected):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
700 usr = UserModel().get_by_username(self.TEST_USER_LOGIN)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
701 kw = {name: expected,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
702 'userid': usr.user_id}
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
703 id_, params = _build_data(self.apikey, 'update_user', **kw)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
704 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
705
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
706 ret = {
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
707 'msg': 'updated user ID:%s %s' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
708 usr.user_id, self.TEST_USER_LOGIN),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
709 'user': jsonify(UserModel() \
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
710 .get_by_username(self.TEST_USER_LOGIN) \
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
711 .get_api_data())
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
712 }
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
713
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
714 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
715 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
716
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
717 def test_api_update_user_no_changed_params(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
718 usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
719 ret = jsonify(usr.get_api_data())
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
720 id_, params = _build_data(self.apikey, 'update_user',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
721 userid=TEST_USER_ADMIN_LOGIN)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
722
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
723 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
724 ret = {
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
725 'msg': 'updated user ID:%s %s' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
726 usr.user_id, TEST_USER_ADMIN_LOGIN),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
727 'user': ret
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
728 }
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
729 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
730 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
731
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
732 def test_api_update_user_by_user_id(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
733 usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
734 ret = jsonify(usr.get_api_data())
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
735 id_, params = _build_data(self.apikey, 'update_user',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
736 userid=usr.user_id)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
737
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
738 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
739 ret = {
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
740 'msg': 'updated user ID:%s %s' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
741 usr.user_id, TEST_USER_ADMIN_LOGIN),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
742 'user': ret
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
743 }
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
744 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
745 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
746
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
747 def test_api_update_user_default_user(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
748 usr = User.get_default_user()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
749 id_, params = _build_data(self.apikey, 'update_user',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
750 userid=usr.user_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
751
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
752 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
753 expected = 'editing default user is forbidden'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
754 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
755
2657
001c7e2ae986 fixed api issue with changing username during update_user
Marcin Kuzminski <marcin@python-works.com>
parents: 2653
diff changeset
756 @mock.patch.object(UserModel, 'update_user', crash)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
757 def test_api_update_user_when_exception_happens(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
758 usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
759 ret = jsonify(usr.get_api_data())
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
760 id_, params = _build_data(self.apikey, 'update_user',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
761 userid=usr.user_id)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
762
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
763 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
764 ret = 'failed to update user `%s`' % usr.user_id
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
765
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
766 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
767 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
768
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
769 def test_api_get_repo(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
770 new_group = 'some_new_group'
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
771 make_user_group(new_group)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
772 RepoModel().grant_user_group_permission(repo=self.REPO,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
773 group_name=new_group,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
774 perm='repository.read')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
775 Session().commit()
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
776 id_, params = _build_data(self.apikey, 'get_repo',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
777 repoid=self.REPO)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
778 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
779
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
780 repo = RepoModel().get_by_repo_name(self.REPO)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
781 ret = repo.get_api_data()
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
782
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
783 members = []
3215
cbc63abe7d59 fixed tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3165
diff changeset
784 followers = []
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
785 for user in repo.repo_to_perm:
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
786 perm = user.permission.permission_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
787 user = user.user
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
788 user_data = {'name': user.username, 'type': "user",
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
789 'permission': perm}
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
790 members.append(user_data)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
791
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
792 for user_group in repo.users_group_to_perm:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
793 perm = user_group.permission.permission_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
794 user_group = user_group.users_group
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
795 user_group_data = {'name': user_group.users_group_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
796 'type': "user_group", 'permission': perm}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
797 members.append(user_group_data)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
798
3215
cbc63abe7d59 fixed tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3165
diff changeset
799 for user in repo.followers:
cbc63abe7d59 fixed tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3165
diff changeset
800 followers.append(user.user.get_api_data())
cbc63abe7d59 fixed tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3165
diff changeset
801
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
802 ret['members'] = members
3215
cbc63abe7d59 fixed tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3165
diff changeset
803 ret['followers'] = followers
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
804
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
805 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
806 self._compare_ok(id_, expected, given=response.body)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
807 fixture.destroy_user_group(new_group)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
808
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
809 @parameterized.expand([
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
810 ('repository.admin',),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
811 ('repository.write',),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
812 ('repository.read',),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
813 ])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
814 def test_api_get_repo_by_non_admin(self, grant_perm):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
815 RepoModel().grant_user_permission(repo=self.REPO,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
816 user=self.TEST_USER_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
817 perm=grant_perm)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
818 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
819 id_, params = _build_data(self.apikey_regular, 'get_repo',
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
820 repoid=self.REPO)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
821 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
822
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
823 repo = RepoModel().get_by_repo_name(self.REPO)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
824 ret = repo.get_api_data()
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
825
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
826 members = []
3215
cbc63abe7d59 fixed tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3165
diff changeset
827 followers = []
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
828 self.assertEqual(2, len(repo.repo_to_perm))
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
829 for user in repo.repo_to_perm:
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
830 perm = user.permission.permission_name
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
831 user_obj = user.user
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
832 user_data = {'name': user_obj.username, 'type': "user",
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
833 'permission': perm}
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
834 members.append(user_data)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
835
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
836 for user_group in repo.users_group_to_perm:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
837 perm = user_group.permission.permission_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
838 user_group_obj = user_group.users_group
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
839 user_group_data = {'name': user_group_obj.users_group_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
840 'type': "user_group", 'permission': perm}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
841 members.append(user_group_data)
3216
81bbb8086f03 whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3215
diff changeset
842
3215
cbc63abe7d59 fixed tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3165
diff changeset
843 for user in repo.followers:
cbc63abe7d59 fixed tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3165
diff changeset
844 followers.append(user.user.get_api_data())
3216
81bbb8086f03 whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3215
diff changeset
845
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
846 ret['members'] = members
3215
cbc63abe7d59 fixed tests
Marcin Kuzminski <marcin@python-works.com>
parents: 3165
diff changeset
847 ret['followers'] = followers
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
848
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
849 expected = ret
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
850 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
851 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
852 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
853 RepoModel().revoke_user_permission(self.REPO, self.TEST_USER_LOGIN)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
854
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
855 def test_api_get_repo_by_non_admin_no_permission_to_repo(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
856 RepoModel().grant_user_permission(repo=self.REPO,
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
857 user=self.TEST_USER_LOGIN,
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
858 perm='repository.none')
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
859
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
860 id_, params = _build_data(self.apikey_regular, 'get_repo',
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
861 repoid=self.REPO)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
862 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
863
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
864 expected = 'repository `%s` does not exist' % (self.REPO)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
865 self._compare_error(id_, expected, given=response.body)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
866
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
867 def test_api_get_repo_that_doesn_not_exist(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
868 id_, params = _build_data(self.apikey, 'get_repo',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
869 repoid='no-such-repo')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
870 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
871
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
872 ret = 'repository `%s` does not exist' % 'no-such-repo'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
873 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
874 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
875
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
876 def test_api_get_repos(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
877 id_, params = _build_data(self.apikey, 'get_repos')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
878 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
879
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
880 result = []
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
881 for repo in RepoModel().get_all():
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
882 result.append(repo.get_api_data())
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
883 ret = jsonify(result)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
884
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
885 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
886 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
887
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
888 def test_api_get_repos_non_admin(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
889 id_, params = _build_data(self.apikey_regular, 'get_repos')
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
890 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
891
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
892 result = []
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
893 for repo in RepoModel().get_all_user_repos(self.TEST_USER_LOGIN):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
894 result.append(repo.get_api_data())
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
895 ret = jsonify(result)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
896
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
897 expected = ret
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
898 self._compare_ok(id_, expected, given=response.body)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
899
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
900 @parameterized.expand([('all', 'all'),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
901 ('dirs', 'dirs'),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
902 ('files', 'files'), ])
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
903 def test_api_get_repo_nodes(self, name, ret_type):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
904 rev = 'tip'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
905 path = '/'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
906 id_, params = _build_data(self.apikey, 'get_repo_nodes',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
907 repoid=self.REPO, revision=rev,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
908 root_path=path,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
909 ret_type=ret_type)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
910 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
911
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
912 # we don't the actual return types here since it's tested somewhere
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
913 # else
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
914 expected = response.json['result']
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
915 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
916
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
917 def test_api_get_repo_nodes_bad_revisions(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
918 rev = 'i-dont-exist'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
919 path = '/'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
920 id_, params = _build_data(self.apikey, 'get_repo_nodes',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
921 repoid=self.REPO, revision=rev,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
922 root_path=path, )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
923 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
924
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
925 expected = 'failed to get repo: `%s` nodes' % self.REPO
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
926 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
927
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
928 def test_api_get_repo_nodes_bad_path(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
929 rev = 'tip'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
930 path = '/idontexits'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
931 id_, params = _build_data(self.apikey, 'get_repo_nodes',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
932 repoid=self.REPO, revision=rev,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
933 root_path=path, )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
934 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
935
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
936 expected = 'failed to get repo: `%s` nodes' % self.REPO
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
937 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
938
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
939 def test_api_get_repo_nodes_bad_ret_type(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
940 rev = 'tip'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
941 path = '/'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
942 ret_type = 'error'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
943 id_, params = _build_data(self.apikey, 'get_repo_nodes',
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
944 repoid=self.REPO, revision=rev,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
945 root_path=path,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
946 ret_type=ret_type)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
947 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
948
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
949 expected = ('ret_type must be one of %s'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
950 % (','.join(['files', 'dirs', 'all'])))
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
951 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
952
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
953 @parameterized.expand([('all', 'all', 'repository.write'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
954 ('dirs', 'dirs', 'repository.admin'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
955 ('files', 'files', 'repository.read'), ])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
956 def test_api_get_repo_nodes_by_regular_user(self, name, ret_type, grant_perm):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
957 RepoModel().grant_user_permission(repo=self.REPO,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
958 user=self.TEST_USER_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
959 perm=grant_perm)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
960 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
961
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
962 rev = 'tip'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
963 path = '/'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
964 id_, params = _build_data(self.apikey_regular, 'get_repo_nodes',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
965 repoid=self.REPO, revision=rev,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
966 root_path=path,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
967 ret_type=ret_type)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
968 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
969
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
970 # we don't the actual return types here since it's tested somewhere
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
971 # else
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
972 expected = response.json['result']
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
973 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
974 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
975 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
976 RepoModel().revoke_user_permission(self.REPO, self.TEST_USER_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
977
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
978 def test_api_create_repo(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
979 repo_name = 'api-repo'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
980 id_, params = _build_data(self.apikey, 'create_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
981 repo_name=repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
982 owner=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
983 repo_type=self.REPO_TYPE,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
984 )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
985 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
986
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
987 repo = RepoModel().get_by_repo_name(repo_name)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
988 self.assertNotEqual(repo, None)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
989 ret = {
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
990 'msg': 'Created new repository `%s`' % repo_name,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
991 'success': True,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
992 'task': None,
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
993 }
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
994 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
995 self._compare_ok(id_, expected, given=response.body)
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
996 fixture.destroy_repo(repo_name)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
997
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
998 def test_api_create_repo_in_group(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
999 repo_name = 'my_gr/api-repo'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1000 id_, params = _build_data(self.apikey, 'create_repo',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1001 repo_name=repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1002 owner=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1003 repo_type=self.REPO_TYPE,)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1004 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1005 print params
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1006 repo = RepoModel().get_by_repo_name(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1007 self.assertNotEqual(repo, None)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1008 ret = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1009 'msg': 'Created new repository `%s`' % repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1010 'success': True,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1011 'task': None,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1012 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1013 expected = ret
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1014 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1015 fixture.destroy_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1016 fixture.destroy_repo_group('my_gr')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1017
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1018 def test_api_create_repo_unknown_owner(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1019 repo_name = 'api-repo'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1020 owner = 'i-dont-exist'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1021 id_, params = _build_data(self.apikey, 'create_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1022 repo_name=repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1023 owner=owner,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1024 repo_type=self.REPO_TYPE,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1025 )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1026 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1027 expected = 'user `%s` does not exist' % owner
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1028 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1029
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1030 def test_api_create_repo_dont_specify_owner(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1031 repo_name = 'api-repo'
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1032 owner = 'i-dont-exist'
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1033 id_, params = _build_data(self.apikey, 'create_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1034 repo_name=repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1035 repo_type=self.REPO_TYPE,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1036 )
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1037 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1038
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1039 repo = RepoModel().get_by_repo_name(repo_name)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1040 self.assertNotEqual(repo, None)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1041 ret = {
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1042 'msg': 'Created new repository `%s`' % repo_name,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1043 'success': True,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1044 'task': None,
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1045 }
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1046 expected = ret
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1047 self._compare_ok(id_, expected, given=response.body)
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1048 fixture.destroy_repo(repo_name)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1049
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1050 def test_api_create_repo_by_non_admin(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1051 repo_name = 'api-repo'
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1052 owner = 'i-dont-exist'
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1053 id_, params = _build_data(self.apikey_regular, 'create_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1054 repo_name=repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1055 repo_type=self.REPO_TYPE,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1056 )
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1057 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1058
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1059 repo = RepoModel().get_by_repo_name(repo_name)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1060 self.assertNotEqual(repo, None)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1061 ret = {
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1062 'msg': 'Created new repository `%s`' % repo_name,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1063 'success': True,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1064 'task': None,
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1065 }
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1066 expected = ret
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1067 self._compare_ok(id_, expected, given=response.body)
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1068 fixture.destroy_repo(repo_name)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1069
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1070 def test_api_create_repo_by_non_admin_specify_owner(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1071 repo_name = 'api-repo'
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1072 owner = 'i-dont-exist'
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1073 id_, params = _build_data(self.apikey_regular, 'create_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1074 repo_name=repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1075 repo_type=self.REPO_TYPE,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1076 owner=owner)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1077 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1078
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1079 expected = 'Only RhodeCode admin can specify `owner` param'
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1080 self._compare_error(id_, expected, given=response.body)
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1081 fixture.destroy_repo(repo_name)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1082
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1083 def test_api_create_repo_exists(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1084 repo_name = self.REPO
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1085 id_, params = _build_data(self.apikey, 'create_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1086 repo_name=repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1087 owner=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1088 repo_type=self.REPO_TYPE,)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1089 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1090 expected = "repo `%s` already exist" % repo_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1091 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1092
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1093 @mock.patch.object(RepoModel, 'create', crash)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1094 def test_api_create_repo_exception_occurred(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1095 repo_name = 'api-repo'
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1096 id_, params = _build_data(self.apikey, 'create_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1097 repo_name=repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1098 owner=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1099 repo_type=self.REPO_TYPE,)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1100 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1101 expected = 'failed to create repository `%s`' % repo_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1102 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1103
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1104 @parameterized.expand([
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1105 ('owner', {'owner': TEST_USER_REGULAR_LOGIN}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1106 ('description', {'description': 'new description'}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1107 ('active', {'active': True}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1108 ('active', {'active': False}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1109 ('clone_uri', {'clone_uri': 'http://foo.com/repo'}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1110 ('clone_uri', {'clone_uri': None}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1111 ('landing_rev', {'landing_rev': 'branch:master'}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1112 ('enable_statistics', {'enable_statistics': True}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1113 ('enable_locking', {'enable_locking': True}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1114 ('enable_downloads', {'enable_downloads': True}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1115 ('name', {'name': 'new_repo_name'}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1116 ('repo_group', {'group': 'test_group_for_update'}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1117 ])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1118 def test_api_update_repo(self, changing_attr, updates):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1119 repo_name = 'api_update_me'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1120 repo = fixture.create_repo(repo_name, repo_type=self.REPO_TYPE)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1121 if changing_attr == 'repo_group':
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1122 fixture.create_repo_group(updates['group'])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1123
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1124 id_, params = _build_data(self.apikey, 'update_repo',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1125 repoid=repo_name, **updates)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1126 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1127 if changing_attr == 'name':
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1128 repo_name = updates['name']
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1129 if changing_attr == 'repo_group':
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1130 repo_name = '/'.join([updates['group'], repo_name])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1131 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1132 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1133 'msg': 'updated repo ID:%s %s' % (repo.repo_id, repo_name),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1134 'repository': repo.get_api_data()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1135 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1136 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1137 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1138 fixture.destroy_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1139 if changing_attr == 'repo_group':
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1140 fixture.destroy_repo_group(updates['group'])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1141
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1142 def test_api_update_repo_repo_group_does_not_exist(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1143 repo_name = 'admin_owned'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1144 fixture.create_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1145 updates = {'group': 'test_group_for_update'}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1146 id_, params = _build_data(self.apikey, 'update_repo',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1147 repoid=repo_name, **updates)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1148 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1149 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1150 expected = 'repository group `%s` does not exist' % updates['group']
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1151 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1152 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1153 fixture.destroy_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1154
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1155 def test_api_update_repo_regular_user_not_allowed(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1156 repo_name = 'admin_owned'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1157 fixture.create_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1158 updates = {'active': False}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1159 id_, params = _build_data(self.apikey_regular, 'update_repo',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1160 repoid=repo_name, **updates)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1161 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1162 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1163 expected = 'repository `%s` does not exist' % repo_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1164 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1165 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1166 fixture.destroy_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1167
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1168 @mock.patch.object(RepoModel, 'update', crash)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1169 def test_api_update_repo_exception_occured(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1170 repo_name = 'api_update_me'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1171 fixture.create_repo(repo_name, repo_type=self.REPO_TYPE)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1172 id_, params = _build_data(self.apikey, 'update_repo',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1173 repoid=repo_name, owner=TEST_USER_ADMIN_LOGIN,)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1174 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1175 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1176 expected = 'failed to update repo `%s`' % repo_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1177 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1178 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1179 fixture.destroy_repo(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1180
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1181 def test_api_delete_repo(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1182 repo_name = 'api_delete_me'
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1183 fixture.create_repo(repo_name, repo_type=self.REPO_TYPE)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1184
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1185 id_, params = _build_data(self.apikey, 'delete_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1186 repoid=repo_name, )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1187 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1188
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1189 ret = {
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1190 'msg': 'Deleted repository `%s`' % repo_name,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1191 'success': True
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1192 }
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1193 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1194 expected = ret
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1195 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1196 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1197 fixture.destroy_repo(repo_name)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1198
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1199 def test_api_delete_repo_by_non_admin(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1200 repo_name = 'api_delete_me'
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1201 fixture.create_repo(repo_name, repo_type=self.REPO_TYPE,
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1202 cur_user=self.TEST_USER_LOGIN)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1203 id_, params = _build_data(self.apikey_regular, 'delete_repo',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1204 repoid=repo_name, )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1205 response = api_call(self, params)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1206
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1207 ret = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1208 'msg': 'Deleted repository `%s`' % repo_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1209 'success': True
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1210 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1211 try:
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1212 expected = ret
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1213 self._compare_ok(id_, expected, given=response.body)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1214 finally:
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1215 fixture.destroy_repo(repo_name)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1216
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1217 def test_api_delete_repo_by_non_admin_no_permission(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1218 repo_name = 'api_delete_me'
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1219 fixture.create_repo(repo_name, repo_type=self.REPO_TYPE)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1220 try:
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1221 id_, params = _build_data(self.apikey_regular, 'delete_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1222 repoid=repo_name, )
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1223 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1224 expected = 'repository `%s` does not exist' % (repo_name)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1225 self._compare_error(id_, expected, given=response.body)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1226 finally:
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1227 fixture.destroy_repo(repo_name)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1228
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1229 def test_api_delete_repo_exception_occurred(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1230 repo_name = 'api_delete_me'
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1231 fixture.create_repo(repo_name, repo_type=self.REPO_TYPE)
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1232 try:
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1233 with mock.patch.object(RepoModel, 'delete', crash):
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1234 id_, params = _build_data(self.apikey, 'delete_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1235 repoid=repo_name, )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1236 response = api_call(self, params)
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1237
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1238 expected = 'failed to delete repository `%s`' % repo_name
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1239 self._compare_error(id_, expected, given=response.body)
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1240 finally:
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1241 fixture.destroy_repo(repo_name)
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1242
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1243 def test_api_fork_repo(self):
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1244 fork_name = 'api-repo-fork'
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1245 id_, params = _build_data(self.apikey, 'fork_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1246 repoid=self.REPO,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1247 fork_name=fork_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1248 owner=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1249 )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1250 response = api_call(self, params)
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1251
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1252 ret = {
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1253 'msg': 'Created fork of `%s` as `%s`' % (self.REPO,
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1254 fork_name),
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1255 'success': True,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1256 'task': None,
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1257 }
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1258 expected = ret
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1259 self._compare_ok(id_, expected, given=response.body)
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1260 fixture.destroy_repo(fork_name)
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1261
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1262 def test_api_fork_repo_non_admin(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1263 fork_name = 'api-repo-fork'
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1264 id_, params = _build_data(self.apikey_regular, 'fork_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1265 repoid=self.REPO,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1266 fork_name=fork_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1267 )
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1268 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1269
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1270 ret = {
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1271 'msg': 'Created fork of `%s` as `%s`' % (self.REPO,
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1272 fork_name),
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1273 'success': True,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1274 'task': None,
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1275 }
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1276 expected = ret
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1277 self._compare_ok(id_, expected, given=response.body)
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1278 fixture.destroy_repo(fork_name)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1279
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1280 def test_api_fork_repo_non_admin_specify_owner(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1281 fork_name = 'api-repo-fork'
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1282 id_, params = _build_data(self.apikey_regular, 'fork_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1283 repoid=self.REPO,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1284 fork_name=fork_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1285 owner=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1286 )
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1287 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1288 expected = 'Only RhodeCode admin can specify `owner` param'
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1289 self._compare_error(id_, expected, given=response.body)
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1290 fixture.destroy_repo(fork_name)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1291
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1292 def test_api_fork_repo_non_admin_no_permission_to_fork(self):
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1293 RepoModel().grant_user_permission(repo=self.REPO,
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1294 user=self.TEST_USER_LOGIN,
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1295 perm='repository.none')
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1296 fork_name = 'api-repo-fork'
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1297 id_, params = _build_data(self.apikey_regular, 'fork_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1298 repoid=self.REPO,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1299 fork_name=fork_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1300 )
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1301 response = api_call(self, params)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1302 expected = 'repository `%s` does not exist' % (self.REPO)
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1303 self._compare_error(id_, expected, given=response.body)
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1304 fixture.destroy_repo(fork_name)
3163
28571535dd61 API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents: 3161
diff changeset
1305
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1306 def test_api_fork_repo_unknown_owner(self):
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1307 fork_name = 'api-repo-fork'
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1308 owner = 'i-dont-exist'
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1309 id_, params = _build_data(self.apikey, 'fork_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1310 repoid=self.REPO,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1311 fork_name=fork_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1312 owner=owner,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1313 )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1314 response = api_call(self, params)
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1315 expected = 'user `%s` does not exist' % owner
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1316 self._compare_error(id_, expected, given=response.body)
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1317
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1318 def test_api_fork_repo_fork_exists(self):
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1319 fork_name = 'api-repo-fork'
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1320 fixture.create_fork(self.REPO, fork_name)
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1321
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1322 try:
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1323 fork_name = 'api-repo-fork'
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1324
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1325 id_, params = _build_data(self.apikey, 'fork_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1326 repoid=self.REPO,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1327 fork_name=fork_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1328 owner=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1329 )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1330 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1331
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1332 expected = "fork `%s` already exist" % fork_name
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1333 self._compare_error(id_, expected, given=response.body)
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1334 finally:
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3502
diff changeset
1335 fixture.destroy_repo(fork_name)
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1336
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1337 def test_api_fork_repo_repo_exists(self):
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1338 fork_name = self.REPO
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1339
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1340 id_, params = _build_data(self.apikey, 'fork_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1341 repoid=self.REPO,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1342 fork_name=fork_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1343 owner=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1344 )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1345 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1346
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1347 expected = "repo `%s` already exist" % fork_name
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1348 self._compare_error(id_, expected, given=response.body)
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1349
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1350 @mock.patch.object(RepoModel, 'create_fork', crash)
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1351 def test_api_fork_repo_exception_occurred(self):
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1352 fork_name = 'api-repo-fork'
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1353 id_, params = _build_data(self.apikey, 'fork_repo',
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1354 repoid=self.REPO,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1355 fork_name=fork_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1356 owner=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1357 )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1358 response = api_call(self, params)
2653
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1359
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1360 expected = 'failed to fork repository `%s` as `%s`' % (self.REPO,
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1361 fork_name)
8be70a4d72c7 Implemented #354 added forking option to API
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
1362 self._compare_error(id_, expected, given=response.body)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1363
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1364 def test_api_get_user_group(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1365 id_, params = _build_data(self.apikey, 'get_user_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1366 usergroupid=TEST_USER_GROUP)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1367 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1368
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1369 user_group = UserGroupModel().get_group(TEST_USER_GROUP)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1370 members = []
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1371 for user in user_group.members:
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1372 user = user.user
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1373 members.append(user.get_api_data())
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1374
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1375 ret = user_group.get_api_data()
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1376 ret['members'] = members
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1377 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1378 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1379
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1380 def test_api_get_user_groups(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1381 gr_name = 'test_user_group2'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1382 make_user_group(gr_name)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1383
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1384 id_, params = _build_data(self.apikey, 'get_user_groups', )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1385 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1386
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1387 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1388 expected = []
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1389 for gr_name in [TEST_USER_GROUP, 'test_user_group2']:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1390 user_group = UserGroupModel().get_group(gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1391 ret = user_group.get_api_data()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1392 expected.append(ret)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1393 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1394 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1395 fixture.destroy_user_group(gr_name)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1396
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1397 def test_api_create_user_group(self):
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1398 group_name = 'some_new_group'
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1399 id_, params = _build_data(self.apikey, 'create_user_group',
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1400 group_name=group_name)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1401 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1402
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1403 ret = {
3415
b8f929bff7e3 fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents: 3235
diff changeset
1404 'msg': 'created new user group `%s`' % group_name,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1405 'user_group': jsonify(UserGroupModel() \
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1406 .get_by_name(group_name) \
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1407 .get_api_data())
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1408 }
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1409 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1410 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1411
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1412 fixture.destroy_user_group(group_name)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1413
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1414 def test_api_get_user_group_that_exist(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1415 id_, params = _build_data(self.apikey, 'create_user_group',
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
1416 group_name=TEST_USER_GROUP)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1417 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1418
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
1419 expected = "user group `%s` already exist" % TEST_USER_GROUP
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1420 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1421
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
1422 @mock.patch.object(UserGroupModel, 'create', crash)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1423 def test_api_get_user_group_exception_occurred(self):
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1424 group_name = 'exception_happens'
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1425 id_, params = _build_data(self.apikey, 'create_user_group',
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1426 group_name=group_name)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1427 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1428
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1429 expected = 'failed to create group `%s`' % group_name
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1430 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1431
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1432 @parameterized.expand([('group_name', {'group_name': 'new_group_name'}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1433 ('group_name', {'group_name': 'test_group_for_update'}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1434 ('owner', {'owner': TEST_USER_REGULAR_LOGIN}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1435 ('active', {'active': False}),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1436 ('active', {'active': True})])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1437 def test_api_update_user_group(self, changing_attr, updates):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1438 gr_name = 'test_group_for_update'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1439 user_group = fixture.create_user_group(gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1440 id_, params = _build_data(self.apikey, 'update_user_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1441 usergroupid=gr_name, **updates)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1442 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1443 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1444 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1445 'msg': 'updated user group ID:%s %s' % (user_group.users_group_id,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1446 user_group.users_group_name),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1447 'user_group': user_group.get_api_data()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1448 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1449 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1450 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1451 if changing_attr == 'group_name':
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1452 # switch to updated name for proper cleanup
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1453 gr_name = updates['group_name']
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1454 fixture.destroy_user_group(gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1455
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1456 @mock.patch.object(UserGroupModel, 'update', crash)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1457 def test_api_update_user_group_exception_occured(self):
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1458 gr_name = 'test_group'
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
1459 fixture.create_user_group(gr_name)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1460 id_, params = _build_data(self.apikey, 'update_user_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1461 usergroupid=gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1462 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1463 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1464 expected = 'failed to update user group `%s`' % gr_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1465 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1466 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1467 fixture.destroy_user_group(gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1468
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1469 def test_api_add_user_to_user_group(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1470 gr_name = 'test_group'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1471 fixture.create_user_group(gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1472 id_, params = _build_data(self.apikey, 'add_user_to_user_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1473 usergroupid=gr_name,
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1474 userid=TEST_USER_ADMIN_LOGIN)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1475 response = api_call(self, params)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1476 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1477 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1478 'msg': 'added member `%s` to user group `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1479 TEST_USER_ADMIN_LOGIN, gr_name),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1480 'success': True
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1481 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1482 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1483 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1484 fixture.destroy_user_group(gr_name)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1485
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1486 def test_api_add_user_to_user_group_that_doesnt_exist(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1487 id_, params = _build_data(self.apikey, 'add_user_to_user_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1488 usergroupid='false-group',
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1489 userid=TEST_USER_ADMIN_LOGIN)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1490 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1491
3415
b8f929bff7e3 fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents: 3235
diff changeset
1492 expected = 'user group `%s` does not exist' % 'false-group'
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1493 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1494
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
1495 @mock.patch.object(UserGroupModel, 'add_user_to_group', crash)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1496 def test_api_add_user_to_user_group_exception_occurred(self):
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1497 gr_name = 'test_group'
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
1498 fixture.create_user_group(gr_name)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1499 id_, params = _build_data(self.apikey, 'add_user_to_user_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1500 usergroupid=gr_name,
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1501 userid=TEST_USER_ADMIN_LOGIN)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1502 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1503
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1504 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1505 expected = 'failed to add member to user group `%s`' % gr_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1506 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1507 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1508 fixture.destroy_user_group(gr_name)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1509
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1510 def test_api_remove_user_from_user_group(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1511 gr_name = 'test_group_3'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1512 gr = fixture.create_user_group(gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1513 UserGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1514 Session().commit()
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1515 id_, params = _build_data(self.apikey, 'remove_user_from_user_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1516 usergroupid=gr_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1517 userid=TEST_USER_ADMIN_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1518 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1519
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1520 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1521 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1522 'msg': 'removed member `%s` from user group `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1523 TEST_USER_ADMIN_LOGIN, gr_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1524 ),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1525 'success': True}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1526 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1527 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1528 fixture.destroy_user_group(gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1529
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1530 @mock.patch.object(UserGroupModel, 'remove_user_from_group', crash)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1531 def test_api_remove_user_from_user_group_exception_occurred(self):
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1532 gr_name = 'test_group_3'
3714
7e3d89d9d3a2 - Manage Userโ€™s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
1533 gr = fixture.create_user_group(gr_name)
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
1534 UserGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1535 Session().commit()
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1536 id_, params = _build_data(self.apikey, 'remove_user_from_user_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1537 usergroupid=gr_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1538 userid=TEST_USER_ADMIN_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1539 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1540 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1541 expected = 'failed to remove member from user group `%s`' % gr_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1542 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1543 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1544 fixture.destroy_user_group(gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1545
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1546 def test_api_delete_user_group(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1547 gr_name = 'test_group'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1548 ugroup = fixture.create_user_group(gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1549 gr_id = ugroup.users_group_id
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1550 id_, params = _build_data(self.apikey, 'delete_user_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1551 usergroupid=gr_name,
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1552 userid=TEST_USER_ADMIN_LOGIN)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1553 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1554
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1555 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1556 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1557 'user_group': None,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1558 'msg': 'deleted user group ID:%s %s' % (gr_id, gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1559 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1560 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1561 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1562 if UserGroupModel().get_by_name(gr_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1563 fixture.destroy_user_group(gr_name)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1564
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1565 def test_api_delete_user_group_that_is_assigned(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1566 gr_name = 'test_group'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1567 ugroup = fixture.create_user_group(gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1568 gr_id = ugroup.users_group_id
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1569
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1570 ugr_to_perm = RepoModel().grant_user_group_permission(self.REPO, gr_name, 'repository.write')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1571 msg = 'RepoGroup assigned to [%s]' % (ugr_to_perm)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1572
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1573 id_, params = _build_data(self.apikey, 'delete_user_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1574 usergroupid=gr_name,
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1575 userid=TEST_USER_ADMIN_LOGIN)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1576 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1577
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1578 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1579 expected = msg
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1580 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1581 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1582 if UserGroupModel().get_by_name(gr_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1583 fixture.destroy_user_group(gr_name)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1584
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1585 def test_api_delete_user_group_exception_occured(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1586 gr_name = 'test_group'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1587 ugroup = fixture.create_user_group(gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1588 gr_id = ugroup.users_group_id
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1589 id_, params = _build_data(self.apikey, 'delete_user_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1590 usergroupid=gr_name,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1591 userid=TEST_USER_ADMIN_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1592
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1593 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1594 with mock.patch.object(UserGroupModel, 'delete', crash):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1595 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1596 expected = 'failed to delete user group ID:%s %s' % (gr_id, gr_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1597 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1598 finally:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1599 fixture.destroy_user_group(gr_name)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1600
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1601 @parameterized.expand([('none', 'repository.none'),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1602 ('read', 'repository.read'),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1603 ('write', 'repository.write'),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1604 ('admin', 'repository.admin')])
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1605 def test_api_grant_user_permission(self, name, perm):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1606 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1607 'grant_user_permission',
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1608 repoid=self.REPO,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1609 userid=TEST_USER_ADMIN_LOGIN,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1610 perm=perm)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1611 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1612
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1613 ret = {
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1614 'msg': 'Granted perm: `%s` for user: `%s` in repo: `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1615 perm, TEST_USER_ADMIN_LOGIN, self.REPO
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1616 ),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1617 'success': True
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1618 }
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1619 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1620 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1621
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1622 def test_api_grant_user_permission_wrong_permission(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1623 perm = 'haha.no.permission'
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1624 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1625 'grant_user_permission',
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1626 repoid=self.REPO,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1627 userid=TEST_USER_ADMIN_LOGIN,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1628 perm=perm)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1629 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1630
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1631 expected = 'permission `%s` does not exist' % perm
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1632 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1633
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1634 @mock.patch.object(RepoModel, 'grant_user_permission', crash)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1635 def test_api_grant_user_permission_exception_when_adding(self):
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1636 perm = 'repository.read'
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1637 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1638 'grant_user_permission',
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1639 repoid=self.REPO,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1640 userid=TEST_USER_ADMIN_LOGIN,
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1641 perm=perm)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1642 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1643
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1644 expected = 'failed to edit permission for user: `%s` in repo: `%s`' % (
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1645 TEST_USER_ADMIN_LOGIN, self.REPO
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1646 )
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1647 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1648
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1649 def test_api_revoke_user_permission(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1650 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1651 'revoke_user_permission',
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1652 repoid=self.REPO,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1653 userid=TEST_USER_ADMIN_LOGIN, )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1654 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1655
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1656 expected = {
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1657 'msg': 'Revoked perm for user: `%s` in repo: `%s`' % (
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1658 TEST_USER_ADMIN_LOGIN, self.REPO
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1659 ),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1660 'success': True
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1661 }
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1662 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1663
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1664 @mock.patch.object(RepoModel, 'revoke_user_permission', crash)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1665 def test_api_revoke_user_permission_exception_when_adding(self):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1666 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1667 'revoke_user_permission',
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1668 repoid=self.REPO,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1669 userid=TEST_USER_ADMIN_LOGIN, )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1670 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1671
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1672 expected = 'failed to edit permission for user: `%s` in repo: `%s`' % (
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1673 TEST_USER_ADMIN_LOGIN, self.REPO
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1674 )
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1675 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1676
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1677 @parameterized.expand([('none', 'repository.none'),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1678 ('read', 'repository.read'),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1679 ('write', 'repository.write'),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1680 ('admin', 'repository.admin')])
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1681 def test_api_grant_user_group_permission(self, name, perm):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1682 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1683 'grant_user_group_permission',
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1684 repoid=self.REPO,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1685 usergroupid=TEST_USER_GROUP,
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1686 perm=perm)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1687 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1688
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1689 ret = {
3415
b8f929bff7e3 fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents: 3235
diff changeset
1690 'msg': 'Granted perm: `%s` for user group: `%s` in repo: `%s`' % (
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
1691 perm, TEST_USER_GROUP, self.REPO
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1692 ),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1693 'success': True
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1694 }
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1695 expected = ret
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1696 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1697
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1698 def test_api_grant_user_group_permission_wrong_permission(self):
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1699 perm = 'haha.no.permission'
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1700 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1701 'grant_user_group_permission',
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1702 repoid=self.REPO,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1703 usergroupid=TEST_USER_GROUP,
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1704 perm=perm)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1705 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1706
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1707 expected = 'permission `%s` does not exist' % perm
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1708 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1709
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1710 @mock.patch.object(RepoModel, 'grant_user_group_permission', crash)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1711 def test_api_grant_user_group_permission_exception_when_adding(self):
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1712 perm = 'repository.read'
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1713 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1714 'grant_user_group_permission',
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1715 repoid=self.REPO,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1716 usergroupid=TEST_USER_GROUP,
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1717 perm=perm)
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1718 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1719
3415
b8f929bff7e3 fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents: 3235
diff changeset
1720 expected = 'failed to edit permission for user group: `%s` in repo: `%s`' % (
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1721 TEST_USER_GROUP, self.REPO
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1722 )
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1723 self._compare_error(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1724
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1725 def test_api_revoke_user_group_permission(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1726 RepoModel().grant_user_group_permission(repo=self.REPO,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1727 group_name=TEST_USER_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1728 perm='repository.read')
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1729 Session().commit()
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1730 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1731 'revoke_user_group_permission',
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1732 repoid=self.REPO,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1733 usergroupid=TEST_USER_GROUP, )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1734 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1735
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1736 expected = {
3415
b8f929bff7e3 fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents: 3235
diff changeset
1737 'msg': 'Revoked perm for user group: `%s` in repo: `%s`' % (
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3415
diff changeset
1738 TEST_USER_GROUP, self.REPO
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1739 ),
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1740 'success': True
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1741 }
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1742 self._compare_ok(id_, expected, given=response.body)
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1743
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1744 @mock.patch.object(RepoModel, 'revoke_user_group_permission', crash)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1745 def test_api_revoke_user_group_permission_exception_when_adding(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1746 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1747 'revoke_user_group_permission',
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1748 repoid=self.REPO,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1749 usergroupid=TEST_USER_GROUP, )
2738
Marcin Kuzminski <marcin@python-works.com>
parents: 2737
diff changeset
1750 response = api_call(self, params)
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1751
3415
b8f929bff7e3 fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents: 3235
diff changeset
1752 expected = 'failed to edit permission for user group: `%s` in repo: `%s`' % (
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1753 TEST_USER_GROUP, self.REPO
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1754 )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1755 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1756
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1757 @parameterized.expand([
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1758 ('none', 'group.none', 'none'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1759 ('read', 'group.read', 'none'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1760 ('write', 'group.write', 'none'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1761 ('admin', 'group.admin', 'none'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1762
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1763 ('none', 'group.none', 'all'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1764 ('read', 'group.read', 'all'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1765 ('write', 'group.write', 'all'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1766 ('admin', 'group.admin', 'all'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1767
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1768 ('none', 'group.none', 'repos'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1769 ('read', 'group.read', 'repos'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1770 ('write', 'group.write', 'repos'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1771 ('admin', 'group.admin', 'repos'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1772
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1773 ('none', 'group.none', 'groups'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1774 ('read', 'group.read', 'groups'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1775 ('write', 'group.write', 'groups'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1776 ('admin', 'group.admin', 'groups'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1777 ])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1778 def test_api_grant_user_permission_to_repo_group(self, name, perm, apply_to_children):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1779 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1780 'grant_user_permission_to_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1781 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1782 userid=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1783 perm=perm, apply_to_children=apply_to_children)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1784 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1785
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1786 ret = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1787 'msg': 'Granted perm: `%s` (recursive:%s) for user: `%s` in repo group: `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1788 perm, apply_to_children, TEST_USER_ADMIN_LOGIN, TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1789 ),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1790 'success': True
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1791 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1792 expected = ret
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1793 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1794
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1795 @parameterized.expand([
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1796 ('none_fails', 'group.none', 'none', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1797 ('read_fails', 'group.read', 'none', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1798 ('write_fails', 'group.write', 'none', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1799 ('admin_fails', 'group.admin', 'none', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1800
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1801 # with granted perms
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1802 ('none_ok', 'group.none', 'none', True, True),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1803 ('read_ok', 'group.read', 'none', True, True),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1804 ('write_ok', 'group.write', 'none', True, True),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1805 ('admin_ok', 'group.admin', 'none', True, True),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1806 ])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1807 def test_api_grant_user_permission_to_repo_group_by_regular_user(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1808 self, name, perm, apply_to_children, grant_admin, access_ok):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1809 if grant_admin:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1810 RepoGroupModel().grant_user_permission(TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1811 self.TEST_USER_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1812 'group.admin')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1813 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1814
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1815 id_, params = _build_data(self.apikey_regular,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1816 'grant_user_permission_to_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1817 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1818 userid=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1819 perm=perm, apply_to_children=apply_to_children)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1820 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1821 if access_ok:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1822 ret = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1823 'msg': 'Granted perm: `%s` (recursive:%s) for user: `%s` in repo group: `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1824 perm, apply_to_children, TEST_USER_ADMIN_LOGIN, TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1825 ),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1826 'success': True
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1827 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1828 expected = ret
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1829 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1830 else:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1831 expected = 'repository group `%s` does not exist' % TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1832 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1833
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1834 def test_api_grant_user_permission_to_repo_group_wrong_permission(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1835 perm = 'haha.no.permission'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1836 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1837 'grant_user_permission_to_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1838 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1839 userid=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1840 perm=perm)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1841 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1842
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1843 expected = 'permission `%s` does not exist' % perm
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1844 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1845
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1846 @mock.patch.object(RepoGroupModel, 'grant_user_permission', crash)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1847 def test_api_grant_user_permission_to_repo_group_exception_when_adding(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1848 perm = 'group.read'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1849 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1850 'grant_user_permission_to_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1851 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1852 userid=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1853 perm=perm)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1854 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1855
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1856 expected = 'failed to edit permission for user: `%s` in repo group: `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1857 TEST_USER_ADMIN_LOGIN, TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1858 )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1859 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1860
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1861 @parameterized.expand([
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1862 ('none', 'none'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1863 ('all', 'all'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1864 ('repos', 'repos'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1865 ('groups', 'groups'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1866 ])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1867 def test_api_revoke_user_permission_from_repo_group(self, name, apply_to_children):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1868 RepoGroupModel().grant_user_permission(repo_group=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1869 user=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1870 perm='group.read',)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1871 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1872
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1873 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1874 'revoke_user_permission_from_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1875 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1876 userid=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1877 apply_to_children=apply_to_children,)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1878 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1879
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1880 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1881 'msg': 'Revoked perm (recursive:%s) for user: `%s` in repo group: `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1882 apply_to_children, TEST_USER_ADMIN_LOGIN, TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1883 ),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1884 'success': True
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1885 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1886 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1887
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1888 @parameterized.expand([
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1889 ('none', 'none', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1890 ('all', 'all', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1891 ('repos', 'repos', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1892 ('groups', 'groups', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1893
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1894 # after granting admin rights
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1895 ('none', 'none', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1896 ('all', 'all', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1897 ('repos', 'repos', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1898 ('groups', 'groups', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1899 ])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1900 def test_api_revoke_user_permission_from_repo_group_by_regular_user(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1901 self, name, apply_to_children, grant_admin, access_ok):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1902 RepoGroupModel().grant_user_permission(repo_group=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1903 user=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1904 perm='group.read',)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1905 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1906
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1907 if grant_admin:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1908 RepoGroupModel().grant_user_permission(TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1909 self.TEST_USER_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1910 'group.admin')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1911 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1912
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1913 id_, params = _build_data(self.apikey_regular,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1914 'revoke_user_permission_from_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1915 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1916 userid=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1917 apply_to_children=apply_to_children,)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1918 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1919 if access_ok:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1920 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1921 'msg': 'Revoked perm (recursive:%s) for user: `%s` in repo group: `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1922 apply_to_children, TEST_USER_ADMIN_LOGIN, TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1923 ),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1924 'success': True
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1925 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1926 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1927 else:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1928 expected = 'repository group `%s` does not exist' % TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1929 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1930
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1931 @mock.patch.object(RepoGroupModel, 'revoke_user_permission', crash)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1932 def test_api_revoke_user_permission_from_repo_group_exception_when_adding(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1933 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1934 'revoke_user_permission_from_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1935 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1936 userid=TEST_USER_ADMIN_LOGIN, )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1937 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1938
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1939 expected = 'failed to edit permission for user: `%s` in repo group: `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1940 TEST_USER_ADMIN_LOGIN, TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1941 )
2526
473794943022 Refactored API
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1942 self._compare_error(id_, expected, given=response.body)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1943
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1944 @parameterized.expand([
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1945 ('none', 'group.none', 'none'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1946 ('read', 'group.read', 'none'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1947 ('write', 'group.write', 'none'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1948 ('admin', 'group.admin', 'none'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1949
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1950 ('none', 'group.none', 'all'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1951 ('read', 'group.read', 'all'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1952 ('write', 'group.write', 'all'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1953 ('admin', 'group.admin', 'all'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1954
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1955 ('none', 'group.none', 'repos'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1956 ('read', 'group.read', 'repos'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1957 ('write', 'group.write', 'repos'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1958 ('admin', 'group.admin', 'repos'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1959
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1960 ('none', 'group.none', 'groups'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1961 ('read', 'group.read', 'groups'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1962 ('write', 'group.write', 'groups'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1963 ('admin', 'group.admin', 'groups'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1964 ])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1965 def test_api_grant_user_group_permission_to_repo_group(self, name, perm, apply_to_children):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1966 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1967 'grant_user_group_permission_to_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1968 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1969 usergroupid=TEST_USER_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1970 perm=perm,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1971 apply_to_children=apply_to_children,)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1972 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1973
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1974 ret = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1975 'msg': 'Granted perm: `%s` (recursive:%s) for user group: `%s` in repo group: `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1976 perm, apply_to_children, TEST_USER_GROUP, TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1977 ),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1978 'success': True
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1979 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1980 expected = ret
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1981 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1982
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1983 @parameterized.expand([
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1984 ('none_fails', 'group.none', 'none', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1985 ('read_fails', 'group.read', 'none', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1986 ('write_fails', 'group.write', 'none', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1987 ('admin_fails', 'group.admin', 'none', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1988
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1989 # with granted perms
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1990 ('none_ok', 'group.none', 'none', True, True),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1991 ('read_ok', 'group.read', 'none', True, True),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1992 ('write_ok', 'group.write', 'none', True, True),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1993 ('admin_ok', 'group.admin', 'none', True, True),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1994 ])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1995 def test_api_grant_user_group_permission_to_repo_group_by_regular_user(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1996 self, name, perm, apply_to_children, grant_admin, access_ok):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1997 if grant_admin:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1998 RepoGroupModel().grant_user_permission(TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
1999 self.TEST_USER_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2000 'group.admin')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2001 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2002
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2003 id_, params = _build_data(self.apikey_regular,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2004 'grant_user_group_permission_to_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2005 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2006 usergroupid=TEST_USER_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2007 perm=perm,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2008 apply_to_children=apply_to_children,)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2009 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2010 if access_ok:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2011 ret = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2012 'msg': 'Granted perm: `%s` (recursive:%s) for user group: `%s` in repo group: `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2013 perm, apply_to_children, TEST_USER_GROUP, TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2014 ),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2015 'success': True
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2016 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2017 expected = ret
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2018 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2019 else:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2020 expected = 'repository group `%s` does not exist' % TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2021 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2022
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2023 def test_api_grant_user_group_permission_to_repo_group_wrong_permission(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2024 perm = 'haha.no.permission'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2025 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2026 'grant_user_group_permission_to_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2027 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2028 usergroupid=TEST_USER_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2029 perm=perm)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2030 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2031
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2032 expected = 'permission `%s` does not exist' % perm
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2033 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2034
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2035 @mock.patch.object(RepoGroupModel, 'grant_user_group_permission', crash)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2036 def test_api_grant_user_group_permission_exception_when_adding(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2037 perm = 'group.read'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2038 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2039 'grant_user_group_permission_to_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2040 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2041 usergroupid=TEST_USER_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2042 perm=perm)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2043 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2044
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2045 expected = 'failed to edit permission for user group: `%s` in repo group: `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2046 TEST_USER_GROUP, TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2047 )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2048 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2049
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2050 @parameterized.expand([
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2051 ('none', 'none'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2052 ('all', 'all'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2053 ('repos', 'repos'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2054 ('groups', 'groups'),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2055 ])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2056 def test_api_revoke_user_group_permission_from_repo_group(self, name, apply_to_children):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2057 RepoGroupModel().grant_user_group_permission(repo_group=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2058 group_name=TEST_USER_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2059 perm='group.read',)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2060 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2061 id_, params = _build_data(self.apikey,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2062 'revoke_user_group_permission_from_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2063 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2064 usergroupid=TEST_USER_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2065 apply_to_children=apply_to_children,)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2066 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2067
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2068 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2069 'msg': 'Revoked perm (recursive:%s) for user group: `%s` in repo group: `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2070 apply_to_children, TEST_USER_GROUP, TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2071 ),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2072 'success': True
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2073 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2074 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2075
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2076 @parameterized.expand([
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2077 ('none', 'none', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2078 ('all', 'all', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2079 ('repos', 'repos', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2080 ('groups', 'groups', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2081
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2082 # after granting admin rights
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2083 ('none', 'none', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2084 ('all', 'all', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2085 ('repos', 'repos', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2086 ('groups', 'groups', False, False),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2087 ])
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2088 def test_api_revoke_user_group_permission_from_repo_group_by_regular_user(
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2089 self, name, apply_to_children, grant_admin, access_ok):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2090 RepoGroupModel().grant_user_permission(repo_group=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2091 user=TEST_USER_ADMIN_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2092 perm='group.read',)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2093 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2094
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2095 if grant_admin:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2096 RepoGroupModel().grant_user_permission(TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2097 self.TEST_USER_LOGIN,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2098 'group.admin')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2099 Session().commit()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2100
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2101 id_, params = _build_data(self.apikey_regular,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2102 'revoke_user_group_permission_from_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2103 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2104 usergroupid=TEST_USER_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2105 apply_to_children=apply_to_children,)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2106 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2107 if access_ok:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2108 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2109 'msg': 'Revoked perm (recursive:%s) for user group: `%s` in repo group: `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2110 apply_to_children, TEST_USER_ADMIN_LOGIN, TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2111 ),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2112 'success': True
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2113 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2114 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2115 else:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2116 expected = 'repository group `%s` does not exist' % TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2117 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2118
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2119 @mock.patch.object(RepoGroupModel, 'revoke_user_group_permission', crash)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2120 def test_api_revoke_user_group_permission_from_repo_group_exception_when_adding(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2121 id_, params = _build_data(self.apikey, 'revoke_user_group_permission_from_repo_group',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2122 repogroupid=TEST_REPO_GROUP,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2123 usergroupid=TEST_USER_GROUP,)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2124 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2125
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2126 expected = 'failed to edit permission for user group: `%s` in repo group: `%s`' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2127 TEST_USER_GROUP, TEST_REPO_GROUP
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2128 )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2129 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2130
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2131 def test_api_get_gist(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2132 gist = fixture.create_gist()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2133 gist_id = gist.gist_access_id
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2134 gist_created_on = gist.created_on
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2135 id_, params = _build_data(self.apikey, 'get_gist',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2136 gistid=gist_id, )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2137 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2138
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2139 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2140 'access_id': gist_id,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2141 'created_on': gist_created_on,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2142 'description': 'new-gist',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2143 'expires': -1.0,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2144 'gist_id': int(gist_id),
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2145 'type': 'public',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2146 'url': 'http://localhost:80/_admin/gists/%s' % gist_id
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2147 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2148
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2149 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2150
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2151 def test_api_get_gist_that_does_not_exist(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2152 id_, params = _build_data(self.apikey_regular, 'get_gist',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2153 gistid='12345', )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2154 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2155 expected = 'gist `%s` does not exist' % ('12345',)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2156 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2157
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2158 def test_api_get_gist_private_gist_without_permission(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2159 gist = fixture.create_gist()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2160 gist_id = gist.gist_access_id
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2161 gist_created_on = gist.created_on
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2162 id_, params = _build_data(self.apikey_regular, 'get_gist',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2163 gistid=gist_id, )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2164 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2165
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2166 expected = 'gist `%s` does not exist' % gist_id
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2167 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2168
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2169 def test_api_get_gists(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2170 fixture.create_gist()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2171 fixture.create_gist()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2172
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2173 id_, params = _build_data(self.apikey, 'get_gists')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2174 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2175 expected = response.json
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2176 self.assertEqual(len(response.json['result']), 2)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2177 #self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2178
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2179 def test_api_get_gists_regular_user(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2180 # by admin
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2181 fixture.create_gist()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2182 fixture.create_gist()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2183
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2184 # by reg user
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2185 fixture.create_gist(owner=self.TEST_USER_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2186 fixture.create_gist(owner=self.TEST_USER_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2187 fixture.create_gist(owner=self.TEST_USER_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2188
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2189 id_, params = _build_data(self.apikey_regular, 'get_gists')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2190 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2191 expected = response.json
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2192 self.assertEqual(len(response.json['result']), 3)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2193 #self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2194
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2195 def test_api_get_gists_only_for_regular_user(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2196 # by admin
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2197 fixture.create_gist()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2198 fixture.create_gist()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2199
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2200 # by reg user
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2201 fixture.create_gist(owner=self.TEST_USER_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2202 fixture.create_gist(owner=self.TEST_USER_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2203 fixture.create_gist(owner=self.TEST_USER_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2204
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2205 id_, params = _build_data(self.apikey, 'get_gists',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2206 userid=self.TEST_USER_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2207 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2208 expected = response.json
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2209 self.assertEqual(len(response.json['result']), 3)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2210 #self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2211
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2212 def test_api_get_gists_regular_user_with_different_userid(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2213 id_, params = _build_data(self.apikey_regular, 'get_gists',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2214 userid=TEST_USER_ADMIN_LOGIN)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2215 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2216 expected = 'userid is not the same as your user'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2217 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2218
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2219 def test_api_create_gist(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2220 id_, params = _build_data(self.apikey_regular, 'create_gist',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2221 lifetime=10,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2222 description='foobar-gist',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2223 gist_type='public',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2224 files={'foobar': {'content': 'foo'}})
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2225 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2226 response_json = response.json
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2227 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2228 'gist': {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2229 'access_id': response_json['result']['gist']['access_id'],
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2230 'created_on': response_json['result']['gist']['created_on'],
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2231 'description': 'foobar-gist',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2232 'expires': response_json['result']['gist']['expires'],
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2233 'gist_id': response_json['result']['gist']['gist_id'],
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2234 'type': 'public',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2235 'url': response_json['result']['gist']['url']
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2236 },
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2237 'msg': 'created new gist'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2238 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2239 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2240
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2241 @mock.patch.object(GistModel, 'create', crash)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2242 def test_api_create_gist_exception_occured(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2243 id_, params = _build_data(self.apikey_regular, 'create_gist',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2244 files={})
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2245 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2246 expected = 'failed to create gist'
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2247 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2248
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2249 def test_api_delete_gist(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2250 gist_id = fixture.create_gist().gist_access_id
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2251 id_, params = _build_data(self.apikey, 'delete_gist',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2252 gistid=gist_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2253 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2254 expected = {'gist': None, 'msg': 'deleted gist ID:%s' % gist_id}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2255 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2256
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2257 def test_api_delete_gist_regular_user(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2258 gist_id = fixture.create_gist(owner=self.TEST_USER_LOGIN).gist_access_id
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2259 id_, params = _build_data(self.apikey_regular, 'delete_gist',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2260 gistid=gist_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2261 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2262 expected = {'gist': None, 'msg': 'deleted gist ID:%s' % gist_id}
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2263 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2264
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2265 def test_api_delete_gist_regular_user_no_permission(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2266 gist_id = fixture.create_gist().gist_access_id
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2267 id_, params = _build_data(self.apikey_regular, 'delete_gist',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2268 gistid=gist_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2269 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2270 expected = 'gist `%s` does not exist' % (gist_id,)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2271 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2272
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2273 @mock.patch.object(GistModel, 'delete', crash)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2274 def test_api_delete_gist_exception_occured(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2275 gist_id = fixture.create_gist().gist_access_id
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2276 id_, params = _build_data(self.apikey, 'delete_gist',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2277 gistid=gist_id)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2278 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2279 expected = 'failed to delete gist ID:%s' % (gist_id,)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2280 self._compare_error(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2281
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2282 def test_api_get_ip(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2283 id_, params = _build_data(self.apikey, 'get_ip')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2284 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2285 expected = {
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2286 'server_ip_addr': '0.0.0.0',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2287 'user_ips': []
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2288 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2289 self._compare_ok(id_, expected, given=response.body)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2290
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2291 def test_api_get_server_info(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2292 id_, params = _build_data(self.apikey, 'get_server_info')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2293 response = api_call(self, params)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2294 expected = RhodeCodeSetting.get_server_info()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3891
diff changeset
2295 self._compare_ok(id_, expected, given=response.body)