Merge lp:~raoul-snyman/openlp/fix-tests into lp:openlp
- fix-tests
- Merge into trunk
Proposed by
Raoul Snyman
Status: | Merged |
---|---|
Merged at revision: | 2589 |
Proposed branch: | lp:~raoul-snyman/openlp/fix-tests |
Merge into: | lp:openlp |
Diff against target: |
642 lines (+129/-176) 11 files modified
openlp/core/lib/db.py (+16/-14) openlp/core/lib/projector/db.py (+18/-18) tests/functional/openlp_core_lib/__init__.py (+0/-23) tests/functional/openlp_core_lib/test_projectordb.py (+38/-36) tests/functional/openlp_core_ui/test_maindisplay.py (+5/-5) tests/interfaces/openlp_core_ui/__init__.py (+0/-32) tests/interfaces/openlp_core_ui/test_projectoreditform.py (+9/-5) tests/interfaces/openlp_core_ui/test_projectormanager.py (+8/-10) tests/interfaces/openlp_core_ui/test_projectorsourceform.py (+11/-9) tests/interfaces/openlp_plugins/bibles/test_lib_http.py (+1/-1) tests/resources/projector/data.py (+23/-23) |
To merge this branch: | bzr merge lp:~raoul-snyman/openlp/fix-tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Bentley | Approve | ||
Tomas Groth | Approve | ||
Review via email: mp+281936@code.launchpad.net |
Commit message
Description of the change
Fix tests. Sadly Windows tests are still broken.
Add this to your merge proposal:
-------
lp:~raoul-snyman/openlp/fix-tests (revision 2596)
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[FAILURE] https:/
To post a comment you must log in.
Revision history for this message
Tomas Groth (tomasgroth) : | # |
review:
Approve
Revision history for this message
Tim Bentley (trb143) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'openlp/core/lib/db.py' | |||
2 | --- openlp/core/lib/db.py 2015-12-31 22:46:06 +0000 | |||
3 | +++ openlp/core/lib/db.py 2016-01-07 22:31:35 +0000 | |||
4 | @@ -55,7 +55,7 @@ | |||
5 | 55 | metadata = MetaData(bind=engine) | 55 | metadata = MetaData(bind=engine) |
6 | 56 | else: | 56 | else: |
7 | 57 | base.metadata.bind = engine | 57 | base.metadata.bind = engine |
9 | 58 | metadata = None | 58 | metadata = base.metadata |
10 | 59 | session = scoped_session(sessionmaker(autoflush=auto_flush, autocommit=auto_commit, bind=engine)) | 59 | session = scoped_session(sessionmaker(autoflush=auto_flush, autocommit=auto_commit, bind=engine)) |
11 | 60 | return session, metadata | 60 | return session, metadata |
12 | 61 | 61 | ||
13 | @@ -227,13 +227,12 @@ | |||
14 | 227 | """ | 227 | """ |
15 | 228 | self.is_dirty = False | 228 | self.is_dirty = False |
16 | 229 | self.session = None | 229 | self.session = None |
23 | 230 | # See if we're using declarative_base with a pre-existing session. | 230 | self.db_url = None |
24 | 231 | log.debug('Manager: Testing for pre-existing session') | 231 | if db_file_name: |
25 | 232 | if session is not None: | 232 | log.debug('Manager: Creating new DB url') |
20 | 233 | log.debug('Manager: Using existing session') | ||
21 | 234 | else: | ||
22 | 235 | log.debug('Manager: Creating new session') | ||
26 | 236 | self.db_url = init_url(plugin_name, db_file_name) | 233 | self.db_url = init_url(plugin_name, db_file_name) |
27 | 234 | else: | ||
28 | 235 | self.db_url = init_url(plugin_name) | ||
29 | 237 | if upgrade_mod: | 236 | if upgrade_mod: |
30 | 238 | try: | 237 | try: |
31 | 239 | db_ver, up_ver = upgrade_db(self.db_url, upgrade_mod) | 238 | db_ver, up_ver = upgrade_db(self.db_url, upgrade_mod) |
32 | @@ -248,10 +247,13 @@ | |||
33 | 248 | 'not be loaded.\n\nDatabase: %s') % (db_ver, up_ver, self.db_url) | 247 | 'not be loaded.\n\nDatabase: %s') % (db_ver, up_ver, self.db_url) |
34 | 249 | ) | 248 | ) |
35 | 250 | return | 249 | return |
40 | 251 | try: | 250 | if not session: |
41 | 252 | self.session = init_schema(self.db_url) | 251 | try: |
42 | 253 | except (SQLAlchemyError, DBAPIError): | 252 | self.session = init_schema(self.db_url) |
43 | 254 | handle_db_error(plugin_name, db_file_name) | 253 | except (SQLAlchemyError, DBAPIError): |
44 | 254 | handle_db_error(plugin_name, db_file_name) | ||
45 | 255 | else: | ||
46 | 256 | self.session = session | ||
47 | 255 | 257 | ||
48 | 256 | def save_object(self, object_instance, commit=True): | 258 | def save_object(self, object_instance, commit=True): |
49 | 257 | """ | 259 | """ |
50 | @@ -344,13 +346,13 @@ | |||
51 | 344 | for try_count in range(3): | 346 | for try_count in range(3): |
52 | 345 | try: | 347 | try: |
53 | 346 | return self.session.query(object_class).filter(filter_clause).first() | 348 | return self.session.query(object_class).filter(filter_clause).first() |
55 | 347 | except OperationalError: | 349 | except OperationalError as oe: |
56 | 348 | # This exception clause is for users running MySQL which likes to terminate connections on its own | 350 | # This exception clause is for users running MySQL which likes to terminate connections on its own |
57 | 349 | # without telling anyone. See bug #927473. However, other dbms can raise it, usually in a | 351 | # without telling anyone. See bug #927473. However, other dbms can raise it, usually in a |
58 | 350 | # non-recoverable way. So we only retry 3 times. | 352 | # non-recoverable way. So we only retry 3 times. |
59 | 353 | if try_count >= 2 or 'MySQL has gone away' in str(oe): | ||
60 | 354 | raise | ||
61 | 351 | log.exception('Probably a MySQL issue, "MySQL has gone away"') | 355 | log.exception('Probably a MySQL issue, "MySQL has gone away"') |
62 | 352 | if try_count >= 2: | ||
63 | 353 | raise | ||
64 | 354 | 356 | ||
65 | 355 | def get_all_objects(self, object_class, filter_clause=None, order_by_ref=None): | 357 | def get_all_objects(self, object_class, filter_clause=None, order_by_ref=None): |
66 | 356 | """ | 358 | """ |
67 | 357 | 359 | ||
68 | === modified file 'openlp/core/lib/projector/db.py' | |||
69 | --- openlp/core/lib/projector/db.py 2015-12-31 22:46:06 +0000 | |||
70 | +++ openlp/core/lib/projector/db.py 2016-01-07 22:31:35 +0000 | |||
71 | @@ -20,18 +20,18 @@ | |||
72 | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # |
73 | 21 | ############################################################################### | 21 | ############################################################################### |
74 | 22 | """ | 22 | """ |
87 | 23 | :mod:`openlp.core.lib.projector.db` module | 23 | :mod:`openlp.core.lib.projector.db` module |
88 | 24 | 24 | ||
89 | 25 | Provides the database functions for the Projector module. | 25 | Provides the database functions for the Projector module. |
90 | 26 | 26 | ||
91 | 27 | The Manufacturer, Model, Source tables keep track of the video source | 27 | The Manufacturer, Model, Source tables keep track of the video source |
92 | 28 | strings used for display of input sources. The Source table maps | 28 | strings used for display of input sources. The Source table maps |
93 | 29 | manufacturer-defined or user-defined strings from PJLink default strings | 29 | manufacturer-defined or user-defined strings from PJLink default strings |
94 | 30 | to end-user readable strings; ex: PJLink code 11 would map "RGB 1" | 30 | to end-user readable strings; ex: PJLink code 11 would map "RGB 1" |
95 | 31 | default string to "RGB PC (analog)" string. | 31 | default string to "RGB PC (analog)" string. |
96 | 32 | (Future feature). | 32 | (Future feature). |
97 | 33 | 33 | ||
98 | 34 | The Projector table keeps track of entries for controlled projectors. | 34 | The Projector table keeps track of entries for controlled projectors. |
99 | 35 | """ | 35 | """ |
100 | 36 | 36 | ||
101 | 37 | import logging | 37 | import logging |
102 | @@ -218,19 +218,19 @@ | |||
103 | 218 | """ | 218 | """ |
104 | 219 | def __init__(self, *args, **kwargs): | 219 | def __init__(self, *args, **kwargs): |
105 | 220 | log.debug('ProjectorDB().__init__(args="%s", kwargs="%s")' % (args, kwargs)) | 220 | log.debug('ProjectorDB().__init__(args="%s", kwargs="%s")' % (args, kwargs)) |
108 | 221 | super().__init__(plugin_name='projector', | 221 | super().__init__(plugin_name='projector', init_schema=self.init_schema) |
107 | 222 | init_schema=self.init_schema) | ||
109 | 223 | log.debug('ProjectorDB() Initialized using db url %s' % self.db_url) | 222 | log.debug('ProjectorDB() Initialized using db url %s' % self.db_url) |
110 | 223 | log.debug('Session: %s', self.session) | ||
111 | 224 | 224 | ||
113 | 225 | def init_schema(*args, **kwargs): | 225 | def init_schema(self, *args, **kwargs): |
114 | 226 | """ | 226 | """ |
115 | 227 | Setup the projector database and initialize the schema. | 227 | Setup the projector database and initialize the schema. |
116 | 228 | 228 | ||
117 | 229 | Declarative uses table classes to define schema. | 229 | Declarative uses table classes to define schema. |
118 | 230 | """ | 230 | """ |
122 | 231 | url = init_url('projector') | 231 | self.db_url = init_url('projector') |
123 | 232 | session, metadata = init_db(url, base=Base) | 232 | session, metadata = init_db(self.db_url, base=Base) |
124 | 233 | Base.metadata.create_all(checkfirst=True) | 233 | metadata.create_all(checkfirst=True) |
125 | 234 | return session | 234 | return session |
126 | 235 | 235 | ||
127 | 236 | def get_projector_by_id(self, dbid): | 236 | def get_projector_by_id(self, dbid): |
128 | 237 | 237 | ||
129 | === modified file 'tests/functional/openlp_core_lib/__init__.py' | |||
130 | --- tests/functional/openlp_core_lib/__init__.py 2015-12-31 22:46:06 +0000 | |||
131 | +++ tests/functional/openlp_core_lib/__init__.py 2016-01-07 22:31:35 +0000 | |||
132 | @@ -22,26 +22,3 @@ | |||
133 | 22 | """ | 22 | """ |
134 | 23 | Module-level functions for the functional test suite | 23 | Module-level functions for the functional test suite |
135 | 24 | """ | 24 | """ |
136 | 25 | |||
137 | 26 | import os | ||
138 | 27 | from tests.functional import patch | ||
139 | 28 | |||
140 | 29 | from openlp.core.common import is_win | ||
141 | 30 | |||
142 | 31 | from .test_projectordb import tmpfile | ||
143 | 32 | |||
144 | 33 | |||
145 | 34 | def setUp(): | ||
146 | 35 | if not is_win(): | ||
147 | 36 | # Wine creates a sharing violation during tests. Ignore. | ||
148 | 37 | try: | ||
149 | 38 | os.remove(tmpfile) | ||
150 | 39 | except: | ||
151 | 40 | pass | ||
152 | 41 | |||
153 | 42 | |||
154 | 43 | def tearDown(): | ||
155 | 44 | """ | ||
156 | 45 | Ensure test suite has been cleaned up after tests | ||
157 | 46 | """ | ||
158 | 47 | patch.stopall() | ||
159 | 48 | 25 | ||
160 | === modified file 'tests/functional/openlp_core_lib/test_projectordb.py' | |||
161 | --- tests/functional/openlp_core_lib/test_projectordb.py 2015-12-31 22:46:06 +0000 | |||
162 | +++ tests/functional/openlp_core_lib/test_projectordb.py 2016-01-07 22:31:35 +0000 | |||
163 | @@ -25,15 +25,13 @@ | |||
164 | 25 | 25 | ||
165 | 26 | PREREQUISITE: add_record() and get_all() functions validated. | 26 | PREREQUISITE: add_record() and get_all() functions validated. |
166 | 27 | """ | 27 | """ |
168 | 28 | 28 | import os | |
169 | 29 | from unittest import TestCase | 29 | from unittest import TestCase |
170 | 30 | |||
171 | 31 | from openlp.core.lib.projector.db import Projector, ProjectorDB, ProjectorSource | ||
172 | 32 | |||
173 | 30 | from tests.functional import MagicMock, patch | 33 | from tests.functional import MagicMock, patch |
180 | 31 | 34 | from tests.resources.projector.data import TEST_DB, TEST1_DATA, TEST2_DATA, TEST3_DATA | |
175 | 32 | from openlp.core.lib.projector.db import Projector, ProjectorDB, ProjectorSource | ||
176 | 33 | |||
177 | 34 | from tests.resources.projector.data import TEST1_DATA, TEST2_DATA, TEST3_DATA | ||
178 | 35 | |||
179 | 36 | tmpfile = '/tmp/openlp-test-projectordb.sql' | ||
181 | 37 | 35 | ||
182 | 38 | 36 | ||
183 | 39 | def compare_data(one, two): | 37 | def compare_data(one, two): |
184 | @@ -60,15 +58,15 @@ | |||
185 | 60 | one.text == two.text | 58 | one.text == two.text |
186 | 61 | 59 | ||
187 | 62 | 60 | ||
189 | 63 | def add_records(self, test): | 61 | def add_records(projector_db, test): |
190 | 64 | """ | 62 | """ |
191 | 65 | Add record if not in database | 63 | Add record if not in database |
192 | 66 | """ | 64 | """ |
194 | 67 | record_list = self.projector.get_projector_all() | 65 | record_list = projector_db.get_projector_all() |
195 | 68 | if len(record_list) < 1: | 66 | if len(record_list) < 1: |
196 | 69 | added = False | 67 | added = False |
197 | 70 | for record in test: | 68 | for record in test: |
199 | 71 | added = self.projector.add_projector(record) or added | 69 | added = projector_db.add_projector(record) or added |
200 | 72 | return added | 70 | return added |
201 | 73 | 71 | ||
202 | 74 | for new_record in test: | 72 | for new_record in test: |
203 | @@ -76,7 +74,7 @@ | |||
204 | 76 | for record in record_list: | 74 | for record in record_list: |
205 | 77 | if compare_data(record, new_record): | 75 | if compare_data(record, new_record): |
206 | 78 | break | 76 | break |
208 | 79 | added = self.projector.add_projector(new_record) | 77 | added = projector_db.add_projector(new_record) |
209 | 80 | return added | 78 | return added |
210 | 81 | 79 | ||
211 | 82 | 80 | ||
212 | @@ -88,15 +86,17 @@ | |||
213 | 88 | """ | 86 | """ |
214 | 89 | Set up anything necessary for all tests | 87 | Set up anything necessary for all tests |
215 | 90 | """ | 88 | """ |
220 | 91 | if not hasattr(self, 'projector'): | 89 | with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url: |
221 | 92 | with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url: | 90 | if os.path.exists(TEST_DB): |
222 | 93 | mocked_init_url.return_value = 'sqlite:///%s' % tmpfile | 91 | os.unlink(TEST_DB) |
223 | 94 | self.projector = ProjectorDB() | 92 | mocked_init_url.return_value = 'sqlite:///%s' % TEST_DB |
224 | 93 | self.projector = ProjectorDB() | ||
225 | 95 | 94 | ||
226 | 96 | def tearDown(self): | 95 | def tearDown(self): |
227 | 97 | """ | 96 | """ |
228 | 98 | Clean up | 97 | Clean up |
229 | 99 | """ | 98 | """ |
230 | 99 | self.projector.session.close() | ||
231 | 100 | self.projector = None | 100 | self.projector = None |
232 | 101 | 101 | ||
233 | 102 | def find_record_by_ip_test(self): | 102 | def find_record_by_ip_test(self): |
234 | @@ -104,13 +104,13 @@ | |||
235 | 104 | Test find record by IP | 104 | Test find record by IP |
236 | 105 | """ | 105 | """ |
237 | 106 | # GIVEN: Record entries in database | 106 | # GIVEN: Record entries in database |
239 | 107 | add_records(self, [TEST1_DATA, TEST2_DATA]) | 107 | add_records(self.projector, [Projector(**TEST1_DATA), Projector(**TEST2_DATA)]) |
240 | 108 | 108 | ||
241 | 109 | # WHEN: Search for record using IP | 109 | # WHEN: Search for record using IP |
243 | 110 | record = self.projector.get_projector_by_ip(TEST2_DATA.ip) | 110 | record = self.projector.get_projector_by_ip(TEST2_DATA['ip']) |
244 | 111 | 111 | ||
245 | 112 | # THEN: Verify proper record returned | 112 | # THEN: Verify proper record returned |
247 | 113 | self.assertTrue(compare_data(TEST2_DATA, record), | 113 | self.assertTrue(compare_data(Projector(**TEST2_DATA), record), |
248 | 114 | 'Record found should have been test_2 data') | 114 | 'Record found should have been test_2 data') |
249 | 115 | 115 | ||
250 | 116 | def find_record_by_name_test(self): | 116 | def find_record_by_name_test(self): |
251 | @@ -118,13 +118,13 @@ | |||
252 | 118 | Test find record by name | 118 | Test find record by name |
253 | 119 | """ | 119 | """ |
254 | 120 | # GIVEN: Record entries in database | 120 | # GIVEN: Record entries in database |
256 | 121 | add_records(self, [TEST1_DATA, TEST2_DATA]) | 121 | add_records(self.projector, [Projector(**TEST1_DATA), Projector(**TEST2_DATA)]) |
257 | 122 | 122 | ||
258 | 123 | # WHEN: Search for record using name | 123 | # WHEN: Search for record using name |
260 | 124 | record = self.projector.get_projector_by_name(TEST2_DATA.name) | 124 | record = self.projector.get_projector_by_name(TEST2_DATA['name']) |
261 | 125 | 125 | ||
262 | 126 | # THEN: Verify proper record returned | 126 | # THEN: Verify proper record returned |
264 | 127 | self.assertTrue(compare_data(TEST2_DATA, record), | 127 | self.assertTrue(compare_data(Projector(**TEST2_DATA), record), |
265 | 128 | 'Record found should have been test_2 data') | 128 | 'Record found should have been test_2 data') |
266 | 129 | 129 | ||
267 | 130 | def record_delete_test(self): | 130 | def record_delete_test(self): |
268 | @@ -132,14 +132,14 @@ | |||
269 | 132 | Test record can be deleted | 132 | Test record can be deleted |
270 | 133 | """ | 133 | """ |
271 | 134 | # GIVEN: Record in database | 134 | # GIVEN: Record in database |
274 | 135 | add_records(self, [TEST3_DATA, ]) | 135 | add_records(self.projector, [Projector(**TEST3_DATA), ]) |
275 | 136 | record = self.projector.get_projector_by_ip(TEST3_DATA.ip) | 136 | record = self.projector.get_projector_by_ip(TEST3_DATA['ip']) |
276 | 137 | 137 | ||
277 | 138 | # WHEN: Record deleted | 138 | # WHEN: Record deleted |
278 | 139 | self.projector.delete_projector(record) | 139 | self.projector.delete_projector(record) |
279 | 140 | 140 | ||
280 | 141 | # THEN: Verify record not retrievable | 141 | # THEN: Verify record not retrievable |
282 | 142 | found = self.projector.get_projector_by_ip(TEST3_DATA.ip) | 142 | found = self.projector.get_projector_by_ip(TEST3_DATA['ip']) |
283 | 143 | self.assertFalse(found, 'test_3 record should have been deleted') | 143 | self.assertFalse(found, 'test_3 record should have been deleted') |
284 | 144 | 144 | ||
285 | 145 | def record_edit_test(self): | 145 | def record_edit_test(self): |
286 | @@ -147,34 +147,35 @@ | |||
287 | 147 | Test edited record returns the same record ID with different data | 147 | Test edited record returns the same record ID with different data |
288 | 148 | """ | 148 | """ |
289 | 149 | # GIVEN: Record entries in database | 149 | # GIVEN: Record entries in database |
291 | 150 | add_records(self, [TEST1_DATA, TEST2_DATA]) | 150 | add_records(self.projector, [Projector(**TEST1_DATA), Projector(**TEST2_DATA)]) |
292 | 151 | 151 | ||
293 | 152 | # WHEN: We retrieve a specific record | 152 | # WHEN: We retrieve a specific record |
295 | 153 | record = self.projector.get_projector_by_ip(TEST1_DATA.ip) | 153 | record = self.projector.get_projector_by_ip(TEST1_DATA['ip']) |
296 | 154 | record_id = record.id | 154 | record_id = record.id |
297 | 155 | 155 | ||
298 | 156 | # WHEN: Data is changed | 156 | # WHEN: Data is changed |
305 | 157 | record.ip = TEST3_DATA.ip | 157 | record.ip = TEST3_DATA['ip'] |
306 | 158 | record.port = TEST3_DATA.port | 158 | record.port = TEST3_DATA['port'] |
307 | 159 | record.pin = TEST3_DATA.pin | 159 | record.pin = TEST3_DATA['pin'] |
308 | 160 | record.name = TEST3_DATA.name | 160 | record.name = TEST3_DATA['name'] |
309 | 161 | record.location = TEST3_DATA.location | 161 | record.location = TEST3_DATA['location'] |
310 | 162 | record.notes = TEST3_DATA.notes | 162 | record.notes = TEST3_DATA['notes'] |
311 | 163 | updated = self.projector.update_projector(record) | 163 | updated = self.projector.update_projector(record) |
312 | 164 | self.assertTrue(updated, 'Save updated record should have returned True') | 164 | self.assertTrue(updated, 'Save updated record should have returned True') |
314 | 165 | record = self.projector.get_projector_by_ip(TEST3_DATA.ip) | 165 | record = self.projector.get_projector_by_ip(TEST3_DATA['ip']) |
315 | 166 | 166 | ||
316 | 167 | # THEN: Record ID should remain the same, but data should be changed | 167 | # THEN: Record ID should remain the same, but data should be changed |
317 | 168 | self.assertEqual(record_id, record.id, 'Edited record should have the same ID') | 168 | self.assertEqual(record_id, record.id, 'Edited record should have the same ID') |
319 | 169 | self.assertTrue(compare_data(TEST3_DATA, record), 'Edited record should have new data') | 169 | self.assertTrue(compare_data(Projector(**TEST3_DATA), record), 'Edited record should have new data') |
320 | 170 | 170 | ||
321 | 171 | def source_add_test(self): | 171 | def source_add_test(self): |
322 | 172 | """ | 172 | """ |
323 | 173 | Test source entry for projector item | 173 | Test source entry for projector item |
324 | 174 | """ | 174 | """ |
325 | 175 | # GIVEN: Record entries in database | 175 | # GIVEN: Record entries in database |
328 | 176 | self.projector.add_projector(TEST1_DATA) | 176 | projector1 = Projector(**TEST1_DATA) |
329 | 177 | item = self.projector.get_projector_by_id(TEST1_DATA.id) | 177 | self.projector.add_projector(projector1) |
330 | 178 | item = self.projector.get_projector_by_id(projector1.id) | ||
331 | 178 | item_id = item.id | 179 | item_id = item.id |
332 | 179 | 180 | ||
333 | 180 | # WHEN: A source entry is saved for item | 181 | # WHEN: A source entry is saved for item |
334 | @@ -184,3 +185,4 @@ | |||
335 | 184 | # THEN: Projector should have the same source entry | 185 | # THEN: Projector should have the same source entry |
336 | 185 | item = self.projector.get_projector_by_id(item_id) | 186 | item = self.projector.get_projector_by_id(item_id) |
337 | 186 | self.assertTrue(compare_source(item.source_list[0], source)) | 187 | self.assertTrue(compare_source(item.source_list[0], source)) |
338 | 188 | |||
339 | 187 | 189 | ||
340 | === modified file 'tests/functional/openlp_core_ui/test_maindisplay.py' | |||
341 | --- tests/functional/openlp_core_ui/test_maindisplay.py 2015-12-31 22:46:06 +0000 | |||
342 | +++ tests/functional/openlp_core_ui/test_maindisplay.py 2016-01-07 22:31:35 +0000 | |||
343 | @@ -22,7 +22,7 @@ | |||
344 | 22 | """ | 22 | """ |
345 | 23 | Package to test the openlp.core.ui.slidecontroller package. | 23 | Package to test the openlp.core.ui.slidecontroller package. |
346 | 24 | """ | 24 | """ |
348 | 25 | from unittest import TestCase | 25 | from unittest import TestCase, skipUnless |
349 | 26 | 26 | ||
350 | 27 | from PyQt5 import QtCore | 27 | from PyQt5 import QtCore |
351 | 28 | 28 | ||
352 | @@ -141,13 +141,14 @@ | |||
353 | 141 | mocked_songs_plugin.refresh_css.assert_called_with(main_display.frame) | 141 | mocked_songs_plugin.refresh_css.assert_called_with(main_display.frame) |
354 | 142 | mocked_bibles_plugin.refresh_css.assert_called_with(main_display.frame) | 142 | mocked_bibles_plugin.refresh_css.assert_called_with(main_display.frame) |
355 | 143 | 143 | ||
357 | 144 | @patch('openlp.core.ui.maindisplay.is_macosx') | 144 | @skipUnless(is_macosx(), 'Can only run test on Mac OS X due to pyobjc dependency.') |
358 | 145 | def macosx_display_window_flags_state_test(self, is_macosx): | 145 | def macosx_display_window_flags_state_test(self, is_macosx): |
359 | 146 | """ | 146 | """ |
360 | 147 | Test that on Mac OS X we set the proper window flags | 147 | Test that on Mac OS X we set the proper window flags |
361 | 148 | """ | 148 | """ |
362 | 149 | if not is_macosx(): | ||
363 | 150 | self.skipTest('Can only run test on Mac OS X due to pyobjc dependency.') | ||
364 | 149 | # GIVEN: A new SlideController instance on Mac OS X. | 151 | # GIVEN: A new SlideController instance on Mac OS X. |
365 | 150 | is_macosx.return_value = True | ||
366 | 151 | self.screens.set_current_display(0) | 152 | self.screens.set_current_display(0) |
367 | 152 | display = MagicMock() | 153 | display = MagicMock() |
368 | 153 | 154 | ||
369 | @@ -159,12 +160,11 @@ | |||
370 | 159 | main_display.windowFlags(), | 160 | main_display.windowFlags(), |
371 | 160 | 'The window flags should be Qt.Window, and Qt.FramelessWindowHint.') | 161 | 'The window flags should be Qt.Window, and Qt.FramelessWindowHint.') |
372 | 161 | 162 | ||
373 | 163 | @skipUnless(is_macosx(), 'Can only run test on Mac OS X due to pyobjc dependency.') | ||
374 | 162 | def macosx_display_test(self): | 164 | def macosx_display_test(self): |
375 | 163 | """ | 165 | """ |
376 | 164 | Test display on Mac OS X | 166 | Test display on Mac OS X |
377 | 165 | """ | 167 | """ |
378 | 166 | if not is_macosx(): | ||
379 | 167 | self.skipTest('Can only run test on Mac OS X due to pyobjc dependency.') | ||
380 | 168 | # GIVEN: A new SlideController instance on Mac OS X. | 168 | # GIVEN: A new SlideController instance on Mac OS X. |
381 | 169 | self.screens.set_current_display(0) | 169 | self.screens.set_current_display(0) |
382 | 170 | display = MagicMock() | 170 | display = MagicMock() |
383 | 171 | 171 | ||
384 | === modified file 'tests/interfaces/openlp_core_ui/__init__.py' | |||
385 | --- tests/interfaces/openlp_core_ui/__init__.py 2015-12-31 22:46:06 +0000 | |||
386 | +++ tests/interfaces/openlp_core_ui/__init__.py 2016-01-07 22:31:35 +0000 | |||
387 | @@ -22,35 +22,3 @@ | |||
388 | 22 | """ | 22 | """ |
389 | 23 | Module-level functions for the functional test suite | 23 | Module-level functions for the functional test suite |
390 | 24 | """ | 24 | """ |
391 | 25 | |||
392 | 26 | import os | ||
393 | 27 | |||
394 | 28 | from openlp.core.common import is_win | ||
395 | 29 | |||
396 | 30 | from tests.interfaces import patch | ||
397 | 31 | from .test_projectormanager import tmpfile | ||
398 | 32 | |||
399 | 33 | |||
400 | 34 | def setUp(): | ||
401 | 35 | """ | ||
402 | 36 | Set up this module of tests | ||
403 | 37 | """ | ||
404 | 38 | if not is_win(): | ||
405 | 39 | # Wine creates a sharing violation during tests. Ignore. | ||
406 | 40 | try: | ||
407 | 41 | os.remove(tmpfile) | ||
408 | 42 | except: | ||
409 | 43 | pass | ||
410 | 44 | |||
411 | 45 | |||
412 | 46 | def tearDown(): | ||
413 | 47 | """ | ||
414 | 48 | Ensure test suite has been cleaned up after tests | ||
415 | 49 | """ | ||
416 | 50 | patch.stopall() | ||
417 | 51 | if not is_win(): | ||
418 | 52 | try: | ||
419 | 53 | # In case of changed schema, remove old test file | ||
420 | 54 | os.remove(tmpfile) | ||
421 | 55 | except FileNotFoundError: | ||
422 | 56 | pass | ||
423 | 57 | 25 | ||
424 | === modified file 'tests/interfaces/openlp_core_ui/test_projectoreditform.py' | |||
425 | --- tests/interfaces/openlp_core_ui/test_projectoreditform.py 2015-12-31 22:46:06 +0000 | |||
426 | +++ tests/interfaces/openlp_core_ui/test_projectoreditform.py 2016-01-07 22:31:35 +0000 | |||
427 | @@ -23,7 +23,7 @@ | |||
428 | 23 | Interface tests to test the openlp.core.ui.projector.editform.ProjectorEditForm() | 23 | Interface tests to test the openlp.core.ui.projector.editform.ProjectorEditForm() |
429 | 24 | class and methods. | 24 | class and methods. |
430 | 25 | """ | 25 | """ |
432 | 26 | 26 | import os | |
433 | 27 | from unittest import TestCase | 27 | from unittest import TestCase |
434 | 28 | 28 | ||
435 | 29 | from openlp.core.common import Registry, Settings | 29 | from openlp.core.common import Registry, Settings |
436 | @@ -32,7 +32,7 @@ | |||
437 | 32 | 32 | ||
438 | 33 | from tests.functional import patch | 33 | from tests.functional import patch |
439 | 34 | from tests.helpers.testmixin import TestMixin | 34 | from tests.helpers.testmixin import TestMixin |
441 | 35 | from tests.resources.projector.data import TEST1_DATA, TEST2_DATA | 35 | from tests.resources.projector.data import TEST_DB, TEST1_DATA, TEST2_DATA |
442 | 36 | 36 | ||
443 | 37 | 37 | ||
444 | 38 | class TestProjectorEditForm(TestCase, TestMixin): | 38 | class TestProjectorEditForm(TestCase, TestMixin): |
445 | @@ -49,7 +49,9 @@ | |||
446 | 49 | self.setup_application() | 49 | self.setup_application() |
447 | 50 | Registry.create() | 50 | Registry.create() |
448 | 51 | with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url: | 51 | with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url: |
450 | 52 | mocked_init_url.return_value = 'sqlite://' | 52 | if os.path.exists(TEST_DB): |
451 | 53 | os.unlink(TEST_DB) | ||
452 | 54 | mocked_init_url.return_value = 'sqlite:///' + TEST_DB | ||
453 | 53 | self.projectordb = ProjectorDB() | 55 | self.projectordb = ProjectorDB() |
454 | 54 | self.projector_form = ProjectorEditForm(projectordb=self.projectordb) | 56 | self.projector_form = ProjectorEditForm(projectordb=self.projectordb) |
455 | 55 | 57 | ||
456 | @@ -93,11 +95,13 @@ | |||
457 | 93 | with patch('openlp.core.ui.projector.editform.QDialog.exec'): | 95 | with patch('openlp.core.ui.projector.editform.QDialog.exec'): |
458 | 94 | 96 | ||
459 | 95 | # WHEN: Calling edit form with existing projector instance | 97 | # WHEN: Calling edit form with existing projector instance |
461 | 96 | self.projector_form.exec(projector=TEST1_DATA) | 98 | self.projector_form.exec(projector=Projector(**TEST1_DATA)) |
462 | 97 | item = self.projector_form.projector | 99 | item = self.projector_form.projector |
463 | 98 | 100 | ||
464 | 99 | # THEN: Should be editing an existing entry | 101 | # THEN: Should be editing an existing entry |
465 | 100 | self.assertFalse(self.projector_form.new_projector, | 102 | self.assertFalse(self.projector_form.new_projector, |
466 | 101 | 'Projector edit form should be marked as existing entry') | 103 | 'Projector edit form should be marked as existing entry') |
468 | 102 | self.assertTrue((item.ip is TEST1_DATA.ip and item.name is TEST1_DATA.name), | 104 | self.assertTrue((item.ip is TEST1_DATA['ip'] and item.name is TEST1_DATA['name']), |
469 | 103 | 'Projector edit form should have TEST1_DATA() instance to edit') | 105 | 'Projector edit form should have TEST1_DATA() instance to edit') |
470 | 106 | |||
471 | 107 | |||
472 | 104 | 108 | ||
473 | === modified file 'tests/interfaces/openlp_core_ui/test_projectormanager.py' | |||
474 | --- tests/interfaces/openlp_core_ui/test_projectormanager.py 2015-12-31 22:46:06 +0000 | |||
475 | +++ tests/interfaces/openlp_core_ui/test_projectormanager.py 2016-01-07 22:31:35 +0000 | |||
476 | @@ -22,7 +22,6 @@ | |||
477 | 22 | """ | 22 | """ |
478 | 23 | Interface tests to test the themeManager class and related methods. | 23 | Interface tests to test the themeManager class and related methods. |
479 | 24 | """ | 24 | """ |
480 | 25 | |||
481 | 26 | import os | 25 | import os |
482 | 27 | from unittest import TestCase | 26 | from unittest import TestCase |
483 | 28 | 27 | ||
484 | @@ -33,9 +32,7 @@ | |||
485 | 33 | from openlp.core.ui import ProjectorManager, ProjectorEditForm | 32 | from openlp.core.ui import ProjectorManager, ProjectorEditForm |
486 | 34 | from openlp.core.lib.projector.db import Projector, ProjectorDB | 33 | from openlp.core.lib.projector.db import Projector, ProjectorDB |
487 | 35 | 34 | ||
491 | 36 | from tests.resources.projector.data import TEST1_DATA, TEST2_DATA, TEST3_DATA | 35 | from tests.resources.projector.data import TEST_DB, TEST1_DATA, TEST2_DATA, TEST3_DATA |
489 | 37 | |||
490 | 38 | tmpfile = '/tmp/openlp-test-projectormanager.sql' | ||
492 | 39 | 36 | ||
493 | 40 | 37 | ||
494 | 41 | class TestProjectorManager(TestCase, TestMixin): | 38 | class TestProjectorManager(TestCase, TestMixin): |
495 | @@ -49,12 +46,13 @@ | |||
496 | 49 | self.build_settings() | 46 | self.build_settings() |
497 | 50 | self.setup_application() | 47 | self.setup_application() |
498 | 51 | Registry.create() | 48 | Registry.create() |
505 | 52 | if not hasattr(self, 'projector_manager'): | 49 | with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url: |
506 | 53 | with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url: | 50 | if os.path.exists(TEST_DB): |
507 | 54 | mocked_init_url.return_value = 'sqlite:///%s' % tmpfile | 51 | os.unlink(TEST_DB) |
508 | 55 | self.projectordb = ProjectorDB() | 52 | mocked_init_url.return_value = 'sqlite:///%s' % TEST_DB |
509 | 56 | if not hasattr(self, 'projector_manager'): | 53 | self.projectordb = ProjectorDB() |
510 | 57 | self.projector_manager = ProjectorManager(projectordb=self.projectordb) | 54 | if not hasattr(self, 'projector_manager'): |
511 | 55 | self.projector_manager = ProjectorManager(projectordb=self.projectordb) | ||
512 | 58 | 56 | ||
513 | 59 | def tearDown(self): | 57 | def tearDown(self): |
514 | 60 | """ | 58 | """ |
515 | 61 | 59 | ||
516 | === modified file 'tests/interfaces/openlp_core_ui/test_projectorsourceform.py' | |||
517 | --- tests/interfaces/openlp_core_ui/test_projectorsourceform.py 2015-12-31 22:46:06 +0000 | |||
518 | +++ tests/interfaces/openlp_core_ui/test_projectorsourceform.py 2016-01-07 22:31:35 +0000 | |||
519 | @@ -20,24 +20,24 @@ | |||
520 | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # | 20 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA # |
521 | 21 | ############################################################################### | 21 | ############################################################################### |
522 | 22 | """ | 22 | """ |
524 | 23 | :mod: `tests.interfaces.openlp_core_ui.test_projectorsourceform` module | 23 | :mod: `tests.interfaces.openlp_core_ui.test_projectorsourceform` module |
525 | 24 | 24 | ||
527 | 25 | Tests for the Projector Source Select form. | 25 | Tests for the Projector Source Select form. |
528 | 26 | """ | 26 | """ |
529 | 27 | import logging | 27 | import logging |
530 | 28 | log = logging.getLogger(__name__) | 28 | log = logging.getLogger(__name__) |
531 | 29 | log.debug('test_projectorsourceform loaded') | 29 | log.debug('test_projectorsourceform loaded') |
533 | 30 | 30 | import os | |
534 | 31 | from unittest import TestCase | 31 | from unittest import TestCase |
535 | 32 | |||
536 | 32 | from PyQt5.QtWidgets import QDialog | 33 | from PyQt5.QtWidgets import QDialog |
537 | 33 | 34 | ||
538 | 34 | from tests.functional import patch | 35 | from tests.functional import patch |
539 | 35 | from tests.functional.openlp_core_lib.test_projectordb import tmpfile | ||
540 | 36 | from tests.helpers.testmixin import TestMixin | 36 | from tests.helpers.testmixin import TestMixin |
541 | 37 | from tests.resources.projector.data import TEST_DB, TEST1_DATA | 37 | from tests.resources.projector.data import TEST_DB, TEST1_DATA |
542 | 38 | 38 | ||
543 | 39 | from openlp.core.common import Registry, Settings | 39 | from openlp.core.common import Registry, Settings |
545 | 40 | from openlp.core.lib.projector.db import ProjectorDB | 40 | from openlp.core.lib.projector.db import ProjectorDB, Projector |
546 | 41 | from openlp.core.lib.projector.constants import PJLINK_DEFAULT_CODES, PJLINK_DEFAULT_SOURCES | 41 | from openlp.core.lib.projector.constants import PJLINK_DEFAULT_CODES, PJLINK_DEFAULT_SOURCES |
547 | 42 | from openlp.core.ui.projector.sourceselectform import source_group, SourceSelectSingle | 42 | from openlp.core.ui.projector.sourceselectform import source_group, SourceSelectSingle |
548 | 43 | 43 | ||
549 | @@ -65,7 +65,9 @@ | |||
550 | 65 | """ | 65 | """ |
551 | 66 | Set up anything necessary for all tests | 66 | Set up anything necessary for all tests |
552 | 67 | """ | 67 | """ |
554 | 68 | mocked_init_url.return_value = 'sqlite:///{}'.format(tmpfile) | 68 | if os.path.exists(TEST_DB): |
555 | 69 | os.unlink(TEST_DB) | ||
556 | 70 | mocked_init_url.return_value = 'sqlite:///{}'.format(TEST_DB) | ||
557 | 69 | self.build_settings() | 71 | self.build_settings() |
558 | 70 | self.setup_application() | 72 | self.setup_application() |
559 | 71 | Registry.create() | 73 | Registry.create() |
560 | @@ -73,10 +75,10 @@ | |||
561 | 73 | if not hasattr(self, 'projectordb'): | 75 | if not hasattr(self, 'projectordb'): |
562 | 74 | self.projectordb = ProjectorDB() | 76 | self.projectordb = ProjectorDB() |
563 | 75 | # Retrieve/create a database record | 77 | # Retrieve/create a database record |
565 | 76 | self.projector = self.projectordb.get_projector_by_ip(TEST1_DATA.ip) | 78 | self.projector = self.projectordb.get_projector_by_ip(TEST1_DATA['ip']) |
566 | 77 | if not self.projector: | 79 | if not self.projector: |
569 | 78 | self.projectordb.add_projector(projector=TEST1_DATA) | 80 | self.projectordb.add_projector(projector=Projector(**TEST1_DATA)) |
570 | 79 | self.projector = self.projectordb.get_projector_by_ip(TEST1_DATA.ip) | 81 | self.projector = self.projectordb.get_projector_by_ip(TEST1_DATA['ip']) |
571 | 80 | self.projector.dbid = self.projector.id | 82 | self.projector.dbid = self.projector.id |
572 | 81 | self.projector.db_item = self.projector | 83 | self.projector.db_item = self.projector |
573 | 82 | 84 | ||
574 | 83 | 85 | ||
575 | === modified file 'tests/interfaces/openlp_plugins/bibles/test_lib_http.py' | |||
576 | --- tests/interfaces/openlp_plugins/bibles/test_lib_http.py 2015-12-31 22:46:06 +0000 | |||
577 | +++ tests/interfaces/openlp_plugins/bibles/test_lib_http.py 2016-01-07 22:31:35 +0000 | |||
578 | @@ -130,7 +130,7 @@ | |||
579 | 130 | # THEN: The list should not be None, and some known bibles should be there | 130 | # THEN: The list should not be None, and some known bibles should be there |
580 | 131 | self.assertIsNotNone(bibles) | 131 | self.assertIsNotNone(bibles) |
581 | 132 | self.assertIn(('New Int. Readers Version', 'NIRV', 'en'), bibles) | 132 | self.assertIn(('New Int. Readers Version', 'NIRV', 'en'), bibles) |
583 | 133 | self.assertIn(('Българската Библия', 'BLG', 'bg'), bibles) | 133 | self.assertIn(('Священное Писание, Восточный перевод', 'CARS', 'ru'), bibles) |
584 | 134 | 134 | ||
585 | 135 | def biblegateway_get_bibles_test(self): | 135 | def biblegateway_get_bibles_test(self): |
586 | 136 | """ | 136 | """ |
587 | 137 | 137 | ||
588 | === modified file 'tests/resources/projector/data.py' | |||
589 | --- tests/resources/projector/data.py 2015-12-31 22:46:06 +0000 | |||
590 | +++ tests/resources/projector/data.py 2016-01-07 22:31:35 +0000 | |||
591 | @@ -24,28 +24,28 @@ | |||
592 | 24 | """ | 24 | """ |
593 | 25 | 25 | ||
594 | 26 | import os | 26 | import os |
596 | 27 | from openlp.core.lib.projector.db import Projector | 27 | from tempfile import gettempdir |
597 | 28 | 28 | ||
598 | 29 | # Test data | 29 | # Test data |
621 | 30 | TEST_DB = os.path.join('tmp', 'openlp-test-projectordb.sql') | 30 | TEST_DB = os.path.join(gettempdir(), 'openlp-test-projectordb.sql') |
622 | 31 | 31 | ||
623 | 32 | TEST1_DATA = Projector(ip='111.111.111.111', | 32 | TEST1_DATA = dict(ip='111.111.111.111', |
624 | 33 | port='1111', | 33 | port='1111', |
625 | 34 | pin='1111', | 34 | pin='1111', |
626 | 35 | name='___TEST_ONE___', | 35 | name='___TEST_ONE___', |
627 | 36 | location='location one', | 36 | location='location one', |
628 | 37 | notes='notes one') | 37 | notes='notes one') |
629 | 38 | 38 | ||
630 | 39 | TEST2_DATA = Projector(ip='222.222.222.222', | 39 | TEST2_DATA = dict(ip='222.222.222.222', |
631 | 40 | port='2222', | 40 | port='2222', |
632 | 41 | pin='2222', | 41 | pin='2222', |
633 | 42 | name='___TEST_TWO___', | 42 | name='___TEST_TWO___', |
634 | 43 | location='location two', | 43 | location='location two', |
635 | 44 | notes='notes two') | 44 | notes='notes two') |
636 | 45 | 45 | ||
637 | 46 | TEST3_DATA = Projector(ip='333.333.333.333', | 46 | TEST3_DATA = dict(ip='333.333.333.333', |
638 | 47 | port='3333', | 47 | port='3333', |
639 | 48 | pin='3333', | 48 | pin='3333', |
640 | 49 | name='___TEST_THREE___', | 49 | name='___TEST_THREE___', |
641 | 50 | location='location three', | 50 | location='location three', |
642 | 51 | notes='notes three') | 51 | notes='notes three') |