diff --git a/setup.cfg b/setup.cfg index e1d02df..f9a1c46 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,6 +43,7 @@ dev = pytest pytest-cov pytest-flask + pytest-mock flake8 selenium beautifulsoup4 \ No newline at end of file diff --git a/tests/test_webinterface.py b/tests/test_webinterface.py index 27aa54f..3467844 100644 --- a/tests/test_webinterface.py +++ b/tests/test_webinterface.py @@ -1,4 +1,5 @@ from bs4 import BeautifulSoup +from imaginaerraum_door_admin.door_handle import DoorHandle def test_login(browser, live_server): response = browser.get(f'http://localhost:{live_server.port}') @@ -14,10 +15,7 @@ def test_login(browser, live_server): assert 'Tür öffnen' in browser.page_source -def login(client, payload): - return client.post('/login', data=payload, follow_redirects=True) - -def test_login_headless(client): +def headless_login(client): # extract csrf token from the login page source response = client.get('/login') soup = BeautifulSoup(response.data) @@ -29,11 +27,35 @@ def test_login_headless(client): 'email': 'gandalf@shire.me', 'password': 'shadowfax' } - response = login(client, payload) + return client.post('/login', data=payload, follow_redirects=True) + +def test_login_headless(client): + response = headless_login(client) soup = BeautifulSoup(response.data) # make sure login succeeded -> Tür öffnen button will appear assert any(['Tür öffnen' in link.contents[0] for link in soup.findAll('a', attrs={'class': ['btn'], 'role': 'button'})]) -def logout(client): - return client.get('/logout', follow_redirects=True) \ No newline at end of file +def test_open_door_button(client, mocker): + mocker.patch('imaginaerraum_door_admin.door_handle.DoorHandle.open_door') + + # we need to log in in order to open the door + response = headless_login(client) + + # visit route for open + client.get('/open') + + # make sure the open method was called + DoorHandle.open_door.assert_called_once_with(user='gandalf') + +def test_close_door_button(client, mocker): + mocker.patch('imaginaerraum_door_admin.door_handle.DoorHandle.close_door') + + # we need to log in in order to open the door + response = headless_login(client) + + # visit route for open + client.get('/close') + + # make sure the open method was called + DoorHandle.close_door.assert_called_once_with(user='gandalf') \ No newline at end of file