Mercurial > kallithea
annotate rhodecode/tests/test_models.py @ 2461:015a42e970a6 beta
whitespace cleanup
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 15 Jun 2012 00:06:26 +0200 |
parents | 9492ab68331f |
children | 1f9c467e01eb |
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 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
7 from rhodecode.model.db import RepoGroup, User, Notification, UserNotification, \ |
2255
95800dad44d0
fixes for tests on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2129
diff
changeset
|
8 UsersGroup, UsersGroupMember, Permission, UsersGroupRepoGroupToPerm,\ |
95800dad44d0
fixes for tests on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2129
diff
changeset
|
9 Repository |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
10 from sqlalchemy.exc import IntegrityError |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
11 from rhodecode.model.user import UserModel |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
12 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
13 from rhodecode.model.meta import Session |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
14 from rhodecode.model.notification import NotificationModel |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
15 from rhodecode.model.users_group import UsersGroupModel |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
16 from rhodecode.lib.auth import AuthUser |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
17 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
18 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
19 def _make_group(path, desc='desc', parent_id=None, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
20 skip_if_exists=False): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
21 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
22 gr = RepoGroup.get_by_group_name(path) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
23 if gr and skip_if_exists: |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
24 return gr |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
25 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
26 gr = ReposGroupModel().create(path, desc, parent_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
27 return gr |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
28 |
1538
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 class TestReposGroups(unittest.TestCase): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
31 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
32 def setUp(self): |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
33 self.g1 = _make_group('test1', skip_if_exists=True) |
2059
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
34 Session.commit() |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
35 self.g2 = _make_group('test2', skip_if_exists=True) |
2059
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
36 Session.commit() |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
37 self.g3 = _make_group('test3', skip_if_exists=True) |
2059
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
38 Session.commit() |
1538
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 def tearDown(self): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
41 print 'out' |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
42 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
43 def __check_path(self, *path): |
2059
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
44 """ |
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
45 Checks the path for existance ! |
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
46 """ |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
47 path = [TESTS_TMP_PATH] + list(path) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
48 path = os.path.join(*path) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
49 return os.path.isdir(path) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
50 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
51 def _check_folders(self): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
52 print os.listdir(TESTS_TMP_PATH) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
53 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
54 def __delete_group(self, id_): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
55 ReposGroupModel().delete(id_) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
56 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
57 def __update_group(self, id_, path, desc='desc', parent_id=None): |
2059
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
58 form_data = dict( |
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
59 group_name=path, |
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
60 group_description=desc, |
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
61 group_parent_id=parent_id, |
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
62 perms_updates=[], |
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
63 perms_new=[] |
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
64 ) |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
65 gr = ReposGroupModel().update(id_, form_data) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
66 return gr |
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 def test_create_group(self): |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
69 g = _make_group('newGroup') |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
70 self.assertEqual(g.full_path, 'newGroup') |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
71 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
72 self.assertTrue(self.__check_path('newGroup')) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
73 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
74 def test_create_same_name_group(self): |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
75 self.assertRaises(IntegrityError, lambda:_make_group('newGroup')) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
76 Session.rollback() |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
77 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
78 def test_same_subgroup(self): |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
79 sg1 = _make_group('sub1', parent_id=self.g1.group_id) |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
84 ssg1 = _make_group('subsub1', parent_id=sg1.group_id) |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
85 self.assertEqual(ssg1.parent_group, sg1) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
86 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
|
87 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
|
88 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
89 def test_remove_group(self): |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
90 sg1 = _make_group('deleteme') |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
91 self.__delete_group(sg1.group_id) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
92 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
93 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
|
94 self.assertFalse(self.__check_path('deteteme')) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
95 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
96 sg1 = _make_group('deleteme', parent_id=self.g1.group_id) |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
97 self.__delete_group(sg1.group_id) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
98 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
99 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
|
100 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
|
101 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
102 def test_rename_single_group(self): |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
103 sg1 = _make_group('initial') |
1538
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 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
|
106 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
|
107 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
|
108 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
109 def test_update_group_parent(self): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
110 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
111 sg1 = _make_group('initial', parent_id=self.g1.group_id) |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
112 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
113 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
|
114 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
|
115 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
|
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, '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
|
118 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
|
119 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
|
120 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
121 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
|
122 self.assertTrue(self.__check_path('hello')) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
123 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
124 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
|
125 |
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
|
126 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
|
127 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
128 g1 = _make_group('g1') |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
129 g2 = _make_group('g2') |
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
|
130 |
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 # 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 repo_type='hg', |
2459
9492ab68331f
Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents:
2255
diff
changeset
|
139 clone_uri=None, |
9492ab68331f
Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents:
2255
diff
changeset
|
140 landing_rev='tip') |
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
|
141 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
|
142 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
|
143 |
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 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
|
145 |
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 # 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 |
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 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
|
155 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
|
156 |
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 # test repo |
2255
95800dad44d0
fixes for tests on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2129
diff
changeset
|
158 self.assertEqual(r.repo_name, RepoGroup.url_sep().join(['g2', 'g1', r.just_name])) |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
159 |
2059
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
160 def test_move_to_root(self): |
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
161 g1 = _make_group('t11') |
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
162 Session.commit() |
2255
95800dad44d0
fixes for tests on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2129
diff
changeset
|
163 g2 = _make_group('t22', parent_id=g1.group_id) |
2059
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
164 Session.commit() |
2064
c9adf2a4929a
added tests for users_group and issue #373
Marcin Kuzminski <marcin@python-works.com>
parents:
2059
diff
changeset
|
165 |
2255
95800dad44d0
fixes for tests on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2129
diff
changeset
|
166 self.assertEqual(g2.full_path, 't11/t22') |
2059
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
167 self.assertTrue(self.__check_path('t11', 't22')) |
2064
c9adf2a4929a
added tests for users_group and issue #373
Marcin Kuzminski <marcin@python-works.com>
parents:
2059
diff
changeset
|
168 |
2059
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
169 g2 = self.__update_group(g2.group_id, 'g22', parent_id=None) |
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
170 Session.commit() |
2064
c9adf2a4929a
added tests for users_group and issue #373
Marcin Kuzminski <marcin@python-works.com>
parents:
2059
diff
changeset
|
171 |
2255
95800dad44d0
fixes for tests on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2129
diff
changeset
|
172 self.assertEqual(g2.group_name, 'g22') |
2059
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
173 # we moved out group from t1 to '' so it's full path should be 'g2' |
2255
95800dad44d0
fixes for tests on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2129
diff
changeset
|
174 self.assertEqual(g2.full_path, 'g22') |
2059
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
175 self.assertFalse(self.__check_path('t11', 't22')) |
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
176 self.assertTrue(self.__check_path('g22')) |
2064
c9adf2a4929a
added tests for users_group and issue #373
Marcin Kuzminski <marcin@python-works.com>
parents:
2059
diff
changeset
|
177 |
2059
d7f1fe9cb146
fixes issue #366 setting null on parent_group didn't propagate to actually db field.
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
178 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
179 class TestUser(unittest.TestCase): |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
180 def __init__(self, methodName='runTest'): |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
181 Session.remove() |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
182 super(TestUser, self).__init__(methodName=methodName) |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1758
diff
changeset
|
183 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
184 def test_create_and_remove(self): |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
185 usr = UserModel().create_or_update(username=u'test_user', password=u'qweqwe', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
186 email=u'u232@rhodecode.org', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
187 name=u'u1', lastname=u'u1') |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
188 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
189 self.assertEqual(User.get_by_username(u'test_user'), usr) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
190 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
191 # make users group |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
192 users_group = UsersGroupModel().create('some_example_group') |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
193 Session.commit() |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
194 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
195 UsersGroupModel().add_user_to_group(users_group, usr) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
196 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
197 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
198 self.assertEqual(UsersGroup.get(users_group.users_group_id), users_group) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
199 self.assertEqual(UsersGroupMember.query().count(), 1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
200 UserModel().delete(usr.user_id) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
201 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
202 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
203 self.assertEqual(UsersGroupMember.query().all(), []) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
204 |
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
|
205 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
206 class TestNotifications(unittest.TestCase): |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
207 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
208 def __init__(self, methodName='runTest'): |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
209 Session.remove() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
210 self.u1 = UserModel().create_or_update(username=u'u1', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
211 password=u'qweqwe', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
212 email=u'u1@rhodecode.org', |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
213 name=u'u1', lastname=u'u1') |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
214 Session.commit() |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
215 self.u1 = self.u1.user_id |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
216 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
217 self.u2 = UserModel().create_or_update(username=u'u2', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
218 password=u'qweqwe', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
219 email=u'u2@rhodecode.org', |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
220 name=u'u2', lastname=u'u3') |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
221 Session.commit() |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
222 self.u2 = self.u2.user_id |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
223 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
224 self.u3 = UserModel().create_or_update(username=u'u3', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
225 password=u'qweqwe', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
226 email=u'u3@rhodecode.org', |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
227 name=u'u3', lastname=u'u3') |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
228 Session.commit() |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
229 self.u3 = self.u3.user_id |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
230 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
231 super(TestNotifications, self).__init__(methodName=methodName) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
232 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
233 def _clean_notifications(self): |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
234 for n in Notification.query().all(): |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
235 Session.delete(n) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
236 |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
237 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
238 self.assertEqual(Notification.query().all(), []) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
239 |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
240 def tearDown(self): |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
241 self._clean_notifications() |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
242 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
243 def test_create_notification(self): |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
244 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
245 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
246 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
247 usrs = [self.u1, self.u2] |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
248 notification = NotificationModel().create(created_by=self.u1, |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
249 subject=u'subj', body=u'hi there', |
1709 | 250 recipients=usrs) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
251 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
252 u1 = User.get(self.u1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
253 u2 = User.get(self.u2) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
254 u3 = User.get(self.u3) |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
255 notifications = Notification.query().all() |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
256 self.assertEqual(len(notifications), 1) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
257 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
258 unotification = UserNotification.query()\ |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
259 .filter(UserNotification.notification == notification).all() |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
260 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
261 self.assertEqual(notifications[0].recipients, [u1, u2]) |
1709 | 262 self.assertEqual(notification.notification_id, |
263 notifications[0].notification_id) | |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
264 self.assertEqual(len(unotification), len(usrs)) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
265 self.assertEqual([x.user.user_id for x in unotification], usrs) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
266 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
267 def test_user_notifications(self): |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
268 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
269 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
270 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
271 notification1 = NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
272 subject=u'subj', body=u'hi there1', |
1709 | 273 recipients=[self.u3]) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
274 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
275 notification2 = NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
276 subject=u'subj', body=u'hi there2', |
1709 | 277 recipients=[self.u3]) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
278 Session.commit() |
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
279 u3 = Session.query(User).get(self.u3) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
280 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
281 self.assertEqual(sorted([x.notification for x in u3.notifications]), |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
282 sorted([notification2, notification1])) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
283 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
284 def test_delete_notifications(self): |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
285 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
286 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
287 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
288 notification = NotificationModel().create(created_by=self.u1, |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
289 subject=u'title', body=u'hi there3', |
1709 | 290 recipients=[self.u3, self.u1, self.u2]) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
291 Session.commit() |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
292 notifications = Notification.query().all() |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
293 self.assertTrue(notification in notifications) |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
294 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
295 Notification.delete(notification.notification_id) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
296 Session.commit() |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
297 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
298 notifications = Notification.query().all() |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
299 self.assertFalse(notification in notifications) |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
300 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
301 un = UserNotification.query().filter(UserNotification.notification |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
302 == notification).all() |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
303 self.assertEqual(un, []) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
304 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
305 def test_delete_association(self): |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
306 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
307 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
308 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
309 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
310 notification = NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
311 subject=u'title', body=u'hi there3', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
312 recipients=[self.u3, self.u1, self.u2]) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
313 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
314 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
315 unotification = UserNotification.query()\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
316 .filter(UserNotification.notification == |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
317 notification)\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
318 .filter(UserNotification.user_id == self.u3)\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
319 .scalar() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
320 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
321 self.assertEqual(unotification.user_id, self.u3) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
322 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
323 NotificationModel().delete(self.u3, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
324 notification.notification_id) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
325 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
326 |
1733
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
327 u3notification = UserNotification.query()\ |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
328 .filter(UserNotification.notification == |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
329 notification)\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
330 .filter(UserNotification.user_id == self.u3)\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
331 .scalar() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
332 |
1733
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
333 self.assertEqual(u3notification, None) |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
334 |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
335 # notification object is still there |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
336 self.assertEqual(Notification.query().all(), [notification]) |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
337 |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
338 #u1 and u2 still have assignments |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
339 u1notification = UserNotification.query()\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
340 .filter(UserNotification.notification == |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
341 notification)\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
342 .filter(UserNotification.user_id == self.u1)\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
343 .scalar() |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
344 self.assertNotEqual(u1notification, None) |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
345 u2notification = UserNotification.query()\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
346 .filter(UserNotification.notification == |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
347 notification)\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
348 .filter(UserNotification.user_id == self.u2)\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
349 .scalar() |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
350 self.assertNotEqual(u2notification, None) |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
351 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
352 def test_notification_counter(self): |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
353 self._clean_notifications() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
354 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
355 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
356 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
357 NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
358 subject=u'title', body=u'hi there_delete', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
359 recipients=[self.u3, self.u1]) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
360 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
361 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
362 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
363 .get_unread_cnt_for_user(self.u1), 1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
364 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
365 .get_unread_cnt_for_user(self.u2), 0) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
366 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
367 .get_unread_cnt_for_user(self.u3), 1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
368 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
369 notification = NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
370 subject=u'title', body=u'hi there3', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
371 recipients=[self.u3, self.u1, self.u2]) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
372 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
373 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
374 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
375 .get_unread_cnt_for_user(self.u1), 2) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
376 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
377 .get_unread_cnt_for_user(self.u2), 1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
378 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
379 .get_unread_cnt_for_user(self.u3), 2) |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
380 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
381 |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
382 class TestUsers(unittest.TestCase): |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
383 |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
384 def __init__(self, methodName='runTest'): |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
385 super(TestUsers, self).__init__(methodName=methodName) |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
386 |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
387 def setUp(self): |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
388 self.u1 = UserModel().create_or_update(username=u'u1', |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
389 password=u'qweqwe', |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
390 email=u'u1@rhodecode.org', |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1758
diff
changeset
|
391 name=u'u1', lastname=u'u1') |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
392 |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
393 def tearDown(self): |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
394 perm = Permission.query().all() |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
395 for p in perm: |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
396 UserModel().revoke_perm(self.u1, p) |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1758
diff
changeset
|
397 |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
398 UserModel().delete(self.u1) |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
399 Session.commit() |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
400 |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
401 def test_add_perm(self): |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
402 perm = Permission.query().all()[0] |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
403 UserModel().grant_perm(self.u1, perm) |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
404 Session.commit() |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
405 self.assertEqual(UserModel().has_perm(self.u1, perm), True) |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
406 |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
407 def test_has_perm(self): |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
408 perm = Permission.query().all() |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
409 for p in perm: |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
410 has_p = UserModel().has_perm(self.u1, p) |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
411 self.assertEqual(False, has_p) |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
412 |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
413 def test_revoke_perm(self): |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
414 perm = Permission.query().all()[0] |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
415 UserModel().grant_perm(self.u1, perm) |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
416 Session.commit() |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
417 self.assertEqual(UserModel().has_perm(self.u1, perm), True) |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
418 |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
419 #revoke |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
420 UserModel().revoke_perm(self.u1, perm) |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
421 Session.commit() |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
422 self.assertEqual(UserModel().has_perm(self.u1, perm), False) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
423 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
424 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
425 class TestPermissions(unittest.TestCase): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
426 def __init__(self, methodName='runTest'): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
427 super(TestPermissions, self).__init__(methodName=methodName) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
428 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
429 def setUp(self): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
430 self.u1 = UserModel().create_or_update( |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
431 username=u'u1', password=u'qweqwe', |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
432 email=u'u1@rhodecode.org', name=u'u1', lastname=u'u1' |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
433 ) |
2124
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
434 self.u2 = UserModel().create_or_update( |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
435 username=u'u2', password=u'qweqwe', |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
436 email=u'u2@rhodecode.org', name=u'u2', lastname=u'u2' |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
437 ) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
438 self.anon = User.get_by_username('default') |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
439 self.a1 = UserModel().create_or_update( |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
440 username=u'a1', password=u'qweqwe', |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
441 email=u'a1@rhodecode.org', name=u'a1', lastname=u'a1', admin=True |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
442 ) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
443 Session.commit() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
444 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
445 def tearDown(self): |
2124
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
446 if hasattr(self, 'test_repo'): |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
447 RepoModel().delete(repo=self.test_repo) |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
448 UserModel().delete(self.u1) |
2124
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
449 UserModel().delete(self.u2) |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
450 UserModel().delete(self.a1) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
451 if hasattr(self, 'g1'): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
452 ReposGroupModel().delete(self.g1.group_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
453 if hasattr(self, 'g2'): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
454 ReposGroupModel().delete(self.g2.group_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
455 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
456 if hasattr(self, 'ug1'): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
457 UsersGroupModel().delete(self.ug1, force=True) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
458 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
459 Session.commit() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
460 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
461 def test_default_perms_set(self): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
462 u1_auth = AuthUser(user_id=self.u1.user_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
463 perms = { |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
464 'repositories_groups': {}, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
465 'global': set([u'hg.create.repository', u'repository.read', |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
466 u'hg.register.manual_activate']), |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
467 'repositories': {u'vcs_test_hg': u'repository.read'} |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
468 } |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
469 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO], |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
470 perms['repositories'][HG_REPO]) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
471 new_perm = 'repository.write' |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
472 RepoModel().grant_user_permission(repo=HG_REPO, user=self.u1, perm=new_perm) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
473 Session.commit() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
474 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
475 u1_auth = AuthUser(user_id=self.u1.user_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
476 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO], new_perm) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
477 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
478 def test_default_admin_perms_set(self): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
479 a1_auth = AuthUser(user_id=self.a1.user_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
480 perms = { |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
481 'repositories_groups': {}, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
482 'global': set([u'hg.admin']), |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
483 'repositories': {u'vcs_test_hg': u'repository.admin'} |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
484 } |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
485 self.assertEqual(a1_auth.permissions['repositories'][HG_REPO], |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
486 perms['repositories'][HG_REPO]) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
487 new_perm = 'repository.write' |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
488 RepoModel().grant_user_permission(repo=HG_REPO, user=self.a1, perm=new_perm) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
489 Session.commit() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
490 # cannot really downgrade admins permissions !? they still get's set as |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
491 # admin ! |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
492 u1_auth = AuthUser(user_id=self.a1.user_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
493 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO], |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
494 perms['repositories'][HG_REPO]) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
495 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
496 def test_default_group_perms(self): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
497 self.g1 = _make_group('test1', skip_if_exists=True) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
498 self.g2 = _make_group('test2', skip_if_exists=True) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
499 u1_auth = AuthUser(user_id=self.u1.user_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
500 perms = { |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
501 'repositories_groups': {u'test1': 'group.read', u'test2': 'group.read'}, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
502 'global': set([u'hg.create.repository', u'repository.read', u'hg.register.manual_activate']), |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
503 'repositories': {u'vcs_test_hg': u'repository.read'} |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
504 } |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
505 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO], |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
506 perms['repositories'][HG_REPO]) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
507 self.assertEqual(u1_auth.permissions['repositories_groups'], |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
508 perms['repositories_groups']) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
509 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
510 def test_default_admin_group_perms(self): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
511 self.g1 = _make_group('test1', skip_if_exists=True) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
512 self.g2 = _make_group('test2', skip_if_exists=True) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
513 a1_auth = AuthUser(user_id=self.a1.user_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
514 perms = { |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
515 'repositories_groups': {u'test1': 'group.admin', u'test2': 'group.admin'}, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
516 'global': set(['hg.admin']), |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
517 'repositories': {u'vcs_test_hg': 'repository.admin'} |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
518 } |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
519 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
520 self.assertEqual(a1_auth.permissions['repositories'][HG_REPO], |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
521 perms['repositories'][HG_REPO]) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
522 self.assertEqual(a1_auth.permissions['repositories_groups'], |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
523 perms['repositories_groups']) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
524 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
525 def test_propagated_permission_from_users_group(self): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
526 # make group |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
527 self.ug1 = UsersGroupModel().create('G1') |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
528 # add user to group |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
529 UsersGroupModel().add_user_to_group(self.ug1, self.u1) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
530 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
531 # set permission to lower |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
532 new_perm = 'repository.none' |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
533 RepoModel().grant_user_permission(repo=HG_REPO, user=self.u1, perm=new_perm) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
534 Session.commit() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
535 u1_auth = AuthUser(user_id=self.u1.user_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
536 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO], |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
537 new_perm) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
538 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
539 # grant perm for group this should override permission from user |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
540 new_perm = 'repository.write' |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
541 RepoModel().grant_users_group_permission(repo=HG_REPO, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
542 group_name=self.ug1, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
543 perm=new_perm) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
544 # check perms |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
545 u1_auth = AuthUser(user_id=self.u1.user_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
546 perms = { |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
547 'repositories_groups': {}, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
548 'global': set([u'hg.create.repository', u'repository.read', |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
549 u'hg.register.manual_activate']), |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
550 'repositories': {u'vcs_test_hg': u'repository.read'} |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
551 } |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
552 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO], |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
553 new_perm) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
554 self.assertEqual(u1_auth.permissions['repositories_groups'], |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
555 perms['repositories_groups']) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
556 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
557 def test_propagated_permission_from_users_group_lower_weight(self): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
558 # make group |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
559 self.ug1 = UsersGroupModel().create('G1') |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
560 # add user to group |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
561 UsersGroupModel().add_user_to_group(self.ug1, self.u1) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
562 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
563 # set permission to lower |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
564 new_perm_h = 'repository.write' |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
565 RepoModel().grant_user_permission(repo=HG_REPO, user=self.u1, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
566 perm=new_perm_h) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
567 Session.commit() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
568 u1_auth = AuthUser(user_id=self.u1.user_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
569 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO], |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
570 new_perm_h) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
571 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
572 # grant perm for group this should NOT override permission from user |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
573 # since it's lower than granted |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
574 new_perm_l = 'repository.read' |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
575 RepoModel().grant_users_group_permission(repo=HG_REPO, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
576 group_name=self.ug1, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
577 perm=new_perm_l) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
578 # check perms |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
579 u1_auth = AuthUser(user_id=self.u1.user_id) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
580 perms = { |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
581 'repositories_groups': {}, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
582 'global': set([u'hg.create.repository', u'repository.read', |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
583 u'hg.register.manual_activate']), |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
584 'repositories': {u'vcs_test_hg': u'repository.write'} |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
585 } |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
586 self.assertEqual(u1_auth.permissions['repositories'][HG_REPO], |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
587 new_perm_h) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
588 self.assertEqual(u1_auth.permissions['repositories_groups'], |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
589 perms['repositories_groups']) |
2124
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
590 |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
591 def test_repo_in_group_permissions(self): |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
592 self.g1 = _make_group('group1', skip_if_exists=True) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
593 self.g2 = _make_group('group2', skip_if_exists=True) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
594 Session.commit() |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
595 # both perms should be read ! |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
596 u1_auth = AuthUser(user_id=self.u1.user_id) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
597 self.assertEqual(u1_auth.permissions['repositories_groups'], |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
598 {u'group1': u'group.read', u'group2': u'group.read'}) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
599 |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
600 a1_auth = AuthUser(user_id=self.anon.user_id) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
601 self.assertEqual(a1_auth.permissions['repositories_groups'], |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
602 {u'group1': u'group.read', u'group2': u'group.read'}) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
603 |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
604 #Change perms to none for both groups |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
605 ReposGroupModel().grant_user_permission(repos_group=self.g1, |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
606 user=self.anon, |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
607 perm='group.none') |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
608 ReposGroupModel().grant_user_permission(repos_group=self.g2, |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
609 user=self.anon, |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
610 perm='group.none') |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
611 |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
612 u1_auth = AuthUser(user_id=self.u1.user_id) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
613 self.assertEqual(u1_auth.permissions['repositories_groups'], |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
614 {u'group1': u'group.none', u'group2': u'group.none'}) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
615 |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
616 a1_auth = AuthUser(user_id=self.anon.user_id) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
617 self.assertEqual(a1_auth.permissions['repositories_groups'], |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
618 {u'group1': u'group.none', u'group2': u'group.none'}) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
619 |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
620 # add repo to group |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
621 form_data = { |
2459
9492ab68331f
Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents:
2255
diff
changeset
|
622 'repo_name': HG_REPO, |
9492ab68331f
Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents:
2255
diff
changeset
|
623 'repo_name_full': RepoGroup.url_sep().join([self.g1.group_name,HG_REPO]), |
9492ab68331f
Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents:
2255
diff
changeset
|
624 'repo_type': 'hg', |
9492ab68331f
Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents:
2255
diff
changeset
|
625 'clone_uri': '', |
9492ab68331f
Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents:
2255
diff
changeset
|
626 'repo_group': self.g1.group_id, |
9492ab68331f
Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents:
2255
diff
changeset
|
627 'description': 'desc', |
9492ab68331f
Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents:
2255
diff
changeset
|
628 'private': False, |
9492ab68331f
Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents:
2255
diff
changeset
|
629 'landing_rev': 'tip' |
2124
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
630 } |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
631 self.test_repo = RepoModel().create(form_data, cur_user=self.u1) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
632 Session.commit() |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
633 |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
634 u1_auth = AuthUser(user_id=self.u1.user_id) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
635 self.assertEqual(u1_auth.permissions['repositories_groups'], |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
636 {u'group1': u'group.none', u'group2': u'group.none'}) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
637 |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
638 a1_auth = AuthUser(user_id=self.anon.user_id) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
639 self.assertEqual(a1_auth.permissions['repositories_groups'], |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
640 {u'group1': u'group.none', u'group2': u'group.none'}) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
641 |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
642 #grant permission for u2 ! |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
643 ReposGroupModel().grant_user_permission(repos_group=self.g1, |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
644 user=self.u2, |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
645 perm='group.read') |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
646 ReposGroupModel().grant_user_permission(repos_group=self.g2, |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
647 user=self.u2, |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
648 perm='group.read') |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
649 Session.commit() |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
650 self.assertNotEqual(self.u1, self.u2) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
651 #u1 and anon should have not change perms while u2 should ! |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
652 u1_auth = AuthUser(user_id=self.u1.user_id) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
653 self.assertEqual(u1_auth.permissions['repositories_groups'], |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
654 {u'group1': u'group.none', u'group2': u'group.none'}) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
655 |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
656 u2_auth = AuthUser(user_id=self.u2.user_id) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
657 self.assertEqual(u2_auth.permissions['repositories_groups'], |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
658 {u'group1': u'group.read', u'group2': u'group.read'}) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
659 |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
660 a1_auth = AuthUser(user_id=self.anon.user_id) |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
661 self.assertEqual(a1_auth.permissions['repositories_groups'], |
273ce1a99c3f
fixed #397 Private repository groups shows up before login
Marcin Kuzminski <marcin@python-works.com>
parents:
2064
diff
changeset
|
662 {u'group1': u'group.none', u'group2': u'group.none'}) |
2129
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
663 |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
664 def test_repo_group_user_as_user_group_member(self): |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
665 # create Group1 |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
666 self.g1 = _make_group('group1', skip_if_exists=True) |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
667 Session.commit() |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
668 a1_auth = AuthUser(user_id=self.anon.user_id) |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
669 |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
670 self.assertEqual(a1_auth.permissions['repositories_groups'], |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
671 {u'group1': u'group.read'}) |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
672 |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
673 # set default permission to none |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
674 ReposGroupModel().grant_user_permission(repos_group=self.g1, |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
675 user=self.anon, |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
676 perm='group.none') |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
677 # make group |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
678 self.ug1 = UsersGroupModel().create('G1') |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
679 # add user to group |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
680 UsersGroupModel().add_user_to_group(self.ug1, self.u1) |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
681 Session.commit() |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
682 |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
683 # check if user is in the group |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
684 membrs = [x.user_id for x in UsersGroupModel().get(self.ug1.users_group_id).members] |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
685 self.assertEqual(membrs, [self.u1.user_id]) |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
686 # add some user to that group |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
687 |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
688 # check his permissions |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
689 a1_auth = AuthUser(user_id=self.anon.user_id) |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
690 self.assertEqual(a1_auth.permissions['repositories_groups'], |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
691 {u'group1': u'group.none'}) |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
692 |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
693 u1_auth = AuthUser(user_id=self.u1.user_id) |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
694 self.assertEqual(u1_auth.permissions['repositories_groups'], |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
695 {u'group1': u'group.none'}) |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
696 |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
697 # grant ug1 read permissions for |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
698 ReposGroupModel().grant_users_group_permission(repos_group=self.g1, |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
699 group_name=self.ug1, |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
700 perm='group.read') |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
701 Session.commit() |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
702 # check if the |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
703 obj = Session.query(UsersGroupRepoGroupToPerm)\ |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
704 .filter(UsersGroupRepoGroupToPerm.group == self.g1)\ |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
705 .filter(UsersGroupRepoGroupToPerm.users_group == self.ug1)\ |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
706 .scalar() |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
707 self.assertEqual(obj.permission.permission_name, 'group.read') |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
708 |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
709 a1_auth = AuthUser(user_id=self.anon.user_id) |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
710 |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
711 self.assertEqual(a1_auth.permissions['repositories_groups'], |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
712 {u'group1': u'group.none'}) |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
713 |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
714 u1_auth = AuthUser(user_id=self.u1.user_id) |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
715 self.assertEqual(u1_auth.permissions['repositories_groups'], |
43481c3d70ca
#399 added inheritance of permissions for users group on repos groups
Marcin Kuzminski <marcin@python-works.com>
parents:
2124
diff
changeset
|
716 {u'group1': u'group.read'}) |