rlt_salary/TestAggregateSalaries.py

40 lines
1.4 KiB
Python
Raw Permalink Normal View History

2024-02-27 20:47:59 +01:00
import json
import unittest
from app import aggregate_salaries, MongoDB, Settings
settings = Settings()
with open(r'tests\samples.json', 'r') as f:
data = json.load(f)
class TestAggregateSalaries(unittest.IsolatedAsyncioTestCase):
async def async_test(self, json_in, json_out, collection):
result = await aggregate_salaries(collection, **json_in)
self.assertEqual(json_out, result)
async def test_month(self):
client = MongoDB(str(settings.DB_URI))
db = client.client[settings.DATABASE_NAME]
collection = db[settings.COLLECTION_NAME]
json_in = data['month']['in']
json_out = data['month']['out']
await self.async_test(json_in, json_out, collection)
async def test_day(self):
client = MongoDB(str(settings.DB_URI))
db = client.client[settings.DATABASE_NAME]
collection = db[settings.COLLECTION_NAME]
json_in = data['day']['in']
json_out = data['day']['out']
await self.async_test(json_in, json_out, collection)
async def test_hour(self):
client = MongoDB(str(settings.DB_URI))
db = client.client[settings.DATABASE_NAME]
collection = db[settings.COLLECTION_NAME]
json_in = data['hour']['in']
json_out = data['hour']['out']
await self.async_test(json_in, json_out, collection)
if __name__ == '__main__':
unittest.main()