Skip to content

Commit

Permalink
[ci] fix tests/chats/test_chat_routes.py::EventsRoutesTestCase::test_…
Browse files Browse the repository at this point in the history
…post_chat_message_with_attachment
  • Loading branch information
EvanBldy committed Nov 13, 2024
1 parent 9039328 commit cdb71bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
22 changes: 16 additions & 6 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ApiTestCase(unittest.TestCase):
"""
Set of helpers to make test development easier.
"""

@classmethod
def setUpClass(cls):
pass
Expand All @@ -82,6 +83,7 @@ def setUp(self):
app.app_context().push()

from zou.app.utils import cache

cache.clear()

def tearDown(self):
Expand Down Expand Up @@ -233,11 +235,11 @@ def download_file(self, path, target_file_path, code=200):
return open(target_file_path, "rb").read()



class ApiDBTestCase(ApiTestCase):
"""
Set of helpers for Api tests.
"""

@classmethod
def setUpClass(cls):
"""
Expand All @@ -246,6 +248,7 @@ def setUpClass(cls):
"""
super(ApiDBTestCase, cls).setUpClass()
from zou.app.utils import dbhelpers

with app.app_context():
dbhelpers.drop_all()
dbhelpers.create_all()
Expand All @@ -258,10 +261,11 @@ def tearDownClass(cls):
"""
super(ApiDBTestCase, cls).tearDownClass()
from zou.app.utils import dbhelpers

with app.app_context():
dbhelpers.drop_all()
def setUp(self):

def setUp(self, expire_on_commit=True):
"""
Configure application before each test.
set up database transaction.
Expand All @@ -270,9 +274,15 @@ def setUp(self):

self._db_connection = db.engine.connect()
self._db_transaction = self._db_connection.begin()
factory = sessionmaker(bind=self._db_connection, binds={})
self._db_session = scoped_session(factory, current_app._get_current_object)
db.session = self._db_session
factory = sessionmaker(
bind=self._db_connection,
binds={},
expire_on_commit=expire_on_commit,
)
self._db_session = scoped_session(
factory, current_app._get_current_object
)
db.session = self._db_session

self.generate_fixture_user()
self.log_in_admin()
Expand Down
10 changes: 7 additions & 3 deletions tests/chats/test_chat_routes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import os

from tests.base import ApiDBTestCase

from zou.app.services import chats_service
from zou.app.stores import file_store
from zou.app.utils import thumbnail


class EventsRoutesTestCase(ApiDBTestCase):
def setUp(self):
super(EventsRoutesTestCase, self).setUp()
super(EventsRoutesTestCase, self).setUp(expire_on_commit=False)

self.generate_fixture_project_status()
self.generate_fixture_project()
Expand Down Expand Up @@ -63,7 +67,7 @@ def test_get_chat_message(self):
)
self.assertEqual(message["id"], chat_message["id"])

""" def test_post_chat_message_with_attachment(self):
def test_post_chat_message_with_attachment(self):
self.post(f"/actions/user/chats/{self.asset.id}/join", {}, 200)
file_path_fixture = self.get_fixture_file_path(
os.path.join("thumbnails", "th01.png"),
Expand All @@ -81,7 +85,7 @@ def test_get_chat_message(self):
size = thumbnail.get_dimensions(
file_store.get_local_picture_path("thumbnails", attachment_id)
)
self.assertEqual(size, (150, 150)) """
self.assertEqual(size, (150, 150))

def test_delete_chat_message(self):
chat_message = self.generate_fixture_chat_message()
Expand Down

0 comments on commit cdb71bc

Please sign in to comment.