annotate rhodecode/tests/test_validators.py @ 3651:659bd922520e beta

config: rename options to show_revision_number and show_sha_length 'sha_show_numeric_rev' had nothing to do with the sha value. The revision numbers are kind of native to Mercurial and there they are known as 'revision numbers'. 'sha_len' was very short and didn't clarify that it only controlled what was shown. These settings are currently only used in the changelog, but they should be used everywhere.
author Mads Kiilerich <madski@unity3d.com>
date Wed, 03 Apr 2013 15:56:12 +0200
parents 8a86836fad64
children ff2ea58debb5
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 unittest
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 import formencode
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 from rhodecode.tests import *
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 from rhodecode.model import validators as v
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3222
diff changeset
8 from rhodecode.model.users_group import UserGroupModel
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 from rhodecode.model.meta import Session
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 from rhodecode.model.repos_group import ReposGroupModel
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 from rhodecode.config.routing import ADMIN_PREFIX
2898
74672d4bdbee fixed validator tests
Marcin Kuzminski <marcin@python-works.com>
parents: 2721
diff changeset
13 from rhodecode.model.db import ChangesetStatus, Repository
2721
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
14 from rhodecode.model.changeset_status import ChangesetStatusModel
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15
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 class TestReposGroups(unittest.TestCase):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 def setUp(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 pass
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 def tearDown(self):
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3417
diff changeset
23 Session.remove()
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 def test_Message_extractor(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 validator = v.ValidUsername()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 self.assertRaises(formencode.Invalid, validator.to_python, 'default')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 class StateObj(object):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 pass
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 validator.to_python, 'default', StateObj)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 def test_ValidUsername(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 validator = v.ValidUsername()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 self.assertRaises(formencode.Invalid, validator.to_python, 'default')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 self.assertRaises(formencode.Invalid, validator.to_python, 'new_user')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 self.assertRaises(formencode.Invalid, validator.to_python, '.,')
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 TEST_USER_ADMIN_LOGIN)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 self.assertEqual('test', validator.to_python('test'))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 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
46
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 def test_ValidRepoUser(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 validator = v.ValidRepoUser()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 self.assertRaises(formencode.Invalid, validator.to_python, 'nouser')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 self.assertEqual(TEST_USER_ADMIN_LOGIN,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 validator.to_python(TEST_USER_ADMIN_LOGIN))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3222
diff changeset
53 def test_ValidUserGroup(self):
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3222
diff changeset
54 validator = v.ValidUserGroup()
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 self.assertRaises(formencode.Invalid, validator.to_python, 'default')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 self.assertRaises(formencode.Invalid, validator.to_python, '.,')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3222
diff changeset
58 gr = UserGroupModel().create('test')
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3222
diff changeset
59 gr2 = UserGroupModel().create('tes2')
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 Session.commit()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 self.assertRaises(formencode.Invalid, validator.to_python, 'test')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 assert gr.users_group_id != None
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3222
diff changeset
63 validator = v.ValidUserGroup(edit=True,
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 old_data={'users_group_id':
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 gr2.users_group_id})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 self.assertRaises(formencode.Invalid, validator.to_python, 'test')
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')
3417
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3222
diff changeset
70 UserGroupModel().delete(gr)
fa6ba6727475 further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents: 3222
diff changeset
71 UserGroupModel().delete(gr2)
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 Session.commit()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 def test_ValidReposGroup(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 validator = v.ValidReposGroup()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 model = ReposGroupModel()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 self.assertRaises(formencode.Invalid, validator.to_python,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 {'group_name': HG_REPO, })
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 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
80 parent=None,
3222
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 2898
diff changeset
81 just_db=True,
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 2898
diff changeset
82 owner=TEST_USER_ADMIN_LOGIN)
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 validator.to_python, {'group_name': gr.group_name, })
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86 validator = v.ValidReposGroup(edit=True,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 old_data={'group_id': gr.group_id})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 validator.to_python, {
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 'group_name': gr.group_name + 'n',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 'group_parent_id': gr.group_id
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 })
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 model.delete(gr)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 def test_ValidPassword(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 validator = v.ValidPassword()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 self.assertEqual('lol', validator.to_python('lol'))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 self.assertEqual(None, validator.to_python(None))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 self.assertRaises(formencode.Invalid, validator.to_python, 'ąćżź')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 def test_ValidPasswordsMatch(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 validator = v.ValidPasswordsMatch()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 validator.to_python, {'password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 'password_confirmation': 'pass2'})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108 validator.to_python, {'new_password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 'password_confirmation': 'pass2'})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 self.assertEqual({'new_password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 'password_confirmation': 'pass'},
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 validator.to_python({'new_password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114 'password_confirmation': 'pass'}))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 self.assertEqual({'password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 'password_confirmation': 'pass'},
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 validator.to_python({'password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 'password_confirmation': 'pass'}))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
120
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121 def test_ValidAuth(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
122 validator = v.ValidAuth()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
123 valid_creds = {
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
124 'username': TEST_USER_REGULAR2_LOGIN,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125 'password': TEST_USER_REGULAR2_PASS,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
126 }
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
127 invalid_creds = {
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
128 'username': 'err',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
129 'password': 'err',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
130 }
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
131 self.assertEqual(valid_creds, validator.to_python(valid_creds))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
132 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
133 validator.to_python, invalid_creds)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
134
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 def test_ValidAuthToken(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136 validator = v.ValidAuthToken()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 # this is untestable without a threadlocal
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138 # self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
139 # validator.to_python, 'BadToken')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140 validator
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
142 def test_ValidRepoName(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 validator = v.ValidRepoName()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
144
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
145 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
146 validator.to_python, {'repo_name': ''})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
147
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
148 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149 validator.to_python, {'repo_name': HG_REPO})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
151 gr = ReposGroupModel().create(group_name='group_test',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
152 group_description='desc',
3222
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 2898
diff changeset
153 parent=None,
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 2898
diff changeset
154 owner=TEST_USER_ADMIN_LOGIN)
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
155 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
156 validator.to_python, {'repo_name': gr.group_name})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
157
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
158 #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
159 # self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
160 # validator.to_python, {'repo_name': 'some',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
161 # 'repo_group': gr.group_id})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
162
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
163 def test_ValidForkName(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
164 # this uses ValidRepoName validator
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
165 assert True
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
166
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
167 @parameterized.expand([
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
168 ('test', 'test'), ('lolz!', 'lolz'), (' aavv', 'aavv'),
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
169 ('ala ma kota', 'ala-ma-kota'), ('@nooo', 'nooo'),
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
170 ('$!haha lolz !', 'haha-lolz'), ('$$$$$', ''), ('{}OK!', 'OK'),
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
171 ('/]re po', 're-po')])
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
172 def test_SlugifyName(self, name, expected):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
173 validator = v.SlugifyName()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
174 self.assertEqual(expected, validator.to_python(name))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
175
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
176 def test_ValidCloneUri(self):
2557
1284b2eaade6 skip failures for two tests in validators
Marcin Kuzminski <marcin@python-works.com>
parents: 2515
diff changeset
177 #TODO: write this one
1284b2eaade6 skip failures for two tests in validators
Marcin Kuzminski <marcin@python-works.com>
parents: 2515
diff changeset
178 pass
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
179
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
180 def test_ValidForkType(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
181 validator = v.ValidForkType(old_data={'repo_type': 'hg'})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
182 self.assertEqual('hg', validator.to_python('hg'))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
183 self.assertRaises(formencode.Invalid, validator.to_python, 'git')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
184
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
185 def test_ValidPerms(self):
2557
1284b2eaade6 skip failures for two tests in validators
Marcin Kuzminski <marcin@python-works.com>
parents: 2515
diff changeset
186 #TODO: write this one
1284b2eaade6 skip failures for two tests in validators
Marcin Kuzminski <marcin@python-works.com>
parents: 2515
diff changeset
187 pass
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
188
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
189 def test_ValidSettings(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
190 validator = v.ValidSettings()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
191 self.assertEqual({'pass': 'pass'},
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
192 validator.to_python(value={'user': 'test',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
193 'pass': 'pass'}))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
194
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
195 self.assertEqual({'user2': 'test', 'pass': 'pass'},
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
196 validator.to_python(value={'user2': 'test',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
197 'pass': 'pass'}))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
198
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
199 def test_ValidPath(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
200 validator = v.ValidPath()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
201 self.assertEqual(TESTS_TMP_PATH,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
202 validator.to_python(TESTS_TMP_PATH))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
203 self.assertRaises(formencode.Invalid, validator.to_python,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
204 '/no_such_dir')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
205
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
206 def test_UniqSystemEmail(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
207 validator = v.UniqSystemEmail(old_data={})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
208
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
209 self.assertEqual('mail@python.org',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
210 validator.to_python('MaiL@Python.org'))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
211
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
212 email = TEST_USER_REGULAR2_EMAIL
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
213 self.assertRaises(formencode.Invalid, validator.to_python, email)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
214
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
215 def test_ValidSystemEmail(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
216 validator = v.ValidSystemEmail()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
217 email = TEST_USER_REGULAR2_EMAIL
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
218
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
219 self.assertEqual(email, validator.to_python(email))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
220 self.assertRaises(formencode.Invalid, validator.to_python, 'err')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
221
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
222 def test_LdapLibValidator(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
223 validator = v.LdapLibValidator()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
224 self.assertRaises(v.LdapImportError, validator.to_python, 'err')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
225
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
226 def test_AttrLoginValidator(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
227 validator = v.AttrLoginValidator()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
228 self.assertRaises(formencode.Invalid, validator.to_python, 123)
2721
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
229
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
230 def test_NotReviewedRevisions(self):
2898
74672d4bdbee fixed validator tests
Marcin Kuzminski <marcin@python-works.com>
parents: 2721
diff changeset
231 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
232 validator = v.NotReviewedRevisions(repo_id)
2721
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
233 rev = '0' * 40
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
234 # 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
235 # reviewed
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
236 new_status = ChangesetStatus()
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
237 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
238 new_status.repo = ChangesetStatusModel()._get_repo(HG_REPO)
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
239 new_status.status = ChangesetStatus.STATUS_APPROVED
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
240 new_status.comment = None
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
241 new_status.revision = rev
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
242 Session().add(new_status)
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
243 Session().commit()
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
244 try:
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
245 self.assertRaises(formencode.Invalid, validator.to_python, [rev])
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
246 finally:
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
247 Session().delete(new_status)
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
248 Session().commit()