diff --git a/tests/base.py b/tests/base.py index c799bc2ad6..ed4892a092 100644 --- a/tests/base.py +++ b/tests/base.py @@ -62,6 +62,7 @@ class ApiTestCase(unittest.TestCase): """ Set of helpers to make test development easier. """ + @classmethod def setUpClass(cls): pass @@ -82,6 +83,7 @@ def setUp(self): app.app_context().push() from zou.app.utils import cache + cache.clear() def tearDown(self): @@ -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): """ @@ -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() @@ -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. @@ -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() diff --git a/tests/chats/test_chat_routes.py b/tests/chats/test_chat_routes.py index 09edc62ff2..d66603d5bd 100644 --- a/tests/chats/test_chat_routes.py +++ b/tests/chats/test_chat_routes.py @@ -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() @@ -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"), @@ -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()