Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
McSinyx committed Jan 20, 2021
1 parent 016a853 commit 66e05be
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Custom `ipfs.toml` must define the following keys,
whose default values are listed as follows:

```toml
[api]
base = 'http://127.0.0.1:5001/api/v0'

[gateway]
base = 'http://127.0.0.1:8080/ipfs'
fallback = 'https://ipfs.io'
Expand Down
6 changes: 3 additions & 3 deletions src/acanban/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def edit(uuid: str) -> ResponseReturnValue:
async def report(uuid: str) -> ResponseReturnValue:
"""Return the projects' report infomation and forms."""
user = await current_user.pluck('projects', 'role')
project = await pluck(uuid, ('id', 'name', 'report'), user['projects'])
project = await pluck(uuid, ('id', 'name', 'report'), user.get('projects'))
query = r.table('files').get_all(*project['report']['revisions'])
async with current_app.db_pool.connection() as conn:
revisions = [file async for file in await query.run(conn)]
Expand All @@ -134,7 +134,7 @@ async def report(uuid: str) -> ResponseReturnValue:
async def report_upload(uuid: str) -> ResponseReturnValue:
"""Handle report upload."""
user = await current_user.pluck('role', 'projects')
await pluck(uuid, projects=user['projects'])
await pluck(uuid, projects=user.get('projects'))
if user['role'] != 'student': raise Unauthorized
action = r.row['report']['revisions'].append(await ipfs_add())
async with current_app.db_pool.connection() as conn:
Expand All @@ -148,7 +148,7 @@ async def report_upload(uuid: str) -> ResponseReturnValue:
async def report_eval(uuid: str) -> ResponseReturnValue:
"""Handle report evaluation."""
user = await current_user.pluck('role', 'projects')
await pluck(uuid, projects=user['projects'])
await pluck(uuid, projects=user.get('projects'))
if user['role'] == 'student': raise Unauthorized
form = await request.form
updated = {'grade': float(form['grade']), 'comment': form['comment']}
Expand Down
10 changes: 4 additions & 6 deletions src/acanban/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ async def view_user_profile(username: str) -> ResponseReturnValue:
if user is None:
raise NotFound
project_uuids = user.get('projects', None)
if project_uuids is not None:
project_list = r.table('projects').get_all(*project_uuids)
projects = await project_list.run(conn)
return await render_template(
'user.html', user=user, projects=projects)
else:
if project_uuids is None:
return await render_template('user.html', user=user)
project_list = r.table('projects').get_all(*project_uuids)
projects = await project_list.run(conn)
return await render_template('user.html', user=user, projects=projects)


@blueprint.route('/<username>/edit', methods=['GET', 'POST'])
Expand Down
6 changes: 4 additions & 2 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
from http import HTTPStatus as Status

from conftest import ClientFactory, parametrize
from pytest import param
from quart.testing import QuartClient


@parametrize(('username', 'status_code'),
(('nexistepas', Status.NOT_FOUND),
('silasl', Status.OK)))
(param('nexistepas', Status.NOT_FOUND, id='not exist'),
param('adaml', Status.OK, id='can have projects'),
param('silasl', Status.OK, id='cannot have projects')))
async def test_get(username: str, status_code: int,
client: QuartClient) -> None:
"""Test GET user root endpoint."""
Expand Down

0 comments on commit 66e05be

Please sign in to comment.