Mercurial > kallithea
annotate rhodecode/tests/fixture.py @ 3642:749dfd6b6e95 beta
added new fixture classes
and detaching/deleting forks
tests
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 31 Mar 2013 17:01:47 +0200 |
parents | |
children | 8a86836fad64 |
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 import os |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 import unittest |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 from rhodecode.tests import * |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 from rhodecode.model.db import Repository, User |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 from rhodecode.model.meta import Session |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 from rhodecode.model.repo import RepoModel |
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 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 def create_repo(self, name, **kwargs): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 form_data = _get_repo_create_params(repo_name=name, **kwargs) |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 cur_user = User.get_by_username(TEST_USER_ADMIN_LOGIN) |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 RepoModel().create(form_data, cur_user) |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 return Repository.get_by_repo_name(name) |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 def create_fork(self, repo_to_fork, fork_name, **kwargs): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 repo_to_fork = Repository.get_by_repo_name(repo_to_fork) |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 vcs_type = repo_to_fork.repo_type |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 form_data = dict( |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 repo_name=fork_name, |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 repo_name_full=fork_name, |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 repo_group=None, |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 repo_type=vcs_type, |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 description='', |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 private=False, |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 copy_permissions=False, |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 landing_rev='tip', |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 update_after_clone=False, |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 fork_parent_id=repo_to_fork, |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 ) |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 cur_user = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 RepoModel().create_fork(form_data, cur_user=cur_user) |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 Session().commit() |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 return Repository.get_by_repo_name(fork_name) |