streamlined tests and added test for trying to access the door without authentication

This commit is contained in:
Simon Pirkelmann 2022-01-30 18:49:09 +01:00
parent 2879a69445
commit ee6ee0e111

View File

@ -52,25 +52,30 @@ def client_authenticated(client):
yield client yield client
@pytest.mark.parametrize("url,function", [('/open', 'open_door'), ('/close', 'close_door')])
def test_open_door_button(client_authenticated, mocker): def test_access_door_button(client_authenticated, mocker, url, function):
mocker.patch('imaginaerraum_door_admin.door_handle.DoorHandle.open_door') mocker.patch('imaginaerraum_door_admin.door_handle.DoorHandle.' + function)
# visit route for open # visit route for open
client_authenticated.get('/open') client_authenticated.get(url)
# make sure the open method was called # make sure the open method was called
DoorHandle.open_door.assert_called_once_with(user='gandalf') getattr(DoorHandle, function).assert_called_once_with(user='gandalf')
def test_close_door_button(client_authenticated, mocker): @pytest.mark.parametrize("url,function", [('/open', 'open_door'), ('/close', 'close_door')])
mocker.patch('imaginaerraum_door_admin.door_handle.DoorHandle.close_door') def test_access_door_unauthenticated(client, mocker, url, function):
# test for trying to visit opening/closing door while not logged in
mocker.patch('imaginaerraum_door_admin.door_handle.DoorHandle.' + function)
# visit route for open # visit route for open
client_authenticated.get('/close') response = client.get(url, follow_redirects=True)
# make sure the open method was called # we should get redirected to login page
DoorHandle.close_door.assert_called_once_with(user='gandalf') assert 'login' in response.request.url
# the open door function should not be called
getattr(DoorHandle, function).assert_not_called()
def test_manage_admins(client_authenticated): def test_manage_admins(client_authenticated):