annotate rhodecode/tests/other/test_validators.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl

Imported some of the GPLv3'd changes from RhodeCode v2.2.5. This imports changes between changesets 21af6c4eab3d and 6177597791c2 in RhodeCode's original repository, including only changes to Python files and HTML. RhodeCode clearly licensed its changes to these files under GPLv3 in their /LICENSE file, which states the following: The Python code and integrated HTML are licensed under the GPLv3 license. (See: https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE or http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE for an online copy of that LICENSE file) Conservancy reviewed these changes and confirmed that they can be licensed as a whole to the Kallithea project under GPLv3-only. While some of the contents committed herein are clearly licensed GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the statement above from RhodeCode indicates that they intend GPLv3-only as their license, per GPLv3§14 and other relevant sections of GPLv3.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:13 -0400
parents b84c83b651de
children 7e5f8c12a3fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 import formencode
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 from rhodecode.tests import *
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 from rhodecode.model import validators as v
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3889
diff changeset
7 from rhodecode.model.user_group import UserGroupModel
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 from rhodecode.model.meta import Session
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3889
diff changeset
10 from rhodecode.model.repo_group import RepoGroupModel
2898
74672d4bdbee fixed validator tests
Marcin Kuzminski <marcin@python-works.com>
parents: 2721
diff changeset
11 from rhodecode.model.db import ChangesetStatus, Repository
2721
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
12 from rhodecode.model.changeset_status import ChangesetStatusModel
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3674
diff changeset
13 from rhodecode.tests.fixture import Fixture
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3674
diff changeset
14
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3674
diff changeset
15 fixture = Fixture()
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3889
diff changeset
18 class TestRepoGroups(BaseTestCase):
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 def setUp(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 pass
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 def tearDown(self):
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
24 Session.remove()
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 def test_Message_extractor(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 validator = v.ValidUsername()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 self.assertRaises(formencode.Invalid, validator.to_python, 'default')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 class StateObj(object):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 pass
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 validator.to_python, 'default', StateObj)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 def test_ValidUsername(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 validator = v.ValidUsername()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 self.assertRaises(formencode.Invalid, validator.to_python, 'default')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 self.assertRaises(formencode.Invalid, validator.to_python, 'new_user')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 self.assertRaises(formencode.Invalid, validator.to_python, '.,')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 self.assertRaises(formencode.Invalid, validator.to_python,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 TEST_USER_ADMIN_LOGIN)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 self.assertEqual('test', validator.to_python('test'))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 validator = v.ValidUsername(edit=True, old_data={'user_id': 1})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 def test_ValidRepoUser(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 validator = v.ValidRepoUser()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 self.assertRaises(formencode.Invalid, validator.to_python, 'nouser')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 self.assertEqual(TEST_USER_ADMIN_LOGIN,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 validator.to_python(TEST_USER_ADMIN_LOGIN))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3222
diff changeset
54 def test_ValidUserGroup(self):
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3222
diff changeset
55 validator = v.ValidUserGroup()
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 self.assertRaises(formencode.Invalid, validator.to_python, 'default')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 self.assertRaises(formencode.Invalid, validator.to_python, '.,')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3674
diff changeset
59 gr = fixture.create_user_group('test')
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3674
diff changeset
60 gr2 = fixture.create_user_group('tes2')
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3674
diff changeset
61 Session().commit()
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 self.assertRaises(formencode.Invalid, validator.to_python, 'test')
3889
b84c83b651de replace equality comparision to None
Marcin Kuzminski <marcin@python-works.com>
parents: 3829
diff changeset
63 assert gr.users_group_id is not None
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3222
diff changeset
64 validator = v.ValidUserGroup(edit=True,
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 old_data={'users_group_id':
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 gr2.users_group_id})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 self.assertRaises(formencode.Invalid, validator.to_python, 'test')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 self.assertRaises(formencode.Invalid, validator.to_python, 'TesT')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 self.assertRaises(formencode.Invalid, validator.to_python, 'TEST')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3222
diff changeset
71 UserGroupModel().delete(gr)
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3222
diff changeset
72 UserGroupModel().delete(gr2)
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3674
diff changeset
73 Session().commit()
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3889
diff changeset
75 def test_ValidRepoGroup(self):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3889
diff changeset
76 validator = v.ValidRepoGroup()
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3889
diff changeset
77 model = RepoGroupModel()
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 self.assertRaises(formencode.Invalid, validator.to_python,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 {'group_name': HG_REPO, })
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 gr = model.create(group_name='test_gr', group_description='desc',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 parent=None,
3222
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 2898
diff changeset
82 just_db=True,
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 2898
diff changeset
83 owner=TEST_USER_ADMIN_LOGIN)
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 validator.to_python, {'group_name': gr.group_name, })
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3889
diff changeset
87 validator = v.ValidRepoGroup(edit=True,
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 old_data={'group_id': gr.group_id})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 validator.to_python, {
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 'group_name': gr.group_name + 'n',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 'group_parent_id': gr.group_id
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 })
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 model.delete(gr)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 def test_ValidPassword(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 validator = v.ValidPassword()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 self.assertEqual('lol', validator.to_python('lol'))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 self.assertEqual(None, validator.to_python(None))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 self.assertRaises(formencode.Invalid, validator.to_python, 'ąćżź')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 def test_ValidPasswordsMatch(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 validator = v.ValidPasswordsMatch()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 validator.to_python, {'password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 'password_confirmation': 'pass2'})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 validator.to_python, {'new_password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 'password_confirmation': 'pass2'})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 self.assertEqual({'new_password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 'password_confirmation': 'pass'},
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114 validator.to_python({'new_password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115 'password_confirmation': 'pass'}))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 self.assertEqual({'password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 'password_confirmation': 'pass'},
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 validator.to_python({'password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
120 'password_confirmation': 'pass'}))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
122 def test_ValidAuth(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
123 validator = v.ValidAuth()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
124 valid_creds = {
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125 'username': TEST_USER_REGULAR2_LOGIN,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
126 'password': TEST_USER_REGULAR2_PASS,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
127 }
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
128 invalid_creds = {
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
129 'username': 'err',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
130 'password': 'err',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
131 }
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
132 self.assertEqual(valid_creds, validator.to_python(valid_creds))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
133 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
134 validator.to_python, invalid_creds)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136 def test_ValidAuthToken(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 validator = v.ValidAuthToken()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138 # this is untestable without a threadlocal
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
139 # self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140 # validator.to_python, 'BadToken')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141 validator
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
142
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 def test_ValidRepoName(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
144 validator = v.ValidRepoName()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
145
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
146 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
147 validator.to_python, {'repo_name': ''})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
148
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150 validator.to_python, {'repo_name': HG_REPO})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
151
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3889
diff changeset
152 gr = RepoGroupModel().create(group_name='group_test',
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
153 group_description='desc',
3222
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 2898
diff changeset
154 parent=None,
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 2898
diff changeset
155 owner=TEST_USER_ADMIN_LOGIN)
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
156 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
157 validator.to_python, {'repo_name': gr.group_name})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
158
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
159 #TODO: write an error case for that ie. create a repo withinh a group
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
160 # self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
161 # validator.to_python, {'repo_name': 'some',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
162 # 'repo_group': gr.group_id})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
163
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
164 def test_ValidForkName(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
165 # this uses ValidRepoName validator
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
166 assert True
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
167
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
168 @parameterized.expand([
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
169 ('test', 'test'), ('lolz!', 'lolz'), (' aavv', 'aavv'),
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
170 ('ala ma kota', 'ala-ma-kota'), ('@nooo', 'nooo'),
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
171 ('$!haha lolz !', 'haha-lolz'), ('$$$$$', ''), ('{}OK!', 'OK'),
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
172 ('/]re po', 're-po')])
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
173 def test_SlugifyName(self, name, expected):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
174 validator = v.SlugifyName()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
175 self.assertEqual(expected, validator.to_python(name))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
176
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
177 def test_ValidCloneUri(self):
2557
1284b2eaade6 skip failures for two tests in validators
Marcin Kuzminski <marcin@python-works.com>
parents: 2515
diff changeset
178 #TODO: write this one
1284b2eaade6 skip failures for two tests in validators
Marcin Kuzminski <marcin@python-works.com>
parents: 2515
diff changeset
179 pass
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
180
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
181 def test_ValidForkType(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
182 validator = v.ValidForkType(old_data={'repo_type': 'hg'})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
183 self.assertEqual('hg', validator.to_python('hg'))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
184 self.assertRaises(formencode.Invalid, validator.to_python, 'git')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
185
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
186 def test_ValidPerms(self):
2557
1284b2eaade6 skip failures for two tests in validators
Marcin Kuzminski <marcin@python-works.com>
parents: 2515
diff changeset
187 #TODO: write this one
1284b2eaade6 skip failures for two tests in validators
Marcin Kuzminski <marcin@python-works.com>
parents: 2515
diff changeset
188 pass
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
189
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
190 def test_ValidSettings(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
191 validator = v.ValidSettings()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
192 self.assertEqual({'pass': 'pass'},
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
193 validator.to_python(value={'user': 'test',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
194 'pass': 'pass'}))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
195
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
196 self.assertEqual({'user2': 'test', 'pass': 'pass'},
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
197 validator.to_python(value={'user2': 'test',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
198 'pass': 'pass'}))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
199
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
200 def test_ValidPath(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
201 validator = v.ValidPath()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
202 self.assertEqual(TESTS_TMP_PATH,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
203 validator.to_python(TESTS_TMP_PATH))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
204 self.assertRaises(formencode.Invalid, validator.to_python,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
205 '/no_such_dir')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
206
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
207 def test_UniqSystemEmail(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
208 validator = v.UniqSystemEmail(old_data={})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
209
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
210 self.assertEqual('mail@python.org',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
211 validator.to_python('MaiL@Python.org'))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
212
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
213 email = TEST_USER_REGULAR2_EMAIL
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
214 self.assertRaises(formencode.Invalid, validator.to_python, email)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
215
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
216 def test_ValidSystemEmail(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
217 validator = v.ValidSystemEmail()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
218 email = TEST_USER_REGULAR2_EMAIL
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
219
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
220 self.assertEqual(email, validator.to_python(email))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
221 self.assertRaises(formencode.Invalid, validator.to_python, 'err')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
222
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
223 def test_LdapLibValidator(self):
3674
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
224 if ldap_lib_installed:
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
225 validator = v.LdapLibValidator()
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
226 self.assertEqual("DN", validator.to_python('DN'))
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
227 else:
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
228 validator = v.LdapLibValidator()
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
229 self.assertRaises(v.LdapImportError, validator.to_python, 'err')
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
230
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
231 def test_AttrLoginValidator(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
232 validator = v.AttrLoginValidator()
3674
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
233 self.assertEqual('DN_attr', validator.to_python('DN_attr'))
2721
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
234
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
235 def test_NotReviewedRevisions(self):
2898
74672d4bdbee fixed validator tests
Marcin Kuzminski <marcin@python-works.com>
parents: 2721
diff changeset
236 repo_id = Repository.get_by_repo_name(HG_REPO).repo_id
74672d4bdbee fixed validator tests
Marcin Kuzminski <marcin@python-works.com>
parents: 2721
diff changeset
237 validator = v.NotReviewedRevisions(repo_id)
2721
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
238 rev = '0' * 40
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
239 # add status for a rev, that should throw an error because it is already
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
240 # reviewed
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
241 new_status = ChangesetStatus()
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
242 new_status.author = ChangesetStatusModel()._get_user(TEST_USER_ADMIN_LOGIN)
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
243 new_status.repo = ChangesetStatusModel()._get_repo(HG_REPO)
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
244 new_status.status = ChangesetStatus.STATUS_APPROVED
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
245 new_status.comment = None
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
246 new_status.revision = rev
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
247 Session().add(new_status)
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
248 Session().commit()
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
249 try:
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
250 self.assertRaises(formencode.Invalid, validator.to_python, [rev])
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
251 finally:
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
252 Session().delete(new_status)
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
253 Session().commit()