annotate rhodecode/tests/test_models.py @ 1707:54fda6ce9e98 beta

fixes timezone issues with tests
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 21 Nov 2011 02:53:17 +0200
parents 8cb7f5c4d494
children 5ca2a5e96793
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
1 import os
1373
66f03a87141c Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
2 import unittest
66f03a87141c Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
3 from rhodecode.tests import *
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
4
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
5 from rhodecode.model.repos_group import ReposGroupModel
1539
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
6 from rhodecode.model.repo import RepoModel
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
7 from rhodecode.model.db import RepoGroup, User, Notification, UserNotification
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
8 from sqlalchemy.exc import IntegrityError
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
9 from rhodecode.model.user import UserModel
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
10
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
11 from rhodecode.model import meta
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
12
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
13 Session = meta.Session()
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
14
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
15 class TestReposGroups(unittest.TestCase):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
16
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
17 def setUp(self):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
18 self.g1 = self.__make_group('test1', skip_if_exists=True)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
19 self.g2 = self.__make_group('test2', skip_if_exists=True)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
20 self.g3 = self.__make_group('test3', skip_if_exists=True)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
21
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
22 def tearDown(self):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
23 print 'out'
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
24
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
25 def __check_path(self, *path):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
26 path = [TESTS_TMP_PATH] + list(path)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
27 path = os.path.join(*path)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
28 return os.path.isdir(path)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
29
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
30 def _check_folders(self):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
31 print os.listdir(TESTS_TMP_PATH)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
32
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
33 def __make_group(self, path, desc='desc', parent_id=None,
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
34 skip_if_exists=False):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
35
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
36 gr = RepoGroup.get_by_group_name(path)
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
37 if gr and skip_if_exists:
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
38 return gr
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
39
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
40 form_data = dict(group_name=path,
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
41 group_description=desc,
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
42 group_parent_id=parent_id)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
43 gr = ReposGroupModel().create(form_data)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
44 return gr
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
45
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
46 def __delete_group(self, id_):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
47 ReposGroupModel().delete(id_)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
48
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
49
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
50 def __update_group(self, id_, path, desc='desc', parent_id=None):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
51 form_data = dict(group_name=path,
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
52 group_description=desc,
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
53 group_parent_id=parent_id)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
54
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
55 gr = ReposGroupModel().update(id_, form_data)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
56 return gr
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
57
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
58 def test_create_group(self):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
59 g = self.__make_group('newGroup')
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
60 self.assertEqual(g.full_path, 'newGroup')
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
61
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
62 self.assertTrue(self.__check_path('newGroup'))
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
63
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
64
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
65 def test_create_same_name_group(self):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
66 self.assertRaises(IntegrityError, lambda:self.__make_group('newGroup'))
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
67
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
68
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
69 def test_same_subgroup(self):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
70 sg1 = self.__make_group('sub1', parent_id=self.g1.group_id)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
71 self.assertEqual(sg1.parent_group, self.g1)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
72 self.assertEqual(sg1.full_path, 'test1/sub1')
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
73 self.assertTrue(self.__check_path('test1', 'sub1'))
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
74
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
75 ssg1 = self.__make_group('subsub1', parent_id=sg1.group_id)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
76 self.assertEqual(ssg1.parent_group, sg1)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
77 self.assertEqual(ssg1.full_path, 'test1/sub1/subsub1')
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
78 self.assertTrue(self.__check_path('test1', 'sub1', 'subsub1'))
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
79
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
80
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
81 def test_remove_group(self):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
82 sg1 = self.__make_group('deleteme')
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
83 self.__delete_group(sg1.group_id)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
84
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
85 self.assertEqual(RepoGroup.get(sg1.group_id), None)
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
86 self.assertFalse(self.__check_path('deteteme'))
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
87
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
88 sg1 = self.__make_group('deleteme', parent_id=self.g1.group_id)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
89 self.__delete_group(sg1.group_id)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
90
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
91 self.assertEqual(RepoGroup.get(sg1.group_id), None)
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
92 self.assertFalse(self.__check_path('test1', 'deteteme'))
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
93
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
94
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
95 def test_rename_single_group(self):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
96 sg1 = self.__make_group('initial')
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
97
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
98 new_sg1 = self.__update_group(sg1.group_id, 'after')
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
99 self.assertTrue(self.__check_path('after'))
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
100 self.assertEqual(RepoGroup.get_by_group_name('initial'), None)
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
101
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
102
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
103 def test_update_group_parent(self):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
104
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
105 sg1 = self.__make_group('initial', parent_id=self.g1.group_id)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
106
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
107 new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g1.group_id)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
108 self.assertTrue(self.__check_path('test1', 'after'))
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
109 self.assertEqual(RepoGroup.get_by_group_name('test1/initial'), None)
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
110
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
111
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
112 new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g3.group_id)
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
113 self.assertTrue(self.__check_path('test3', 'after'))
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
114 self.assertEqual(RepoGroup.get_by_group_name('test3/initial'), None)
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
115
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
116
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
117 new_sg1 = self.__update_group(sg1.group_id, 'hello')
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
118 self.assertTrue(self.__check_path('hello'))
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
119
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1539
diff changeset
120 self.assertEqual(RepoGroup.get_by_group_name('hello'), new_sg1)
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
121
1539
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
122
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
123
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
124 def test_subgrouping_with_repo(self):
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
125
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
126 g1 = self.__make_group('g1')
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
127 g2 = self.__make_group('g2')
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
128
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
129 # create new repo
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
130 form_data = dict(repo_name='john',
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
131 repo_name_full='john',
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
132 fork_name=None,
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
133 description=None,
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
134 repo_group=None,
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
135 private=False,
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
136 repo_type='hg',
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
137 clone_uri=None)
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
138 cur_user = User.get_by_username(TEST_USER_ADMIN_LOGIN)
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
139 r = RepoModel().create(form_data, cur_user)
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
140
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
141 self.assertEqual(r.repo_name, 'john')
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
142
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
143 # put repo into group
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
144 form_data = form_data
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
145 form_data['repo_group'] = g1.group_id
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
146 form_data['perms_new'] = []
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
147 form_data['perms_updates'] = []
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
148 RepoModel().update(r.repo_name, form_data)
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
149 self.assertEqual(r.repo_name, 'g1/john')
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
150
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
151
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
152 self.__update_group(g1.group_id, 'g1', parent_id=g2.group_id)
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
153 self.assertTrue(self.__check_path('g2', 'g1'))
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
154
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
155 # test repo
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
156 self.assertEqual(r.repo_name, os.path.join('g2', 'g1', r.just_name))
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
157
bd604cf75c5a fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
158
1702
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
159 class TestNotifications(unittest.TestCase):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
160
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
161
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
162
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
163 def setUp(self):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
164 self.u1 = UserModel().create_or_update(username='u1', password='qweqwe',
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
165 email='u1@rhodecode.org',
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
166 name='u1', lastname='u1')
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
167 self.u2 = UserModel().create_or_update(username='u2', password='qweqwe',
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
168 email='u2@rhodecode.org',
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
169 name='u2', lastname='u3')
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
170 self.u3 = UserModel().create_or_update(username='u3', password='qweqwe',
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
171 email='u3@rhodecode.org',
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
172 name='u3', lastname='u3')
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
173
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
174
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
175
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
176 def test_create_notification(self):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
177 usrs = [self.u1, self.u2]
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
178 notification = Notification.create(subject='subj', body='hi there',
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
179 recipients=usrs)
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
180
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
181 notifications = Session.query(Notification).all()
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
182 unotification = UserNotification.query()\
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
183 .filter(UserNotification.notification == notification).all()
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
184 self.assertEqual(len(notifications), 1)
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
185 self.assertEqual(notifications[0].recipients, [self.u1, self.u2])
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
186 self.assertEqual(notification, notifications[0])
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
187 self.assertEqual(len(unotification), len(usrs))
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
188 self.assertEqual([x.user.user_id for x in unotification],
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
189 [x.user_id for x in usrs])
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
190
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
191 def test_user_notifications(self):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
192 notification1 = Notification.create(subject='subj', body='hi there',
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
193 recipients=[self.u3])
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
194 notification2 = Notification.create(subject='subj', body='hi there',
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
195 recipients=[self.u3])
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
196 self.assertEqual(self.u3.notifications, [notification1, notification2])
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
197
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
198 def test_delete_notifications(self):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
199 notification = Notification.create(subject='title', body='hi there3',
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
200 recipients=[self.u3, self.u1, self.u2])
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
201 notifications = Notification.query().all()
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
202 self.assertTrue(notification in notifications)
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
203
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
204 Notification.delete(notification.notification_id)
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
205
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
206 notifications = Notification.query().all()
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
207 self.assertFalse(notification in notifications)
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
208
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
209 un = UserNotification.query().filter(UserNotification.notification
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
210 == notification).all()
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
211 self.assertEqual(un, [])
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
212
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
213 def tearDown(self):
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
214 User.delete(self.u1.user_id)
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
215 User.delete(self.u2.user_id)
8cb7f5c4d494 #302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
216 User.delete(self.u3.user_id)