annotate rhodecode/tests/test_validators.py @ 3238:26bf9c8baad2 beta

added HSTS headers when using SSL for RhodeCode
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 27 Jan 2013 22:37:55 +0100
parents b4daef4cc26d
children fa6ba6727475
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
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 from rhodecode.model.users_group import UsersGroupModel
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
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
15 from rhodecode.model.comment import ChangesetCommentsModel
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
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 class TestReposGroups(unittest.TestCase):
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):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 pass
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
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 def test_ValidUsersGroup(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 validator = v.ValidUsersGroup()
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
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 gr = UsersGroupModel().create('test')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 gr2 = UsersGroupModel().create('tes2')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 Session.commit()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 self.assertRaises(formencode.Invalid, validator.to_python, 'test')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 assert gr.users_group_id != None
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 validator = v.ValidUsersGroup(edit=True,
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')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 UsersGroupModel().delete(gr)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 UsersGroupModel().delete(gr2)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 Session.commit()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 def test_ValidReposGroup(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 validator = v.ValidReposGroup()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 model = ReposGroupModel()
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
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 validator = v.ValidReposGroup(edit=True,
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
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
152 gr = ReposGroupModel().create(group_name='group_test',
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):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
224 validator = v.LdapLibValidator()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
225 self.assertRaises(v.LdapImportError, validator.to_python, 'err')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
226
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
227 def test_AttrLoginValidator(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
228 validator = v.AttrLoginValidator()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
229 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
230
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
231 def test_NotReviewedRevisions(self):
2898
74672d4bdbee fixed validator tests
Marcin Kuzminski <marcin@python-works.com>
parents: 2721
diff changeset
232 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
233 validator = v.NotReviewedRevisions(repo_id)
2721
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
234 rev = '0' * 40
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
235 # 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
236 # reviewed
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
237 new_status = ChangesetStatus()
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
238 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
239 new_status.repo = ChangesetStatusModel()._get_repo(HG_REPO)
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
240 new_status.status = ChangesetStatus.STATUS_APPROVED
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
241 new_status.comment = None
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
242 new_status.revision = rev
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
243 Session().add(new_status)
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
244 Session().commit()
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
245 try:
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
246 self.assertRaises(formencode.Invalid, validator.to_python, [rev])
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
247 finally:
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
248 Session().delete(new_status)
36915dd4544d Add test for NotReviewed validator
Marcin Kuzminski <marcin@python-works.com>
parents: 2557
diff changeset
249 Session().commit()