##// END OF EJS Templates
added new fixture classes...
marcink -
r3642:749dfd6b beta
parent child Browse files
Show More
@@ -0,0 +1,43 b''
1 """
2 Helpers for fixture generation
3 """
4 import os
5 import unittest
6 from rhodecode.tests import *
7 from rhodecode.model.db import Repository, User
8 from rhodecode.model.meta import Session
9 from rhodecode.model.repo import RepoModel
10
11
12 class Fixture(object):
13
14 def __init__(self):
15 pass
16
17 def create_repo(self, name, **kwargs):
18 form_data = _get_repo_create_params(repo_name=name, **kwargs)
19 cur_user = User.get_by_username(TEST_USER_ADMIN_LOGIN)
20 RepoModel().create(form_data, cur_user)
21 return Repository.get_by_repo_name(name)
22
23 def create_fork(self, repo_to_fork, fork_name, **kwargs):
24 repo_to_fork = Repository.get_by_repo_name(repo_to_fork)
25 vcs_type = repo_to_fork.repo_type
26
27 form_data = dict(
28 repo_name=fork_name,
29 repo_name_full=fork_name,
30 repo_group=None,
31 repo_type=vcs_type,
32 description='',
33 private=False,
34 copy_permissions=False,
35 landing_rev='tip',
36 update_after_clone=False,
37 fork_parent_id=repo_to_fork,
38 )
39 cur_user = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN)
40 RepoModel().create_fork(form_data, cur_user=cur_user)
41
42 Session().commit()
43 return Repository.get_by_repo_name(fork_name)
@@ -0,0 +1,79 b''
1 import os
2 import unittest
3 from rhodecode.tests import *
4
5 from rhodecode.model.meta import Session
6 from rhodecode.tests.fixture import Fixture
7 from rhodecode.model.repo import RepoModel
8 from rhodecode.model.db import Repository
9 from rhodecode.lib.exceptions import AttachedForksError
10
11 fixture = Fixture()
12
13
14 class TestRepos(unittest.TestCase):
15
16 def setUp(self):
17 pass
18
19 def tearDown(self):
20 Session.remove()
21
22 def test_remove_repo(self):
23 repo = fixture.create_repo(name='test-repo-1')
24 Session().commit()
25
26 RepoModel().delete(repo=repo)
27 Session().commit()
28
29 self.assertEqual(None, Repository.get_by_repo_name(repo_name='test-repo-1'))
30
31 def test_remove_repo_repo_raises_exc_when_attached_forks(self):
32 repo = fixture.create_repo(name='test-repo-1')
33 Session().commit()
34
35 fixture.create_fork(repo.repo_name, 'test-repo-fork-1')
36 Session().commit()
37
38 self.assertRaises(AttachedForksError, lambda: RepoModel().delete(repo=repo))
39
40 def test_remove_repo_delete_forks(self):
41 repo = fixture.create_repo(name='test-repo-1')
42 Session().commit()
43
44 fork = fixture.create_fork(repo.repo_name, 'test-repo-fork-1')
45 Session().commit()
46
47 #fork of fork
48 fixture.create_fork(fork.repo_name, 'test-repo-fork-fork-1')
49 Session().commit()
50
51 RepoModel().delete(repo=repo, forks='delete')
52 Session().commit()
53
54 self.assertEqual(None, Repository.get_by_repo_name(repo_name='test-repo-1'))
55 self.assertEqual(None, Repository.get_by_repo_name(repo_name='test-repo-fork-1'))
56 self.assertEqual(None, Repository.get_by_repo_name(repo_name='test-repo-fork-fork-1'))
57
58 def test_remove_repo_detach_forks(self):
59 repo = fixture.create_repo(name='test-repo-1')
60 Session().commit()
61
62 fork = fixture.create_fork(repo.repo_name, 'test-repo-fork-1')
63 Session().commit()
64
65 #fork of fork
66 fixture.create_fork(fork.repo_name, 'test-repo-fork-fork-1')
67 Session().commit()
68
69 RepoModel().delete(repo=repo, forks='detach')
70 Session().commit()
71
72 try:
73 self.assertEqual(None, Repository.get_by_repo_name(repo_name='test-repo-1'))
74 self.assertNotEqual(None, Repository.get_by_repo_name(repo_name='test-repo-fork-1'))
75 self.assertNotEqual(None, Repository.get_by_repo_name(repo_name='test-repo-fork-fork-1'))
76 finally:
77 RepoModel().delete(repo='test-repo-fork-fork-1')
78 RepoModel().delete(repo='test-repo-fork-1')
79 Session().commit()
General Comments 0
You need to be logged in to leave comments. Login now