comparison test/test_liveserver.py @ 6650:5be4f9104cf7

Make i18n tests work These use installed roundup locales but should use the checked-out locales. Also revert monkey patches in i18n after the test.
author Ralf Schlatterbeck <rsc@runtux.com>
date Mon, 02 May 2022 13:46:58 +0200
parents 53c9b62494e6
children da6c9050a79e
comparison
equal deleted inserted replaced
6649:33616bc80baf 6650:5be4f9104cf7
1 import shutil, errno, pytest, json, gzip, os, re 1 import shutil, errno, pytest, json, gzip, os, re
2 2
3 from roundup import i18n
3 from roundup.anypy.strings import b2s 4 from roundup.anypy.strings import b2s
4 from roundup.cgi.wsgi_handler import RequestDispatcher 5 from roundup.cgi.wsgi_handler import RequestDispatcher
5 from .wsgi_liveserver import LiveServerTestCase 6 from .wsgi_liveserver import LiveServerTestCase
6 from . import db_test_base 7 from . import db_test_base
7 8
38 39
39 @skip_requests 40 @skip_requests
40 class SimpleTest(LiveServerTestCase): 41 class SimpleTest(LiveServerTestCase):
41 # have chicken and egg issue here. Need to encode the base_url 42 # have chicken and egg issue here. Need to encode the base_url
42 # in the config file but we don't know it until after 43 # in the config file but we don't know it until after
43 # the server is started nd has read the config.ini. 44 # the server is started and has read the config.ini.
44 # so only allow one port number 45 # so only allow one port number
45 port_range = (9001, 9001) # default is (8080, 8090) 46 port_range = (9001, 9001) # default is (8080, 8090)
46 47
47 dirname = '_test_instance' 48 dirname = '_test_instance'
48 backend = 'anydbm' 49 backend = 'anydbm'
49 50
50 @classmethod 51 @classmethod
51 def setup_class(cls): 52 def setup_class(cls):
52 '''All test in this class use the same roundup instance. 53 '''All tests in this class use the same roundup instance.
53 This instance persists across all tests. 54 This instance persists across all tests.
54 Create the tracker dir here so that it is ready for the 55 Create the tracker dir here so that it is ready for the
55 create_app() method to be called. 56 create_app() method to be called.
56 ''' 57 '''
57 # tests in this class. 58 # tests in this class.
73 74
74 cls.db.config.save() 75 cls.db.config.save()
75 76
76 cls.db.commit() 77 cls.db.commit()
77 cls.db.close() 78 cls.db.close()
79
80 # Force locale config to find locales in checkout not in
81 # installed directories
82 cls.backup_domain = i18n.DOMAIN
83 cls.backup_locale_dirs = i18n.LOCALE_DIRS
84 i18n.LOCALE_DIRS = ['locale']
85 i18n.DOMAIN = ''
78 86
79 @classmethod 87 @classmethod
80 def teardown_class(cls): 88 def teardown_class(cls):
81 '''Close the database and delete the tracker directory 89 '''Close the database and delete the tracker directory
82 now that the app should be exiting. 90 now that the app should be exiting.
85 cls.db.close() 93 cls.db.close()
86 try: 94 try:
87 shutil.rmtree(cls.dirname) 95 shutil.rmtree(cls.dirname)
88 except OSError as error: 96 except OSError as error:
89 if error.errno not in (errno.ENOENT, errno.ESRCH): raise 97 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
98 i18n.LOCALE_DIRS = cls.backup_locale_dirs
99 i18n.DOMAIN = cls.backup_domain
90 100
91 def create_app(self): 101 def create_app(self):
92 '''The wsgi app to start''' 102 '''The wsgi app to start'''
93 if _py3: 103 if _py3:
94 return validator(RequestDispatcher(self.dirname)) 104 return validator(RequestDispatcher(self.dirname))

Roundup Issue Tracker: http://roundup-tracker.org/