|
2 | 2 | import uuid
|
3 | 3 |
|
4 | 4 | import pytest
|
| 5 | +from parameterized import parameterized |
5 | 6 |
|
6 | 7 | from tests.utils import get_test_weaver_app, setup_config_with_mongodb
|
7 | 8 | from weaver.formats import ContentType
|
@@ -45,23 +46,24 @@ class StatusCodeTestCase(unittest.TestCase):
|
45 | 46 |
|
46 | 47 | headers = {"Accept": ContentType.APP_JSON}
|
47 | 48 |
|
48 |
| - def setUp(self): |
| 49 | + @classmethod |
| 50 | + def setUpClass(cls): |
49 | 51 | config = setup_config_with_mongodb()
|
50 |
| - self.testapp = get_test_weaver_app(config) |
| 52 | + cls.testapp = get_test_weaver_app(config) |
51 | 53 |
|
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") |
56 | 58 |
|
57 | 59 | @pytest.mark.xfail(reason="Not working if not behind proxy. Protected implementation to be done.")
|
| 60 | + @parameterized.expand(TEST_FORBIDDEN_ROUTES) |
58 | 61 | @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") |
63 | 65 |
|
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