diff --git a/tests/unit/database_test.py b/tests/unit/database_test.py index c109649..fc23d95 100644 --- a/tests/unit/database_test.py +++ b/tests/unit/database_test.py @@ -13,7 +13,8 @@ @pytest.mark.generate def test_generate(): sys.argv.extend(('generate', '--fast', '--minimal')) - runpy.run_path('../desktop_shop/database.py', run_name='__main__') + path = os.path.join(os.path.dirname(__file__), '..', '..', 'desktop_shop', 'database.py') + runpy.run_path(path) def teardown(): while len(sys.argv) > 1: diff --git a/tests/unit/gui/init_test.py b/tests/unit/gui/init_test.py index 158d4e6..a3c4e6e 100644 --- a/tests/unit/gui/init_test.py +++ b/tests/unit/gui/init_test.py @@ -4,19 +4,29 @@ import sys from collections import namedtuple -import desktop_shop.gui.init as init -import desktop_shop.server as server +from desktop_shop import server, database import pytest -from desktop_shop import gui -from desktop_shop.gui.views import views Product = namedtuple("Product", ["id", "name", "price"]) -def test_gui_init(): +def test_gui_init(monkeypatch): if sys.platform.startswith('linux') and os.environ.get('DISPLAY') is None: # FIXME pytest.skip('Tkinter cannot be initialised on headless server') + from desktop_shop import gui + from desktop_shop.gui import init + from desktop_shop.gui.views import views + + Product = namedtuple("Product", ["id", "name", "price"]) + def fake_products_query(*_, **__): + return [ + Product(0, "a", 1000), + Product(1, "b", 1000), + Product(2, "c", 1000), + ] + + monkeypatch.setattr(database, "query_product_data_from_product_table", fake_products_query) init.init() for view in gui.app.views_dict.values(): view.pack() @@ -26,6 +36,8 @@ def test_checkout_view(): if sys.platform.startswith('linux') and os.environ.get('DISPLAY') is None: # FIXME pytest.skip('Tkinter cannot be initialised on headless server') + from desktop_shop import gui + class MonkeyPatch: def __enter__(self): self.func = server.query_product_data_from_product_table_by_product_ids