##// END OF EJS Templates
tests: use test_context for tests needing internationalization (bis)...
Thomas De Schampheleire -
r6521:9f8a1212 default
parent child Browse files
Show More
@@ -5,6 +5,9 b' from kallithea.model.user import UserMod'
5 from kallithea.model.meta import Session
5 from kallithea.model.meta import Session
6 from kallithea.tests.base import *
6 from kallithea.tests.base import *
7
7
8 from kallithea.tests.test_context import test_context
9
10
8 class TestAdminPermissionsController(TestController):
11 class TestAdminPermissionsController(TestController):
9
12
10 def test_index(self):
13 def test_index(self):
@@ -42,9 +45,10 b' class TestAdminPermissionsController(Tes'
42
45
43 ## first add
46 ## first add
44 new_ip = '127.0.0.0/24'
47 new_ip = '127.0.0.0/24'
45 user_model = UserModel()
48 with test_context(self.app):
46 ip_obj = user_model.add_extra_ip(default_user_id, new_ip)
49 user_model = UserModel()
47 Session().commit()
50 ip_obj = user_model.add_extra_ip(default_user_id, new_ip)
51 Session().commit()
48
52
49 ## double check that add worked
53 ## double check that add worked
50 # IP permissions are cached, need to invalidate this cache explicitly
54 # IP permissions are cached, need to invalidate this cache explicitly
@@ -111,7 +111,8 b' class TestAdminUsersController(TestContr'
111 'email': email,
111 'email': email,
112 '_authentication_token': self.authentication_token()})
112 '_authentication_token': self.authentication_token()})
113
113
114 msg = validators.ValidUsername(False, {})._messages['system_invalid_username']
114 with test_context(self.app):
115 msg = validators.ValidUsername(False, {})._messages['system_invalid_username']
115 msg = h.html_escape(msg % {'username': 'new_user'})
116 msg = h.html_escape(msg % {'username': 'new_user'})
116 response.mustcontain("""<span class="error-message">%s</span>""" % msg)
117 response.mustcontain("""<span class="error-message">%s</span>""" % msg)
117 response.mustcontain("""<span class="error-message">Please enter a value</span>""")
118 response.mustcontain("""<span class="error-message">Please enter a value</span>""")
@@ -431,8 +432,9 b' class TestAdminUsersController(TestContr'
431 user_id = user.user_id
432 user_id = user.user_id
432 ip = '127.0.0.1/32'
433 ip = '127.0.0.1/32'
433 ip_range = '127.0.0.1 - 127.0.0.1'
434 ip_range = '127.0.0.1 - 127.0.0.1'
434 new_ip = UserModel().add_extra_ip(user_id, ip)
435 with test_context(self.app):
435 Session().commit()
436 new_ip = UserModel().add_extra_ip(user_id, ip)
437 Session().commit()
436 new_ip_id = new_ip.ip_id
438 new_ip_id = new_ip.ip_id
437
439
438 response = self.app.get(url('edit_user_ips', id=user_id))
440 response = self.app.get(url('edit_user_ips', id=user_id))
@@ -517,20 +519,19 b' class TestAdminUsersController(TestContr'
517 class TestAdminUsersController_unittest(TestController):
519 class TestAdminUsersController_unittest(TestController):
518 """ Unit tests for the users controller """
520 """ Unit tests for the users controller """
519
521
520 def test_get_user_or_raise_if_default(self, monkeypatch):
522 def test_get_user_or_raise_if_default(self, monkeypatch, test_context_fixture):
521 with test_context(self.app):
523 # flash complains about an non-existing session
522 # flash complains about an non-existing session
524 def flash_mock(*args, **kwargs):
523 def flash_mock(*args, **kwargs):
525 pass
524 pass
526 monkeypatch.setattr(h, 'flash', flash_mock)
525 monkeypatch.setattr(h, 'flash', flash_mock)
526
527
527 u = UsersController()
528 u = UsersController()
528 # a regular user should work correctly
529 # a regular user should work correctly
529 user = User.get_by_username(TEST_USER_REGULAR_LOGIN)
530 user = User.get_by_username(TEST_USER_REGULAR_LOGIN)
530 assert u._get_user_or_raise_if_default(user.user_id) == user
531 assert u._get_user_or_raise_if_default(user.user_id) == user
531 # the default user should raise
532 # the default user should raise
532 with pytest.raises(HTTPNotFound):
533 with pytest.raises(HTTPNotFound):
533 u._get_user_or_raise_if_default(User.get_default_user().user_id)
534 u._get_user_or_raise_if_default(User.get_default_user().user_id)
534
535
535
536
536 class TestAdminUsersControllerForDefaultUser(TestController):
537 class TestAdminUsersControllerForDefaultUser(TestController):
@@ -16,6 +16,8 b' from kallithea.model.db import User, Not'
16 from kallithea.model.meta import Session
16 from kallithea.model.meta import Session
17 from kallithea.model.user import UserModel
17 from kallithea.model.user import UserModel
18
18
19 from kallithea.tests.test_context import test_context
20
19 fixture = Fixture()
21 fixture = Fixture()
20
22
21
23
@@ -219,7 +221,8 b' class TestLoginController(TestController'
219 'firstname': 'test',
221 'firstname': 'test',
220 'lastname': 'test'})
222 'lastname': 'test'})
221
223
222 msg = validators.ValidUsername()._messages['username_exists']
224 with test_context(self.app):
225 msg = validators.ValidUsername()._messages['username_exists']
223 msg = h.html_escape(msg % {'username': uname})
226 msg = h.html_escape(msg % {'username': uname})
224 response.mustcontain(msg)
227 response.mustcontain(msg)
225
228
@@ -232,7 +235,8 b' class TestLoginController(TestController'
232 'firstname': 'test',
235 'firstname': 'test',
233 'lastname': 'test'})
236 'lastname': 'test'})
234
237
235 msg = validators.UniqSystemEmail()()._messages['email_taken']
238 with test_context(self.app):
239 msg = validators.UniqSystemEmail()()._messages['email_taken']
236 response.mustcontain(msg)
240 response.mustcontain(msg)
237
241
238 def test_register_err_same_email_case_sensitive(self):
242 def test_register_err_same_email_case_sensitive(self):
@@ -243,7 +247,8 b' class TestLoginController(TestController'
243 'email': TEST_USER_ADMIN_EMAIL.title(),
247 'email': TEST_USER_ADMIN_EMAIL.title(),
244 'firstname': 'test',
248 'firstname': 'test',
245 'lastname': 'test'})
249 'lastname': 'test'})
246 msg = validators.UniqSystemEmail()()._messages['email_taken']
250 with test_context(self.app):
251 msg = validators.UniqSystemEmail()()._messages['email_taken']
247 response.mustcontain(msg)
252 response.mustcontain(msg)
248
253
249 def test_register_err_wrong_data(self):
254 def test_register_err_wrong_data(self):
@@ -284,7 +289,8 b' class TestLoginController(TestController'
284 'lastname': 'test'})
289 'lastname': 'test'})
285
290
286 response.mustcontain('An email address must contain a single @')
291 response.mustcontain('An email address must contain a single @')
287 msg = validators.ValidUsername()._messages['username_exists']
292 with test_context(self.app):
293 msg = validators.ValidUsername()._messages['username_exists']
288 msg = h.html_escape(msg % {'username': usr})
294 msg = h.html_escape(msg % {'username': usr})
289 response.mustcontain(msg)
295 response.mustcontain(msg)
290
296
@@ -297,7 +303,8 b' class TestLoginController(TestController'
297 'firstname': 'test',
303 'firstname': 'test',
298 'lastname': 'test'})
304 'lastname': 'test'})
299
305
300 msg = validators.ValidPassword()._messages['invalid_password']
306 with test_context(self.app):
307 msg = validators.ValidPassword()._messages['invalid_password']
301 response.mustcontain(msg)
308 response.mustcontain(msg)
302
309
303 def test_register_password_mismatch(self):
310 def test_register_password_mismatch(self):
@@ -308,7 +315,8 b' class TestLoginController(TestController'
308 'email': 'goodmailm@test.plxa',
315 'email': 'goodmailm@test.plxa',
309 'firstname': 'test',
316 'firstname': 'test',
310 'lastname': 'test'})
317 'lastname': 'test'})
311 msg = validators.ValidPasswordsMatch('password', 'password_confirmation')._messages['password_mismatch']
318 with test_context(self.app):
319 msg = validators.ValidPasswordsMatch('password', 'password_confirmation')._messages['password_mismatch']
312 response.mustcontain(msg)
320 response.mustcontain(msg)
313
321
314 def test_register_ok(self):
322 def test_register_ok(self):
@@ -7,6 +7,8 b' from kallithea.lib import helpers as h'
7 from kallithea.model.user import UserModel
7 from kallithea.model.user import UserModel
8 from kallithea.model.meta import Session
8 from kallithea.model.meta import Session
9
9
10 from kallithea.tests.test_context import test_context
11
10 fixture = Fixture()
12 fixture = Fixture()
11
13
12
14
@@ -180,8 +182,9 b' class TestMyAccountController(TestContro'
180
182
181 response.mustcontain('An email address must contain a single @')
183 response.mustcontain('An email address must contain a single @')
182 from kallithea.model import validators
184 from kallithea.model import validators
183 msg = validators.ValidUsername(edit=False, old_data={}) \
185 with test_context(self.app):
184 ._messages['username_exists']
186 msg = validators.ValidUsername(edit=False, old_data={}) \
187 ._messages['username_exists']
185 msg = h.html_escape(msg % {'username': TEST_USER_ADMIN_LOGIN})
188 msg = h.html_escape(msg % {'username': TEST_USER_ADMIN_LOGIN})
186 response.mustcontain(msg)
189 response.mustcontain(msg)
187
190
@@ -15,6 +15,7 b' from kallithea.tests.fixture import Fixt'
15 fixture = Fixture()
15 fixture = Fixture()
16
16
17
17
18 @pytest.mark.usefixtures("test_context_fixture") # apply fixture for all test methods
18 class TestRepoGroups(TestController):
19 class TestRepoGroups(TestController):
19
20
20 def teardown_method(self, method):
21 def teardown_method(self, method):
General Comments 0
You need to be logged in to leave comments. Login now