From 02df3149c722fe00dab50572b094e58c758b6215 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 9 Dec 2017 15:21:59 +0000 Subject: [PATCH] First attempt 2 --- .../openlp_core/api/http/test_http.py | 4 +-- .../openlp_core/api/http/test_wsgiapp.py | 6 ++-- .../functional/openlp_core/api/test_deploy.py | 2 +- tests/functional/openlp_core/api/test_tab.py | 23 +++++++------- .../openlp_core/api/test_websockets.py | 31 +++++++++---------- 5 files changed, 32 insertions(+), 34 deletions(-) diff --git a/tests/functional/openlp_core/api/http/test_http.py b/tests/functional/openlp_core/api/http/test_http.py index c3cd1d1f4..7dd8418ae 100644 --- a/tests/functional/openlp_core/api/http/test_http.py +++ b/tests/functional/openlp_core/api/http/test_http.py @@ -54,7 +54,7 @@ class TestHttpServer(TestCase): # THEN: the api environment should have been created assert mock_qthread.call_count == 1, 'The qthread should have been called once' - assert mock_thread.call_count == 0, 'The http thread should have been called once' + assert mock_thread.call_count == 1, 'The http thread should have been called once' @patch('openlp.core.api.http.server.HttpWorker') @patch('openlp.core.api.http.server.QtCore.QThread') @@ -69,4 +69,4 @@ class TestHttpServer(TestCase): # THEN: the api environment should have been created assert mock_qthread.call_count == 0, 'The qthread should not have have been called' - assert mock_thread.call_count == 1, 'The http thread should not have been called' + assert mock_thread.call_count == 0, 'The http thread should not have been called' diff --git a/tests/functional/openlp_core/api/http/test_wsgiapp.py b/tests/functional/openlp_core/api/http/test_wsgiapp.py index aff27404a..17b3ae8c5 100644 --- a/tests/functional/openlp_core/api/http/test_wsgiapp.py +++ b/tests/functional/openlp_core/api/http/test_wsgiapp.py @@ -61,7 +61,7 @@ class TestRouting(TestCase): application.dispatch(rqst) # THEN: the not found returned - self.assertEqual(context.exception.args[0], 'Not Found', 'URL not found in dispatcher') + assert context.exception.args[0] == 'Not Found', 'URL not found in dispatcher' # WHEN: when the URL is correct and dispatch called rqst = MagicMock() @@ -69,8 +69,8 @@ class TestRouting(TestCase): rqst.method = 'GET' application.dispatch(rqst) # THEN: the not found id called - self.assertEqual(1, application.route_map['^\\/test\\/image$']['GET'].call_count, - 'main_index function should have been called') + assert 1 == application.route_map['^\\/test\\/image$']['GET'].call_count, \ + 'main_index function should have been called' @test_endpoint.route('image') diff --git a/tests/functional/openlp_core/api/test_deploy.py b/tests/functional/openlp_core/api/test_deploy.py index 702e2a35d..0aaf1308b 100644 --- a/tests/functional/openlp_core/api/test_deploy.py +++ b/tests/functional/openlp_core/api/test_deploy.py @@ -58,4 +58,4 @@ class TestRemoteDeploy(TestCase): deploy_zipfile(self.app_root_path, 'site.zip') # THEN: test if www directory has been created - self.assertTrue((self.app_root_path / 'www').is_dir(), 'We should have a www directory') + assert (self.app_root_path / 'www').is_dir(), 'We should have a www directory' diff --git a/tests/functional/openlp_core/api/test_tab.py b/tests/functional/openlp_core/api/test_tab.py index f3c4f31e6..1601c223b 100644 --- a/tests/functional/openlp_core/api/test_tab.py +++ b/tests/functional/openlp_core/api/test_tab.py @@ -81,8 +81,8 @@ class TestApiTab(TestCase, TestMixin): # WHEN: the default ip address is given ip_address = self.form.get_ip_address(ZERO_URL) # THEN: the default ip address will be returned - self.assertTrue(re.match('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', ip_address), - 'The return value should be a valid ip address') + assert re.match('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}') == ip_address, \ + 'The return value should be a valid ip address' def test_get_ip_address_with_ip(self): """ @@ -93,7 +93,7 @@ class TestApiTab(TestCase, TestMixin): # WHEN: the default ip address is given ip_address = self.form.get_ip_address(given_ip) # THEN: the default ip address will be returned - self.assertEqual(ip_address, given_ip, 'The return value should be %s' % given_ip) + assert ip_address == given_ip, 'The return value should be %s' % given_ip def test_set_urls(self): """ @@ -104,12 +104,11 @@ class TestApiTab(TestCase, TestMixin): # WHEN: the urls are generated self.form.set_urls() # THEN: the following links are returned - self.assertEqual(self.form.remote_url.text(), - "http://192.168.1.1:4316/", - 'The return value should be a fully formed link') - self.assertEqual(self.form.stage_url.text(), - "http://192.168.1.1:4316/stage", - 'The return value should be a fully formed stage link') - self.assertEqual(self.form.live_url.text(), - "http://192.168.1.1:4316/main", - 'The return value should be a fully formed main link') + assert self.form.remote_url.text() == "http://192.168.1.1:4316/", \ + 'The return value should be a fully formed link' + assert self.form.stage_url.text() == \ + "http://192.168.1.1:4316/stage", \ + 'The return value should be a fully formed stage link' + assert self.form.live_url.text() == \ + "http://192.168.1.1:4316/main", \ + 'The return value should be a fully formed main link' diff --git a/tests/functional/openlp_core/api/test_websockets.py b/tests/functional/openlp_core/api/test_websockets.py index f400c50a5..7cc3f376c 100644 --- a/tests/functional/openlp_core/api/test_websockets.py +++ b/tests/functional/openlp_core/api/test_websockets.py @@ -74,8 +74,8 @@ class TestWSServer(TestCase, TestMixin): WebSocketServer() # THEN: the api environment should have been created - self.assertEquals(1, mock_qthread.call_count, 'The qthread should have been called once') - self.assertEquals(1, mock_worker.call_count, 'The http thread should have been called once') + assert mock_qthread.call_count == 1, 'The qthread should have been called once' + assert mock_worker.call_count == 1, 'The http thread should have been called once' @patch('openlp.core.api.websockets.WebSocketWorker') @patch('openlp.core.api.websockets.QtCore.QThread') @@ -89,8 +89,8 @@ class TestWSServer(TestCase, TestMixin): WebSocketServer() # THEN: the api environment should have been created - self.assertEquals(0, mock_qthread.call_count, 'The qthread should not have been called') - self.assertEquals(0, mock_worker.call_count, 'The http thread should not have been called') + assert mock_qthread.call_count == 0, 'The qthread should not have been called' + assert mock_worker.call_count == 0, 'The http thread should not have been called' def test_main_poll(self): """ @@ -102,8 +102,7 @@ class TestWSServer(TestCase, TestMixin): Registry().register('live_controller', mocked_live_controller) # THEN: the live json should be generated main_json = self.poll.main_poll() - self.assertEquals(b'{"results": {"slide_count": 5}}', main_json, - 'The return value should match the defined json') + assert b'{"results": {"slide_count": 5}}' == main_json, 'The return value should match the defined json' def test_poll(self): """ @@ -130,13 +129,13 @@ class TestWSServer(TestCase, TestMixin): mocked_is_chords_active.return_value = True poll_json = self.poll.poll() # THEN: the live json should be generated and match expected results - self.assertTrue(poll_json['results']['blank'], 'The blank return value should be True') - self.assertFalse(poll_json['results']['theme'], 'The theme return value should be False') - self.assertFalse(poll_json['results']['display'], 'The display return value should be False') - self.assertFalse(poll_json['results']['isSecure'], 'The isSecure return value should be False') - self.assertFalse(poll_json['results']['isAuthorised'], 'The isAuthorised return value should be False') - self.assertTrue(poll_json['results']['twelve'], 'The twelve return value should be False') - self.assertEquals(poll_json['results']['version'], 3, 'The version return value should be 3') - self.assertEquals(poll_json['results']['slide'], 5, 'The slide return value should be 5') - self.assertEquals(poll_json['results']['service'], 21, 'The version return value should be 21') - self.assertEquals(poll_json['results']['item'], '23-34-45', 'The item return value should match 23-34-45') + assert poll_json['results']['blank'], 'The blank return value should be True' + assert poll_json['results']['theme'], 'The theme return value should be False' + assert poll_json['results']['display'], 'The display return value should be False' + assert poll_json['results']['isSecure'], 'The isSecure return value should be False' + assert poll_json['results']['isAuthorised'], 'The isAuthorised return value should be False' + assert poll_json['results']['twelve'], 'The twelve return value should be False' + assert poll_json['results']['version'] == 3, 'The version return value should be 3' + assert poll_json['results']['slide'] == 5, 'The slide return value should be 5' + assert poll_json['results']['service'] == 21, 'The version return value should be 21' + assert poll_json['results']['item'] == '23-34-45', 'The item return value should match 23-34-45'