Mercurial > kallithea
annotate rhodecode/tests/test_models.py @ 1749:8ecc6b8229a5 beta
commit less models
- models don't do any commits(with few exceptions)
- all db transactions should be handled by higher level modules like controllers, celery tasks
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 02 Dec 2011 22:31:13 +0200 |
parents | 48d4fcf04a29 |
children | a87aa385f21c |
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, \ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
8 UsersGroup, UsersGroupMember |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
9 from sqlalchemy.exc import IntegrityError |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
10 from rhodecode.model.user import UserModel |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
11 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
12 from rhodecode.model.meta import Session |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
13 from rhodecode.model.notification import NotificationModel |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
14 from rhodecode.model.users_group import UsersGroupModel |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
15 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
16 class TestReposGroups(unittest.TestCase): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
17 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
18 def setUp(self): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
19 self.g1 = self.__make_group('test1', skip_if_exists=True) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
20 self.g2 = self.__make_group('test2', skip_if_exists=True) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
21 self.g3 = self.__make_group('test3', skip_if_exists=True) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
22 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
23 def tearDown(self): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
24 print 'out' |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
25 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
26 def __check_path(self, *path): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
27 path = [TESTS_TMP_PATH] + list(path) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
28 path = os.path.join(*path) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
29 return os.path.isdir(path) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
30 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
31 def _check_folders(self): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
32 print os.listdir(TESTS_TMP_PATH) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
33 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
34 def __make_group(self, path, desc='desc', parent_id=None, |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
35 skip_if_exists=False): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
36 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
37 gr = RepoGroup.get_by_group_name(path) |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
38 if gr and skip_if_exists: |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
39 return gr |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
40 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
41 form_data = dict(group_name=path, |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
42 group_description=desc, |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
43 group_parent_id=parent_id) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
44 gr = ReposGroupModel().create(form_data) |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
45 Session.commit() |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
46 return gr |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
47 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
48 def __delete_group(self, id_): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
49 ReposGroupModel().delete(id_) |
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 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
52 def __update_group(self, id_, path, desc='desc', parent_id=None): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
53 form_data = dict(group_name=path, |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
54 group_description=desc, |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
55 group_parent_id=parent_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 gr = ReposGroupModel().update(id_, form_data) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
58 return gr |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
59 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
60 def test_create_group(self): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
61 g = self.__make_group('newGroup') |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
62 self.assertEqual(g.full_path, 'newGroup') |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
63 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
64 self.assertTrue(self.__check_path('newGroup')) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
65 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
66 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
67 def test_create_same_name_group(self): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
68 self.assertRaises(IntegrityError, lambda:self.__make_group('newGroup')) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
69 Session.rollback() |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
70 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
71 def test_same_subgroup(self): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
72 sg1 = self.__make_group('sub1', parent_id=self.g1.group_id) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
73 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
|
74 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
|
75 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
|
76 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
77 ssg1 = self.__make_group('subsub1', parent_id=sg1.group_id) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
78 self.assertEqual(ssg1.parent_group, sg1) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
79 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
|
80 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
|
81 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
82 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
83 def test_remove_group(self): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
84 sg1 = self.__make_group('deleteme') |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
85 self.__delete_group(sg1.group_id) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
86 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
87 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
|
88 self.assertFalse(self.__check_path('deteteme')) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
89 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
90 sg1 = self.__make_group('deleteme', parent_id=self.g1.group_id) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
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('test1', 'deteteme')) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
95 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
96 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
97 def test_rename_single_group(self): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
98 sg1 = self.__make_group('initial') |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
99 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 |
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 def test_update_group_parent(self): |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
106 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
107 sg1 = self.__make_group('initial', parent_id=self.g1.group_id) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
108 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
113 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
118 |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
119 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
|
120 self.assertTrue(self.__check_path('hello')) |
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
121 |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
122 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
|
123 |
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
|
124 |
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
125 |
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
126 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 |
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
128 g1 = self.__make_group('g1') |
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
129 g2 = self.__make_group('g2') |
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
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', |
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
139 clone_uri=None) |
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
140 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
|
141 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
|
142 |
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
143 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
|
144 |
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 # 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 |
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 |
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
158 self.assertEqual(r.repo_name, os.path.join('g2', 'g1', r.just_name)) |
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
159 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
160 class TestUser(unittest.TestCase): |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
161 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
162 def test_create_and_remove(self): |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
163 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
|
164 email=u'u232@rhodecode.org', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
165 name=u'u1', lastname=u'u1') |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
166 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
167 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
|
168 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
169 # make users group |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
170 users_group = UsersGroupModel().create('some_example_group') |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
171 Session.commit() |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
172 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
173 UsersGroupModel().add_user_to_group(users_group, usr) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
174 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
175 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
176 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
|
177 self.assertEqual(UsersGroupMember.query().count(), 1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
178 UserModel().delete(usr.user_id) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
179 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
180 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
181 self.assertEqual(UsersGroupMember.query().all(), []) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
182 |
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
|
183 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
184 class TestNotifications(unittest.TestCase): |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
185 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
186 def __init__(self, methodName='runTest'): |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
187 self.u1 = UserModel().create_or_update(username=u'u1', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
188 password=u'qweqwe', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
189 email=u'u1@rhodecode.org', |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
190 name=u'u1', lastname=u'u1') |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
191 Session.commit() |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
192 self.u1 = self.u1.user_id |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
193 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
194 self.u2 = UserModel().create_or_update(username=u'u2', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
195 password=u'qweqwe', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
196 email=u'u2@rhodecode.org', |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
197 name=u'u2', lastname=u'u3') |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
198 Session.commit() |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
199 self.u2 = self.u2.user_id |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
200 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
201 self.u3 = UserModel().create_or_update(username=u'u3', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
202 password=u'qweqwe', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
203 email=u'u3@rhodecode.org', |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
204 name=u'u3', lastname=u'u3') |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
205 Session.commit() |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
206 self.u3 = self.u3.user_id |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
207 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
208 super(TestNotifications, self).__init__(methodName=methodName) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
209 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
210 def _clean_notifications(self): |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
211 for n in Notification.query().all(): |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
212 Session.delete(n) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
213 |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
214 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
215 self.assertEqual(Notification.query().all(), []) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
216 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
217 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
218 def test_create_notification(self): |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
219 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
220 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
221 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
222 usrs = [self.u1, self.u2] |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
223 notification = NotificationModel().create(created_by=self.u1, |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
224 subject=u'subj', body=u'hi there', |
1709 | 225 recipients=usrs) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
226 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
227 u1 = User.get(self.u1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
228 u2 = User.get(self.u2) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
229 u3 = User.get(self.u3) |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
230 notifications = Notification.query().all() |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
231 self.assertEqual(len(notifications), 1) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
232 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
233 unotification = UserNotification.query()\ |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
234 .filter(UserNotification.notification == notification).all() |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
235 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
236 self.assertEqual(notifications[0].recipients, [u1, u2]) |
1709 | 237 self.assertEqual(notification.notification_id, |
238 notifications[0].notification_id) | |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
239 self.assertEqual(len(unotification), len(usrs)) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
240 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
|
241 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
242 self._clean_notifications() |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
243 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
244 def test_user_notifications(self): |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
245 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
246 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
247 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
248 notification1 = NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
249 subject=u'subj', body=u'hi there1', |
1709 | 250 recipients=[self.u3]) |
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 notification2 = NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
253 subject=u'subj', body=u'hi there2', |
1709 | 254 recipients=[self.u3]) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
255 Session.commit() |
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
256 u3 = Session.query(User).get(self.u3) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
257 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
258 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
|
259 sorted([notification2, notification1])) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
260 self._clean_notifications() |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
261 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
262 def test_delete_notifications(self): |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
263 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
264 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
265 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
266 notification = NotificationModel().create(created_by=self.u1, |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
267 subject=u'title', body=u'hi there3', |
1709 | 268 recipients=[self.u3, self.u1, self.u2]) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
269 Session.commit() |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
270 notifications = Notification.query().all() |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
271 self.assertTrue(notification in notifications) |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
272 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
273 Notification.delete(notification.notification_id) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
274 Session.commit() |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
275 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
276 notifications = Notification.query().all() |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
277 self.assertFalse(notification in notifications) |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
278 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
279 un = UserNotification.query().filter(UserNotification.notification |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
280 == notification).all() |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
281 self.assertEqual(un, []) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
282 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
283 self._clean_notifications() |
1733
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
284 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
285 def test_delete_association(self): |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
286 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
287 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
288 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
289 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
290 notification = NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
291 subject=u'title', body=u'hi there3', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
292 recipients=[self.u3, self.u1, self.u2]) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
293 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
294 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
295 unotification = UserNotification.query()\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
296 .filter(UserNotification.notification == |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
297 notification)\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
298 .filter(UserNotification.user_id == self.u3)\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
299 .scalar() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
300 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
301 self.assertEqual(unotification.user_id, self.u3) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
302 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
303 NotificationModel().delete(self.u3, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
304 notification.notification_id) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
305 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
306 |
1733
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
307 u3notification = UserNotification.query()\ |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
308 .filter(UserNotification.notification == |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
309 notification)\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
310 .filter(UserNotification.user_id == self.u3)\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
311 .scalar() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
312 |
1733
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
313 self.assertEqual(u3notification, None) |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
314 |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
315 # notification object is still there |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
316 self.assertEqual(Notification.query().all(), [notification]) |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
317 |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
318 #u1 and u2 still have assignments |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
319 u1notification = UserNotification.query()\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
320 .filter(UserNotification.notification == |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
321 notification)\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
322 .filter(UserNotification.user_id == self.u1)\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
323 .scalar() |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
324 self.assertNotEqual(u1notification, None) |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
325 u2notification = UserNotification.query()\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
326 .filter(UserNotification.notification == |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
327 notification)\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
328 .filter(UserNotification.user_id == self.u2)\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
329 .scalar() |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
330 self.assertNotEqual(u2notification, None) |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
331 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
332 self._clean_notifications() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
333 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
334 def test_notification_counter(self): |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
335 self._clean_notifications() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
336 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
337 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
338 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
339 NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
340 subject=u'title', body=u'hi there_delete', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
341 recipients=[self.u3, self.u1]) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
342 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
343 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
344 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
345 .get_unread_cnt_for_user(self.u1), 1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
346 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
347 .get_unread_cnt_for_user(self.u2), 0) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
348 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
349 .get_unread_cnt_for_user(self.u3), 1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
350 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
351 notification = NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
352 subject=u'title', body=u'hi there3', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
353 recipients=[self.u3, self.u1, self.u2]) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1734
diff
changeset
|
354 Session.commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
355 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
356 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
357 .get_unread_cnt_for_user(self.u1), 2) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
358 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
359 .get_unread_cnt_for_user(self.u2), 1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
360 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
361 .get_unread_cnt_for_user(self.u3), 2) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
362 self._clean_notifications() |