Skip to content

Commit 8462d69

Browse files
committed
speed up some tests setup + avoid long timeout on random server for subscriber test requests
1 parent fd8d6be commit 8462d69

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

tests/functional/test_cli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import mock
1717
import pytest
18+
import responses
1819
import yaml
1920
from owslib.ows import DEFAULT_OWS_NAMESPACE
2021
from owslib.wps import WPSException
@@ -1869,13 +1870,18 @@ def test_execute_subscriber_options(self):
18691870
"""
18701871
proc = self.test_process["Echo"]
18711872
with contextlib.ExitStack() as stack_exec:
1873+
req_mock = stack_exec.enter_context(responses.RequestsMock())
18721874
for mock_exec_proc in mocked_execute_celery():
18731875
stack_exec.enter_context(mock_exec_proc)
18741876

18751877
test_email_started = "started-job@email.com"
18761878
test_email_failed = "failed-job@email.com"
18771879
test_callback_started = "https://server.com/started"
18781880
test_callback_success = "https://server.com/success"
1881+
1882+
req_mock.add_callback(responses.POST, test_callback_started, callback=lambda _: (200, {}, ""))
1883+
req_mock.add_callback(responses.POST, test_callback_success, callback=lambda _: (200, {}, ""))
1884+
18791885
lines = mocked_sub_requests(
18801886
self.app, run_command,
18811887
[

tests/wps_restapi/test_status_codes.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import uuid
33

44
import pytest
5+
from parameterized import parameterized
56

67
from tests.utils import get_test_weaver_app, setup_config_with_mongodb
78
from weaver.formats import ContentType
@@ -45,23 +46,24 @@ class StatusCodeTestCase(unittest.TestCase):
4546

4647
headers = {"Accept": ContentType.APP_JSON}
4748

48-
def setUp(self):
49+
@classmethod
50+
def setUpClass(cls):
4951
config = setup_config_with_mongodb()
50-
self.testapp = get_test_weaver_app(config)
52+
cls.testapp = get_test_weaver_app(config)
5153

52-
def test_200(self):
53-
for uri in TEST_PUBLIC_ROUTES:
54-
resp = self.testapp.get(uri, expect_errors=True, headers=self.headers)
55-
self.assertEqual(200, resp.status_code, f"route {uri} did not return 200")
54+
@parameterized.expand(TEST_PUBLIC_ROUTES)
55+
def test_200(self, uri):
56+
resp = self.testapp.get(uri, expect_errors=True, headers=self.headers)
57+
self.assertEqual(200, resp.status_code, f"route {uri} did not return 200")
5658

5759
@pytest.mark.xfail(reason="Not working if not behind proxy. Protected implementation to be done.")
60+
@parameterized.expand(TEST_FORBIDDEN_ROUTES)
5861
@unittest.expectedFailure
59-
def test_401(self):
60-
for uri in TEST_FORBIDDEN_ROUTES:
61-
resp = self.testapp.get(uri, expect_errors=True, headers=self.headers)
62-
self.assertEqual(401, resp.status_code, f"route {uri} did not return 401")
62+
def test_401(self, uri):
63+
resp = self.testapp.get(uri, expect_errors=True, headers=self.headers)
64+
self.assertEqual(401, resp.status_code, f"route {uri} did not return 401")
6365

64-
def test_404(self):
65-
for uri in TEST_NOTFOUND_ROUTES:
66-
resp = self.testapp.get(uri, expect_errors=True, headers=self.headers)
67-
self.assertEqual(404, resp.status_code, f"route {uri} did not return 404")
66+
@parameterized.expand(TEST_NOTFOUND_ROUTES)
67+
def test_404(self, uri):
68+
resp = self.testapp.get(uri, expect_errors=True, headers=self.headers)
69+
self.assertEqual(404, resp.status_code, f"route {uri} did not return 404")

0 commit comments

Comments
 (0)