First attempt 2

This commit is contained in:
Tim Bentley 2017-12-09 15:21:59 +00:00
parent d2ba2ad599
commit 02df3149c7
5 changed files with 32 additions and 34 deletions

View File

@ -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'

View File

@ -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')

View File

@ -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'

View File

@ -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(),
"<a href=\"http://192.168.1.1:4316/\">http://192.168.1.1:4316/</a>",
'The return value should be a fully formed link')
self.assertEqual(self.form.stage_url.text(),
"<a href=\"http://192.168.1.1:4316/stage\">http://192.168.1.1:4316/stage</a>",
'The return value should be a fully formed stage link')
self.assertEqual(self.form.live_url.text(),
"<a href=\"http://192.168.1.1:4316/main\">http://192.168.1.1:4316/main</a>",
'The return value should be a fully formed main link')
assert self.form.remote_url.text() == "<a href=\"http://192.168.1.1:4316/\">http://192.168.1.1:4316/</a>", \
'The return value should be a fully formed link'
assert self.form.stage_url.text() == \
"<a href=\"http://192.168.1.1:4316/stage\">http://192.168.1.1:4316/stage</a>", \
'The return value should be a fully formed stage link'
assert self.form.live_url.text() == \
"<a href=\"http://192.168.1.1:4316/main\">http://192.168.1.1:4316/main</a>", \
'The return value should be a fully formed main link'

View File

@ -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'