Mercurial > kallithea
annotate rhodecode/tests/fixture.py @ 3651:659bd922520e beta
config: rename options to show_revision_number and show_sha_length
'sha_show_numeric_rev' had nothing to do with the sha value.
The revision numbers are kind of native to Mercurial and there they are known
as 'revision numbers'.
'sha_len' was very short and didn't clarify that it only controlled what was shown.
These settings are currently only used in the changelog, but they should be used everywhere.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 03 Apr 2013 15:56:12 +0200 |
parents | 8a86836fad64 |
children | 7e3d89d9d3a2 |
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 * |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
5 from rhodecode.model.db import Repository, User, RepoGroup |
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 |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 |
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 class Fixture(object): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 def __init__(self): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 pass |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
16 def _get_repo_create_params(self, **custom): |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
17 defs = dict( |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
18 repo_name=None, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
19 repo_type='hg', |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
20 clone_uri='', |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
21 repo_group='', |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
22 repo_description='DESC', |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
23 repo_private=False, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
24 repo_landing_rev='tip' |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
25 ) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
26 defs.update(custom) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
27 if 'repo_name_full' not in custom: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
28 defs.update({'repo_name_full': defs['repo_name']}) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
29 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
30 return defs |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
31 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
32 def _get_group_create_params(self, **custom): |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
33 defs = dict( |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
34 group_name=None, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
35 group_description='DESC', |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
36 group_parent_id=None, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
37 perms_updates=[], |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
38 perms_new=[], |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
39 enable_locking=False, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
40 recursive=False |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
41 ) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
42 defs.update(custom) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
43 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
44 return defs |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
45 |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 def create_repo(self, name, **kwargs): |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
47 if 'skip_if_exists' in kwargs: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
48 del kwargs['skip_if_exists'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
49 r = Repository.get_by_repo_name(name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
50 if r: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
51 return r |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
52 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
53 if isinstance(kwargs.get('repos_group'), RepoGroup): |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
54 #TODO: rename the repos_group ! |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
55 kwargs['repo_group'] = kwargs['repos_group'].group_id |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
56 del kwargs['repos_group'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
57 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
58 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
|
59 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
|
60 RepoModel().create(form_data, cur_user) |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
61 Session().commit() |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 return Repository.get_by_repo_name(name) |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 def create_fork(self, repo_to_fork, fork_name, **kwargs): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 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
|
66 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
67 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
|
68 fork_parent_id=repo_to_fork, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
69 repo_type=repo_to_fork.repo_type, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
70 **kwargs) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
71 form_data['update_after_clone'] = False |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
72 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
73 #TODO: fix it !! |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
74 form_data['description'] = form_data['repo_description'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
75 form_data['private'] = form_data['repo_private'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
76 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
|
77 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
78 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
|
79 RepoModel().create_fork(form_data, cur_user=owner) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
80 Session().commit() |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
81 r = Repository.get_by_repo_name(fork_name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
82 assert r |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
83 return r |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
85 def destroy_repo(self, repo_name): |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
86 RepoModel().delete(repo_name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
87 Session().commit() |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
89 def create_group(self, name, **kwargs): |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
90 if 'skip_if_exists' in kwargs: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
91 del kwargs['skip_if_exists'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
92 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
|
93 if gr: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
94 return gr |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 group_description=form_data['group_name'], |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
99 owner=owner, parent=form_data['group_parent_id']) |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 Session().commit() |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
101 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
|
102 return gr |