Skip to content
Prev Previous commit
Next Next commit
fixed asyncio test
  • Loading branch information
orronai committed Oct 15, 2021
commit 1fb34b9fc83211cd5f827fc12cc78c0abdc3ec12
8 changes: 5 additions & 3 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest.mock import Mock, patch

from flask.testing import FlaskClient
import pytest
from werkzeug.datastructures import FileStorage

from lms.lmsdb.models import Course, User
Expand Down Expand Up @@ -244,12 +245,13 @@ def teardown(self):
def open_file(filename: str) -> BufferedReader:
return open(Path(conftest.SAMPLES_DIR) / filename, 'br')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do it with fixture: use file_handler = open(...), then yield file_handler and finally file_handler.close it


def test_upload_avatar(self, student_user: User, captured_templates):
@pytest.mark.asyncio
async def test_upload_avatar(self, student_user: User, captured_templates):
client = conftest.get_logged_user(student_user.username)
conftest.upload_avatar(client, self.image_storage)
await conftest.upload_avatar(client, self.image_storage)
template, _ = captured_templates[-1]
assert template.name == "user.html"
conftest.upload_avatar(client, self.image_storage_2)
await conftest.upload_avatar(client, self.image_storage_2)
client.get('/avatar/delete')
template, _ = captured_templates[-1]
assert template.name == "user.html"
Expand Down