added tests for opening and closing the door via button
This commit is contained in:
parent
bb022fd1ce
commit
ba9379449a
|
@ -43,6 +43,7 @@ dev =
|
|||
pytest
|
||||
pytest-cov
|
||||
pytest-flask
|
||||
pytest-mock
|
||||
flake8
|
||||
selenium
|
||||
beautifulsoup4
|
|
@ -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)
|
||||
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')
|
Loading…
Reference in New Issue
Block a user