annotate rhodecode/tests/test_validators.py @ 2501:044c31d67ccc beta

make get_action always return action
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 21 Jun 2012 17:51:01 +0200
parents 7010dc12f10c
children 623e1d68a2e0
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
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 class TestReposGroups(unittest.TestCase):
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 def setUp(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 pass
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 tearDown(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 test_Message_extractor(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 validator = v.ValidUsername()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 self.assertRaises(formencode.Invalid, validator.to_python, 'default')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 class StateObj(object):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 pass
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 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 validator.to_python, 'default', StateObj)
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 def test_ValidUsername(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 validator = v.ValidUsername()
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 self.assertRaises(formencode.Invalid, validator.to_python, 'default')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 self.assertRaises(formencode.Invalid, validator.to_python, 'new_user')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 self.assertRaises(formencode.Invalid, validator.to_python, '.,')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 self.assertRaises(formencode.Invalid, validator.to_python,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 TEST_USER_ADMIN_LOGIN)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 self.assertEqual('test', validator.to_python('test'))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 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
44
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 def test_ValidRepoUser(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 validator = v.ValidRepoUser()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 self.assertRaises(formencode.Invalid, validator.to_python, 'nouser')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 self.assertEqual(TEST_USER_ADMIN_LOGIN,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 validator.to_python(TEST_USER_ADMIN_LOGIN))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 def test_ValidUsersGroup(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 validator = v.ValidUsersGroup()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 self.assertRaises(formencode.Invalid, validator.to_python, 'default')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 self.assertRaises(formencode.Invalid, validator.to_python, '.,')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 gr = UsersGroupModel().create('test')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 gr2 = UsersGroupModel().create('tes2')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 Session.commit()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 self.assertRaises(formencode.Invalid, validator.to_python, 'test')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 assert gr.users_group_id != None
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 validator = v.ValidUsersGroup(edit=True,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 old_data={'users_group_id':
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 gr2.users_group_id})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 self.assertRaises(formencode.Invalid, validator.to_python, 'test')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 self.assertRaises(formencode.Invalid, validator.to_python, 'TesT')
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 UsersGroupModel().delete(gr)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 UsersGroupModel().delete(gr2)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 Session.commit()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 def test_ValidReposGroup(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 validator = v.ValidReposGroup()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 model = ReposGroupModel()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 self.assertRaises(formencode.Invalid, validator.to_python,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 {'group_name': HG_REPO, })
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 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
78 parent=None,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 just_db=True)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 validator.to_python, {'group_name': gr.group_name, })
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 validator = v.ValidReposGroup(edit=True,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 old_data={'group_id': gr.group_id})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86 validator.to_python, {
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 'group_name': gr.group_name + 'n',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 'group_parent_id': gr.group_id
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 })
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 model.delete(gr)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 def test_ValidPassword(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 validator = v.ValidPassword()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 self.assertEqual('lol', validator.to_python('lol'))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 self.assertEqual(None, validator.to_python(None))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 self.assertRaises(formencode.Invalid, validator.to_python, 'ąćżź')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 def test_ValidPasswordsMatch(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 validator = v.ValidPasswordsMatch()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 validator.to_python, {'password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 'password_confirmation': 'pass2'})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103
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, {'new_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.assertEqual({'new_password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 'password_confirmation': 'pass'},
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 validator.to_python({'new_password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 'password_confirmation': 'pass'}))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 self.assertEqual({'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 validator.to_python({'password': 'pass',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 'password_confirmation': 'pass'}))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 def test_ValidAuth(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 validator = v.ValidAuth()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
120 valid_creds = {
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121 'username': TEST_USER_REGULAR2_LOGIN,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
122 'password': TEST_USER_REGULAR2_PASS,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
123 }
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
124 invalid_creds = {
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125 'username': 'err',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
126 'password': 'err',
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 self.assertEqual(valid_creds, validator.to_python(valid_creds))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
129 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
130 validator.to_python, invalid_creds)
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 def test_ValidAuthToken(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
133 validator = v.ValidAuthToken()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
134 # this is untestable without a threadlocal
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 # self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136 # validator.to_python, 'BadToken')
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 validator
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
139 def test_ValidRepoName(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140 validator = v.ValidRepoName()
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 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 validator.to_python, {'repo_name': ''})
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': HG_REPO})
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 gr = ReposGroupModel().create(group_name='group_test',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149 group_description='desc',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150 parent=None,)
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
151 self.assertRaises(formencode.Invalid,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
152 validator.to_python, {'repo_name': gr.group_name})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
153
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
154 #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
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': 'some',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
157 # 'repo_group': gr.group_id})
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 def test_ValidForkName(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
160 # this uses ValidRepoName validator
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
161 assert True
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 @parameterized.expand([
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
164 ('test', 'test'), ('lolz!', 'lolz'), (' aavv', 'aavv'),
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
165 ('ala ma kota', 'ala-ma-kota'), ('@nooo', 'nooo'),
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
166 ('$!haha lolz !', 'haha-lolz'), ('$$$$$', ''), ('{}OK!', 'OK'),
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
167 ('/]re po', 're-po')])
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
168 def test_SlugifyName(self, name, expected):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
169 validator = v.SlugifyName()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
170 self.assertEqual(expected, validator.to_python(name))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
171
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
172 def test_ValidCloneUri(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
173 assert False
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
174
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
175 def test_ValidForkType(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
176 validator = v.ValidForkType(old_data={'repo_type': 'hg'})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
177 self.assertEqual('hg', validator.to_python('hg'))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
178 self.assertRaises(formencode.Invalid, validator.to_python, 'git')
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_ValidPerms(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
181 assert False
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
182
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
183 def test_ValidSettings(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
184 validator = v.ValidSettings()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
185 self.assertEqual({'pass': 'pass'},
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
186 validator.to_python(value={'user': 'test',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
187 'pass': 'pass'}))
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 self.assertEqual({'user2': 'test', 'pass': 'pass'},
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
190 validator.to_python(value={'user2': 'test',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
191 'pass': 'pass'}))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
192
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
193 def test_ValidPath(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
194 validator = v.ValidPath()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
195 self.assertEqual(TESTS_TMP_PATH,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
196 validator.to_python(TESTS_TMP_PATH))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
197 self.assertRaises(formencode.Invalid, validator.to_python,
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
198 '/no_such_dir')
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_UniqSystemEmail(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
201 validator = v.UniqSystemEmail(old_data={})
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
202
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
203 self.assertEqual('mail@python.org',
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
204 validator.to_python('MaiL@Python.org'))
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 email = TEST_USER_REGULAR2_EMAIL
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
207 self.assertRaises(formencode.Invalid, validator.to_python, email)
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 def test_ValidSystemEmail(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
210 validator = v.ValidSystemEmail()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
211 email = TEST_USER_REGULAR2_EMAIL
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 self.assertEqual(email, validator.to_python(email))
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
214 self.assertRaises(formencode.Invalid, validator.to_python, 'err')
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_LdapLibValidator(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
217 validator = v.LdapLibValidator()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
218 self.assertRaises(v.LdapImportError, validator.to_python, 'err')
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 def test_AttrLoginValidator(self):
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
221 validator = v.AttrLoginValidator()
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
222 self.assertRaises(formencode.Invalid, validator.to_python, 123)