Skip to content

Commit

Permalink
Revert "ISSUE #92 - Remove unittest_run_loop"
Browse files Browse the repository at this point in the history
This reverts commit 8ad997e
  • Loading branch information
vladyslav-fenchak committed Feb 16, 2022
1 parent 8ad997e commit bd9a6c1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/test_api_gateway/test_rest/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from aiohttp.test_utils import (
AioHTTPTestCase,
unittest_run_loop,
)

from minos.api_gateway.rest import (
Expand Down Expand Up @@ -42,6 +43,7 @@ async def get_application(self):

return await rest_service.create_application()

@unittest_run_loop
async def test_admin_login(self):
url = "/admin/login"

Expand All @@ -55,6 +57,7 @@ async def test_admin_login(self):
self.assertIn("id", await response.text())
self.assertIn("token", await response.text())

@unittest_run_loop
async def test_admin_login_no_data(self):
url = "/admin/login"

Expand All @@ -63,6 +66,7 @@ async def test_admin_login_no_data(self):
self.assertEqual(401, response.status)
self.assertDictEqual({"error": "Something went wrong!."}, json.loads(await response.text()))

@unittest_run_loop
async def test_admin_login_wrong_data(self):
url = "/admin/login"

Expand Down Expand Up @@ -101,6 +105,7 @@ async def get_application(self):

return await rest_service.create_application()

@unittest_run_loop
async def test_admin_get_endpoints(self):
url = "/admin/endpoints"

Expand Down Expand Up @@ -132,6 +137,7 @@ async def get_application(self):

return await rest_service.create_application()

@unittest_run_loop
async def test_admin_get_endpoints(self):
url = "/admin/endpoints"

Expand Down Expand Up @@ -162,13 +168,15 @@ async def get_application(self):

return await rest_service.create_application()

@unittest_run_loop
async def test_admin_get_rules(self):
url = "/admin/rules"

response = await self.client.request("GET", url)

self.assertEqual(200, response.status)

@unittest_run_loop
async def test_admin_create_rule(self):
url = "/admin/rules"

Expand All @@ -180,6 +188,7 @@ async def test_admin_create_rule(self):

self.assertEqual(200, response.status)

@unittest_run_loop
async def test_admin_update_rule(self):
url = "/admin/rules"

Expand All @@ -203,6 +212,7 @@ async def test_admin_update_rule(self):

self.assertEqual(200, response.status)

@unittest_run_loop
async def test_admin_delete_rule(self):
url = "/admin/rules"

Expand Down
12 changes: 12 additions & 0 deletions tests/test_api_gateway/test_rest/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from aiohttp.test_utils import (
AioHTTPTestCase,
unittest_run_loop,
)
from werkzeug.exceptions import (
abort,
Expand Down Expand Up @@ -87,6 +88,7 @@ async def get_application(self):

return await rest_service.create_application()

@unittest_run_loop
async def test_auth_headers_1(self):
url = "/order"
headers = {"Authorization": "Bearer credential-token-test"}
Expand All @@ -96,6 +98,7 @@ async def test_auth_headers_1(self):
self.assertEqual(200, response.status)
self.assertIn("Microservice call correct!!!", await response.text())

@unittest_run_loop
async def test_auth_headers_2(self):
url = "/merchants/5"
headers = {"Authorization": "Bearer credential-token-test"}
Expand All @@ -105,6 +108,7 @@ async def test_auth_headers_2(self):
self.assertEqual(200, response.status)
self.assertIn("Microservice call correct!!!", await response.text())

@unittest_run_loop
async def test_auth_headers_3(self):
url = "/categories/5"
headers = {"Authorization": "Bearer credential-token-test"}
Expand All @@ -114,6 +118,7 @@ async def test_auth_headers_3(self):
self.assertEqual(200, response.status)
self.assertIn("Microservice call correct!!!", await response.text())

@unittest_run_loop
async def test_default_auth_headers(self):
url = "/auth/token"
headers = {"Authorization": "Bearer credential-token-test"}
Expand All @@ -123,6 +128,7 @@ async def test_default_auth_headers(self):
self.assertEqual(200, response.status)
self.assertIn("token", await response.text())

@unittest_run_loop
async def test_auth(self):
url = "/auth/credentials"
headers = {"Authorization": "Bearer credential-token-test"}
Expand All @@ -132,6 +138,7 @@ async def test_auth(self):
self.assertEqual(200, response.status)
self.assertIn("uuid", await response.text())

@unittest_run_loop
async def test_wrong_auth_headers(self):
url = "/order"
headers = {"Authorization": "Bearer"} # Missing token
Expand All @@ -140,6 +147,7 @@ async def test_wrong_auth_headers(self):
self.assertEqual(200, response.status)
self.assertIn("Microservice call correct!!!", await response.text())

@unittest_run_loop
async def test_request_has_token(self):
url = "/order"
headers = {"Authorization": "Bearer"} # Missing token
Expand Down Expand Up @@ -185,6 +193,7 @@ async def get_application(self):

return await rest_service.create_application()

@unittest_run_loop
async def test_auth_disabled(self):
url = "/order"
headers = {"Authorization": "Bearer test_token"}
Expand Down Expand Up @@ -236,6 +245,7 @@ async def get_application(self):

return await rest_service.create_application()

@unittest_run_loop
async def test_auth_unauthorized(self):
await self.client.post(
"/admin/rules",
Expand Down Expand Up @@ -286,6 +296,7 @@ async def get_application(self):

return await rest_service.create_application()

@unittest_run_loop
async def test_auth_unreachable(self):
url = "/merchants/iweuwieuwe"
headers = {"Authorization": "Bearer test_token"}
Expand All @@ -294,6 +305,7 @@ async def test_auth_unreachable(self):
self.assertEqual(503, response.status)
self.assertEqual("The requested endpoint is not available.", await response.text())

@unittest_run_loop
async def test_auth(self):
url = "/auth/credentials"
headers = {"Authorization": "Bearer credential-token-test"}
Expand Down
2 changes: 2 additions & 0 deletions tests/test_api_gateway/test_rest/test_cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import attr
from aiohttp.test_utils import (
AioHTTPTestCase,
unittest_run_loop,
)
from aiohttp_middlewares.cors import (
ACCESS_CONTROL_ALLOW_HEADERS,
Expand Down Expand Up @@ -76,6 +77,7 @@ def check_allow_origin(
if allow_methods:
assert response.headers[ACCESS_CONTROL_ALLOW_METHODS] == ", ".join(allow_methods)

@unittest_run_loop
async def test_cors_enabled(self):
method = "GET"
extra_headers = {}
Expand Down
10 changes: 10 additions & 0 deletions tests/test_api_gateway/test_rest/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from aiohttp.test_utils import (
AioHTTPTestCase,
unittest_run_loop,
)
from werkzeug.exceptions import (
abort,
Expand Down Expand Up @@ -59,34 +60,39 @@ async def get_application(self):

return await rest_service.create_application()

@unittest_run_loop
async def test_get(self):
url = "/order/5?verb=GET&path=12324"
response = await self.client.request("GET", url)

self.assertEqual(200, response.status)
self.assertIn("Microservice call correct!!!", await response.text())

@unittest_run_loop
async def test_post(self):
url = "/order"
response = await self.client.request("POST", url)

self.assertEqual(200, response.status)
self.assertIn("Microservice call correct!!!", await response.text())

@unittest_run_loop
async def test_put(self):
url = "/order/5"
response = await self.client.request("PUT", url)

self.assertEqual(200, response.status)
self.assertIn("Microservice call correct!!!", await response.text())

@unittest_run_loop
async def test_patch(self):
url = "/order/5"
response = await self.client.request("PATCH", url)

self.assertEqual(200, response.status)
self.assertIn("Microservice call correct!!!", await response.text())

@unittest_run_loop
async def test_delete(self):
url = "/order/5"
response = await self.client.request("DELETE", url)
Expand Down Expand Up @@ -119,6 +125,7 @@ async def get_application(self):

return await rest_service.create_application()

@unittest_run_loop
async def test_get(self):
url = "/order/5?verb=GET&path=12324"
response = await self.client.request("GET", url)
Expand Down Expand Up @@ -153,6 +160,7 @@ async def get_application(self):

return await rest_service.create_application()

@unittest_run_loop
async def test_get(self):
url = "/order/5?verb=GET&path=12324"
response = await self.client.request("GET", url)
Expand All @@ -179,6 +187,7 @@ async def get_application(self):

return await rest_service.create_application()

@unittest_run_loop
async def test_get(self):
url = "/order/5?verb=GET&path=12324"
response = await self.client.request("GET", url)
Expand Down Expand Up @@ -215,6 +224,7 @@ async def get_application(self):

return await rest_service.create_application()

@unittest_run_loop
async def test_get(self):
url = "/order/5?verb=GET&path=12324"
response = await self.client.request("GET", url)
Expand Down

0 comments on commit bd9a6c1

Please sign in to comment.