Skip to content

Commit

Permalink
e2e integration tests + little addition to helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
AvangardAA committed Nov 2, 2023
1 parent 3fe9e72 commit ff42429
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
8 changes: 7 additions & 1 deletion functions/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ async def get_reports(reportname, ffrom, to):
async def helper_function_exam():
c = 0
users_data = fetch(c)
if users_data == []:
return {"msg":"error"}
q = int(users_data['total'])

file_path = os.path.join(os.getcwd(), "log_exam.txt")
Expand All @@ -400,8 +402,12 @@ async def helper_function_exam():
c += len(users_data['data'])
users_data = fetch(c)

return "success"

async def get_uuser_list_exam():
await helper_function_exam()
res = await helper_function_exam()
if res != "success":
return {"err": "some error"}
with open('log_exam.txt', 'r') as file:
file_contents = file.read()

Expand Down
23 changes: 23 additions & 0 deletions tests/e2e/e2e_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ async def test_get_reports_V2_200(self):
except json.JSONDecodeError:
self.fail("Response is not valid JSON")

async def test_list_exam(self):
async with httpx.AsyncClient() as client:
response = await client.get(
"http://127.0.0.1:8000/api/users/list")
if response.status_code == 307:
location = response.headers.get("Location")
response = await client.get(location)

data = response.text

if response.status_code != 200:
self.assertEqual(response.status_code, 404)
else:
try:
parsed_data = json.loads(data)
self.assertIsInstance(parsed_data, list)
self.assertTrue(len(parsed_data)>0)
except json.JSONDecodeError:
self.fail("Response is not valid JSON")

def test_start_get200_fail(self):
asyncio.run(self.test_get_reports_307_then_200_then_fail())

Expand All @@ -112,5 +132,8 @@ def test_start_get200(self):
def test_start_get200V2(self):
asyncio.run(self.test_get_reports_V2_200())

def test_start_exam_list(self):
asyncio.run(self.test_list_exam())

if __name__ == '__main__':
unittest.main()
34 changes: 34 additions & 0 deletions tests/integration/exam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest
from collections import defaultdict
from unittest.mock import patch
import asyncio

from functions.funcs import helper_function_exam, get_uuser_list_exam

class TestIntegration(unittest.TestCase):

@patch('functions.funcs.fetch')
def test_helper_func_fetch_empty(self, mock_fetch):
async def async_test():
mock_fetch.return_value = []
res = await helper_function_exam()

self.assertIsInstance(res, dict)
self.assertTrue(res == {"msg":"error"})

asyncio.run(async_test())

@patch('functions.funcs.helper_function_exam')
def test_exam_return_endpoint(self, mock_helper):
async def async_test():
mock_helper.return_value = "failure"

res = await get_uuser_list_exam()
self.assertIsInstance(res, dict)
self.assertTrue(res == {"err": "some error"})

asyncio.run(async_test())


if __name__ == '__main__':
unittest.main()

0 comments on commit ff42429

Please sign in to comment.