mirror of
https://github.com/shadoll/scatcher.git
synced 2026-02-04 11:03:23 +00:00
Add unit tests for app and history controller
This commit is contained in:
@@ -9,6 +9,7 @@ from unittest import IsolatedAsyncioTestCase
|
||||
from schema.methods import Methods
|
||||
from typing import Any
|
||||
|
||||
|
||||
class TestHistoryController(IsolatedAsyncioTestCase):
|
||||
def setUp(self):
|
||||
self.namespace = "test"
|
||||
@@ -38,7 +39,11 @@ class TestHistoryController(IsolatedAsyncioTestCase):
|
||||
async def test_history_with_id_existing_request(self):
|
||||
self.history.add(self.request_data)
|
||||
response = Response()
|
||||
result = await self.controller.history(response, id=0, namespace=self.namespace)
|
||||
result = await self.controller.history(
|
||||
response,
|
||||
id=0,
|
||||
namespace=self.namespace,
|
||||
)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(result, RequestData(**self.request_data))
|
||||
|
||||
@@ -46,7 +51,9 @@ class TestHistoryController(IsolatedAsyncioTestCase):
|
||||
self.history.clear()
|
||||
response = Response()
|
||||
result = await self.controller.history(
|
||||
response=response, id=0, namespace=self.namespace
|
||||
response=response,
|
||||
id=0,
|
||||
namespace=self.namespace,
|
||||
)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(
|
||||
@@ -63,6 +70,17 @@ class TestHistoryController(IsolatedAsyncioTestCase):
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(result, [RequestData(**self.request_data)])
|
||||
|
||||
async def test_history_without_id_no_requests(self):
|
||||
self.history.clear()
|
||||
response = Response()
|
||||
result = await self.controller.history(
|
||||
response=response, namespace=self.namespace
|
||||
)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(
|
||||
result, Answer(status=Status.error, message="No requests found.")
|
||||
)
|
||||
|
||||
async def test_last_requests_invalid_namespace(self):
|
||||
response = Response()
|
||||
result = await self.controller.last_requests(
|
||||
|
||||
Reference in New Issue
Block a user