From a69df60978644d47365f7d98e0db059377c288ea Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 21 Dec 2016 09:47:33 +0000 Subject: [PATCH] Fix tests again --- .../openlp_core_common/test_httputils.py | 18 ++++++++++++++---- .../openlp_core_ui/test_firsttimeform.py | 3 ++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/functional/openlp_core_common/test_httputils.py b/tests/functional/openlp_core_common/test_httputils.py index 8709e9cfb..6bf7aaa4c 100644 --- a/tests/functional/openlp_core_common/test_httputils.py +++ b/tests/functional/openlp_core_common/test_httputils.py @@ -22,19 +22,29 @@ """ Functional tests to test the AppLocation class and related methods. """ -import socket import os +import tempfile +import socket from unittest import TestCase from openlp.core.common.httputils import get_user_agent, get_web_page, get_url_file_size, url_get_file from tests.functional import MagicMock, patch +from tests.helpers.testmixin import TestMixin -class TestHttpUtils(TestCase): +class TestHttpUtils(TestCase, TestMixin): + """ - A test suite to test out various methods around the AppLocation class. + A test suite to test out various http helper functions. """ + def setUp(self): + self.tempfile = os.path.join(tempfile.gettempdir(), 'testfile') + + def tearDown(self): + if os.path.isfile(self.tempfile): + os.remove(self.tempfile) + def test_get_user_agent_linux(self): """ Test that getting a user agent on Linux returns a user agent suitable for Linux @@ -257,7 +267,7 @@ class TestHttpUtils(TestCase): mocked_urlopen.side_effect = socket.timeout() # WHEN: Attempt to retrieve a file - url_get_file(url='http://localhost/test', f_path=self.tempfile) + url_get_file(MagicMock(), url='http://localhost/test', f_path=self.tempfile) # THEN: socket.timeout should have been caught # NOTE: Test is if $tmpdir/tempfile is still there, then test fails since ftw deletes bad downloaded files diff --git a/tests/functional/openlp_core_ui/test_firsttimeform.py b/tests/functional/openlp_core_ui/test_firsttimeform.py index ec26f60fe..ec77a3134 100644 --- a/tests/functional/openlp_core_ui/test_firsttimeform.py +++ b/tests/functional/openlp_core_ui/test_firsttimeform.py @@ -224,7 +224,8 @@ class TestFirstTimeForm(TestCase, TestMixin): # GIVEN: Initial setup and mocks first_time_form = FirstTimeForm(None) first_time_form.initialize(MagicMock()) - mocked_get_web_page.side_effect = urllib.error.HTTPError(url='http//localhost', + mocked_get_web_page.side_effect = urllib.error.HTTPError(MagicMock(), + url='http//localhost', code=407, msg='Network proxy error', hdrs=None,