Skip to content

Commit

Permalink
[#213] Fix some failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Oct 10, 2022
1 parent 716c671 commit 8900388
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 93 deletions.
8 changes: 3 additions & 5 deletions backend/tests/test_10_stress_and_timeout.py
Expand Up @@ -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)
161 changes: 77 additions & 84 deletions backend/tests/test_15_1_charts.py
Expand Up @@ -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
Expand All @@ -46,32 +43,32 @@ 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(
self, app: FastAPI,
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
Expand All @@ -80,28 +77,28 @@ 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(
self, app: FastAPI,
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
Expand All @@ -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",
}]
}
8 changes: 4 additions & 4 deletions backend/tests/test_15_delete_data.py
Expand Up @@ -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"]),
Expand All @@ -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

Expand Down

0 comments on commit 8900388

Please sign in to comment.