annotate rhodecode/tests/models/test_repos.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 5067d6e826a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3642
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 import os
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 import unittest
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 from rhodecode.tests import *
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 from rhodecode.model.meta import Session
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 from rhodecode.tests.fixture import Fixture
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 from rhodecode.model.repo import RepoModel
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 from rhodecode.model.db import Repository
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 from rhodecode.lib.exceptions import AttachedForksError
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 fixture = Fixture()
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
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 class TestRepos(unittest.TestCase):
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 def setUp(self):
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 pass
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 def tearDown(self):
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 Session.remove()
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 def test_remove_repo(self):
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 repo = fixture.create_repo(name='test-repo-1')
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 Session().commit()
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 RepoModel().delete(repo=repo)
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 Session().commit()
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 self.assertEqual(None, Repository.get_by_repo_name(repo_name='test-repo-1'))
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 def test_remove_repo_repo_raises_exc_when_attached_forks(self):
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 repo = fixture.create_repo(name='test-repo-1')
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 Session().commit()
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 fixture.create_fork(repo.repo_name, 'test-repo-fork-1')
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 Session().commit()
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 self.assertRaises(AttachedForksError, lambda: RepoModel().delete(repo=repo))
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 def test_remove_repo_delete_forks(self):
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 repo = fixture.create_repo(name='test-repo-1')
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
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 fork = fixture.create_fork(repo.repo_name, 'test-repo-fork-1')
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 Session().commit()
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 #fork of fork
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 fixture.create_fork(fork.repo_name, 'test-repo-fork-fork-1')
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 Session().commit()
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 RepoModel().delete(repo=repo, forks='delete')
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 Session().commit()
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 self.assertEqual(None, Repository.get_by_repo_name(repo_name='test-repo-1'))
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 self.assertEqual(None, Repository.get_by_repo_name(repo_name='test-repo-fork-1'))
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 self.assertEqual(None, Repository.get_by_repo_name(repo_name='test-repo-fork-fork-1'))
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 def test_remove_repo_detach_forks(self):
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 repo = fixture.create_repo(name='test-repo-1')
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 Session().commit()
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 fork = fixture.create_fork(repo.repo_name, 'test-repo-fork-1')
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 Session().commit()
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 #fork of fork
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 fixture.create_fork(fork.repo_name, 'test-repo-fork-fork-1')
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 Session().commit()
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 RepoModel().delete(repo=repo, forks='detach')
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 Session().commit()
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 try:
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 self.assertEqual(None, Repository.get_by_repo_name(repo_name='test-repo-1'))
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 self.assertNotEqual(None, Repository.get_by_repo_name(repo_name='test-repo-fork-1'))
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 self.assertNotEqual(None, Repository.get_by_repo_name(repo_name='test-repo-fork-fork-1'))
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 finally:
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 RepoModel().delete(repo='test-repo-fork-fork-1')
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 RepoModel().delete(repo='test-repo-fork-1')
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 Session().commit()