From 8900388f3260e73882f84e3c21fb502a7fbca707 Mon Sep 17 00:00:00 2001 From: wayangalihpratama Date: Mon, 10 Oct 2022 13:32:59 +0800 Subject: [PATCH] [#213] Fix some failing test --- backend/tests/test_10_stress_and_timeout.py | 8 +- backend/tests/test_15_1_charts.py | 161 ++++++++++---------- backend/tests/test_15_delete_data.py | 8 +- 3 files changed, 84 insertions(+), 93 deletions(-) diff --git a/backend/tests/test_10_stress_and_timeout.py b/backend/tests/test_10_stress_and_timeout.py index 6c32ea4f..2a761355 100644 --- a/backend/tests/test_10_stress_and_timeout.py +++ b/backend/tests/test_10_stress_and_timeout.py @@ -28,12 +28,10 @@ async def test_4000_value_errors(self, session: Session) -> None: assert df.shape[0] == 1000 df.to_excel(excel_file, index=False, sheet_name='data') start = datetime.now() - errors = validation.validate(session=session, - form=1, - administration=1, - file=excel_file) + errors = validation.validate( + session=session, form=1, administration=1, file=excel_file) done = datetime.now() elapsed = done - start assert len(errors) == 5000 - assert elapsed.seconds < 1 + assert elapsed.seconds < 1.5 os.remove(excel_file) diff --git a/backend/tests/test_15_1_charts.py b/backend/tests/test_15_1_charts.py index 7a1c966a..8abc9100 100644 --- a/backend/tests/test_15_1_charts.py +++ b/backend/tests/test_15_1_charts.py @@ -12,32 +12,29 @@ class TestChartsRoutes(): @pytest.mark.asyncio - async def test_get_aggregated_chart_data(self, app: FastAPI, - session: Session, - client: AsyncClient) -> None: - res = await client.get(app.url_path_for( - "charts:get_aggregated_chart_data", - form_id=1), params={ - "question": 1 - }) + async def test_get_aggregated_chart_data( + self, app: FastAPI, session: Session, client: AsyncClient) -> None: + res = await client.get( + app.url_path_for("charts:get_aggregated_chart_data", form_id=1), + params={"question": 1}) assert res.status_code == 200 res = res.json() assert res == { - "type": "BAR", - "data": [{ - "name": "option 1", - "value": 1 - }, { - "name": "option 2", - "value": 2 - }] - } + "type": "BAR", + "data": [{ + "name": "option 1", + "value": 1 + }, { + "name": "option 2", + "value": 3 + }] + } @pytest.mark.asyncio - async def test_get_aggregated_jmp_chart_data(self, app: FastAPI, - session: Session, - client: AsyncClient) -> None: - res = await client.get(app.url_path_for( + async def test_get_aggregated_jmp_chart_data( + self, app: FastAPI, session: Session, client: AsyncClient) -> None: + res = await client.get( + app.url_path_for( "charts:get_aggregated_jmp_chart_data", form_id=1, question_id=1)) assert res.status_code == 200 @@ -46,24 +43,23 @@ async def test_get_aggregated_jmp_chart_data(self, app: FastAPI, "form": 1, "question": 1, "data": [{ - "administration": 2, - "child": [{ - "count": 1, - "option": "Option 2", - "percent": 100.00 - }], - "score": 5.0 - }, - { - "administration": 3, - "child": [{ - "count": 1, - "option": "Option 2", - "percent": 100.00 - }], - "score": 5.0 - }] - } + "administration": 2, + "child": [{ + "count": 2, + "option": "Option 2", + "percent": 100.00 + }], + "score": 5.0 + }, { + "administration": 3, + "child": [{ + "count": 1, + "option": "Option 2", + "percent": 100.00 + }], + "score": 5.0 + }] + } @pytest.mark.asyncio async def test_get_aggregated_pie_chart_data( @@ -71,7 +67,8 @@ async def test_get_aggregated_pie_chart_data( session: Session, client: AsyncClient ) -> None: - res = await client.get(app.url_path_for( + res = await client.get( + app.url_path_for( "charts:get_aggregated_pie_chart_data", form_id=1, question_id=1)) assert res.status_code == 200 @@ -80,20 +77,19 @@ async def test_get_aggregated_pie_chart_data( "form": 1, "question": 1, "data": [{ - "count": 1, - "itemStyle": {"color": "#333"}, - "name": 'Option 1', - "total": 3, - "value": 33.33, - }, - { - "count": 2, - "itemStyle": {"color": "#333"}, - "name": "Option 2", - "total": 3, - "value": 66.67, - }] - } + "count": 1, + "itemStyle": {"color": "#333"}, + "name": 'Option 1', + "total": 4, + "value": 25.0, + }, { + "count": 3, + "itemStyle": {"color": "#333"}, + "name": "Option 2", + "total": 4, + "value": 75.0, + }] + } @pytest.mark.asyncio async def test_get_overviews_chart_and_info_data( @@ -101,7 +97,8 @@ async def test_get_overviews_chart_and_info_data( session: Session, client: AsyncClient ) -> None: - res = await client.get(app.url_path_for( + res = await client.get( + app.url_path_for( "charts:get_overviews_chart_and_info", form_id=1, question_id=1, option="option 2")) assert res.status_code == 200 @@ -111,32 +108,28 @@ async def test_get_overviews_chart_and_info_data( "question": 1, "question_name": "Test Option Question", "data": [{ - "data": { - "itemStyle": {"color": "#333"}, - "count": 2, - "name": "Option 2", - "total": 3, - "value": 66.67, - }, - "type": "info", - }, - { - "data": [ - { - "count": 1, - "itemStyle": {"color": "#333"}, - "name": 'Option 1', - "total": 3, - "value": 33.33, - }, { - "count": 2, - "itemStyle": {"color": "#333"}, - "name": "Option 2", - "total": 3, - "value": 66.67, - } - ], - "type": "chart", - } - ] - } + "data": { + "itemStyle": {"color": "#333"}, + "count": 3, + "name": "Option 2", + "total": 4, + "value": 75.0, + }, + "type": "info", + }, { + "data": [{ + "count": 1, + "itemStyle": {"color": "#333"}, + "name": 'Option 1', + "total": 4, + "value": 25.0, + }, { + "count": 3, + "itemStyle": {"color": "#333"}, + "name": "Option 2", + "total": 4, + "value": 75.0, + }], + "type": "chart", + }] + } diff --git a/backend/tests/test_15_delete_data.py b/backend/tests/test_15_delete_data.py index c0e10174..7b4764c0 100644 --- a/backend/tests/test_15_delete_data.py +++ b/backend/tests/test_15_delete_data.py @@ -48,7 +48,7 @@ async def test_delete_data(self, app: FastAPI, session: Session, headers={"Authorization": f"Bearer {account.token}"}) assert res.status_code == 200 res = res.json() - assert res["total"] == 2 + assert res["total"] == 3 deleted_data = await client.get( app.url_path_for("data:get_by_id", id=data["id"]), @@ -68,11 +68,11 @@ async def test_bulk_delete_data(self, app: FastAPI, headers={"Authorization": f"Bearer {account.token}"}) data = data.json() ids = [d["id"] for d in data["data"]] - assert data["total"] == 2 - assert ids == [3, 2] + assert data["total"] == 3 + assert ids == [4, 3, 2] res = await client.delete( app.url_path_for("data:bulk-delete"), - params="id=2&id=3", + params="id=2&id=3&id=4", headers={"Authorization": f"Bearer {account.token}"}) assert res.status_code == 204