Mercurial > kallithea
annotate rhodecode/tests/fixture.py @ 3714:7e3d89d9d3a2 beta
- Manage User’s Groups: create, delete, rename, add/remove users inside.
by user group admin.
In this case, a user's group can be owned by several people thru an owner user's group.
Some refactoring of naming, permission handling logic.
- remove some code duplicity as well as inconsistent naming
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 08 Apr 2013 22:47:35 +0200 |
parents | 8a86836fad64 |
children | ffd45b185016 |
rev | line source |
---|---|
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 """ |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 Helpers for fixture generation |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 """ |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 from rhodecode.tests import * |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
5 from rhodecode.model.db import Repository, User, RepoGroup, UserGroup |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 from rhodecode.model.meta import Session |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 from rhodecode.model.repo import RepoModel |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
8 from rhodecode.model.repos_group import ReposGroupModel |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
9 from rhodecode.model.users_group import UserGroupModel |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 class Fixture(object): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 def __init__(self): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 pass |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
17 def _get_repo_create_params(self, **custom): |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
18 defs = dict( |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
19 repo_name=None, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
20 repo_type='hg', |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
21 clone_uri='', |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
22 repo_group='', |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
23 repo_description='DESC', |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
24 repo_private=False, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
25 repo_landing_rev='tip' |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
26 ) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
27 defs.update(custom) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
28 if 'repo_name_full' not in custom: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
29 defs.update({'repo_name_full': defs['repo_name']}) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
30 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
31 return defs |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
32 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
33 def _get_group_create_params(self, **custom): |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
34 defs = dict( |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
35 group_name=None, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
36 group_description='DESC', |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
37 group_parent_id=None, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
38 perms_updates=[], |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
39 perms_new=[], |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
40 enable_locking=False, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
41 recursive=False |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
42 ) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
43 defs.update(custom) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
44 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
45 return defs |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
46 |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
47 def _get_user_group_create_params(self, name, **custom): |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
48 defs = dict( |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
49 users_group_name=name, |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
50 users_group_active=True, |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
51 ) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
52 defs.update(custom) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
53 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
54 return defs |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
55 |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 def create_repo(self, name, **kwargs): |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
57 if 'skip_if_exists' in kwargs: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
58 del kwargs['skip_if_exists'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
59 r = Repository.get_by_repo_name(name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
60 if r: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
61 return r |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
62 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
63 if isinstance(kwargs.get('repos_group'), RepoGroup): |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
64 #TODO: rename the repos_group ! |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
65 kwargs['repo_group'] = kwargs['repos_group'].group_id |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
66 del kwargs['repos_group'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
67 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
68 form_data = self._get_repo_create_params(repo_name=name, **kwargs) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
69 cur_user = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 RepoModel().create(form_data, cur_user) |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
71 Session().commit() |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 return Repository.get_by_repo_name(name) |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 def create_fork(self, repo_to_fork, fork_name, **kwargs): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 repo_to_fork = Repository.get_by_repo_name(repo_to_fork) |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
76 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
77 form_data = self._get_repo_create_params(repo_name=fork_name, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
78 fork_parent_id=repo_to_fork, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
79 repo_type=repo_to_fork.repo_type, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
80 **kwargs) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
81 form_data['update_after_clone'] = False |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
82 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
83 #TODO: fix it !! |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
84 form_data['description'] = form_data['repo_description'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
85 form_data['private'] = form_data['repo_private'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
86 form_data['landing_rev'] = form_data['repo_landing_rev'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
87 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
88 owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
89 RepoModel().create_fork(form_data, cur_user=owner) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
90 Session().commit() |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
91 r = Repository.get_by_repo_name(fork_name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
92 assert r |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
93 return r |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
95 def destroy_repo(self, repo_name): |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
96 RepoModel().delete(repo_name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
97 Session().commit() |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
99 def create_group(self, name, **kwargs): |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
100 if 'skip_if_exists' in kwargs: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
101 del kwargs['skip_if_exists'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
102 gr = RepoGroup.get_by_group_name(group_name=name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
103 if gr: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
104 return gr |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
105 form_data = self._get_group_create_params(group_name=name, **kwargs) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
106 owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
107 gr = ReposGroupModel().create(group_name=form_data['group_name'], |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
108 group_description=form_data['group_name'], |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
109 owner=owner, parent=form_data['group_parent_id']) |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
110 Session().commit() |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
111 gr = RepoGroup.get_by_group_name(gr.group_name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
112 return gr |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
113 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
114 def create_user_group(self, name, **kwargs): |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
115 if 'skip_if_exists' in kwargs: |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
116 del kwargs['skip_if_exists'] |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
117 gr = UserGroup.get_by_group_name(group_name=name) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
118 if gr: |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
119 return gr |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
120 form_data = self._get_user_group_create_params(name, **kwargs) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
121 owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
122 user_group = UserGroupModel().create(name=form_data['users_group_name'], |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
123 owner=owner, active=form_data['users_group_active']) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
124 Session().commit() |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
125 user_group = UserGroup.get_by_group_name(user_group.users_group_name) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
126 return user_group |