Skip to content

Commit

Permalink
Fix database and gui init tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rbaltrusch committed Jun 16, 2022
1 parent 098ee49 commit 986d106
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tests/unit/database_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 17 additions & 5 deletions tests/unit/gui/init_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit 986d106

Please sign in to comment.