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
|
||||||
pytest-cov
|
pytest-cov
|
||||||
pytest-flask
|
pytest-flask
|
||||||
|
pytest-mock
|
||||||
flake8
|
flake8
|
||||||
selenium
|
selenium
|
||||||
beautifulsoup4
|
beautifulsoup4
|
|
@ -1,4 +1,5 @@
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
from imaginaerraum_door_admin.door_handle import DoorHandle
|
||||||
|
|
||||||
def test_login(browser, live_server):
|
def test_login(browser, live_server):
|
||||||
response = browser.get(f'http://localhost:{live_server.port}')
|
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
|
assert 'Tür öffnen' in browser.page_source
|
||||||
|
|
||||||
|
|
||||||
def login(client, payload):
|
def headless_login(client):
|
||||||
return client.post('/login', data=payload, follow_redirects=True)
|
|
||||||
|
|
||||||
def test_login_headless(client):
|
|
||||||
# extract csrf token from the login page source
|
# extract csrf token from the login page source
|
||||||
response = client.get('/login')
|
response = client.get('/login')
|
||||||
soup = BeautifulSoup(response.data)
|
soup = BeautifulSoup(response.data)
|
||||||
|
@ -29,11 +27,35 @@ def test_login_headless(client):
|
||||||
'email': 'gandalf@shire.me',
|
'email': 'gandalf@shire.me',
|
||||||
'password': 'shadowfax'
|
'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)
|
soup = BeautifulSoup(response.data)
|
||||||
|
|
||||||
# make sure login succeeded -> Tür öffnen button will appear
|
# 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'})])
|
assert any(['Tür öffnen' in link.contents[0] for link in soup.findAll('a', attrs={'class': ['btn'], 'role': 'button'})])
|
||||||
|
|
||||||
def logout(client):
|
def test_open_door_button(client, mocker):
|
||||||
return client.get('/logout', follow_redirects=True)
|
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