2022-07-03 15:01:21 +02:00
|
|
|
from selenium.webdriver.common.by import By
|
|
|
|
|
2022-03-23 12:36:41 +01:00
|
|
|
from .utils import TEST_URL, login_valid_user, register_valid_user_and_logout
|
2020-09-13 21:39:44 +02:00
|
|
|
|
|
|
|
URL = f'{TEST_URL}/login'
|
|
|
|
|
|
|
|
|
|
|
|
class TestLogin:
|
|
|
|
def test_navbar_contains_login(self, selenium):
|
|
|
|
selenium.get(URL)
|
|
|
|
|
2022-07-03 15:01:21 +02:00
|
|
|
nav = selenium.find_element(By.ID, 'nav').text
|
2020-09-13 21:39:44 +02:00
|
|
|
assert 'Login' in nav
|
|
|
|
|
|
|
|
def test_it_displays_login_form(self, selenium):
|
|
|
|
selenium.get(URL)
|
|
|
|
|
2022-07-03 15:01:21 +02:00
|
|
|
inputs = selenium.find_elements(By.TAG_NAME, 'input')
|
2021-10-31 21:04:47 +01:00
|
|
|
assert len(inputs) == 2
|
|
|
|
assert inputs[0].get_attribute('id') == 'email'
|
2020-09-13 21:39:44 +02:00
|
|
|
assert inputs[0].get_attribute('type') == 'email'
|
2021-10-31 21:04:47 +01:00
|
|
|
assert inputs[1].get_attribute('id') == 'password'
|
2020-09-13 21:39:44 +02:00
|
|
|
assert inputs[1].get_attribute('type') == 'password'
|
2021-10-31 21:04:47 +01:00
|
|
|
|
2023-07-13 21:49:27 +02:00
|
|
|
button = selenium.find_elements(By.TAG_NAME, 'button')[-1]
|
2021-10-31 21:04:47 +01:00
|
|
|
assert button.get_attribute('type') == 'submit'
|
|
|
|
assert 'Log in' in button.text
|
|
|
|
|
2022-07-03 15:01:21 +02:00
|
|
|
links = selenium.find_elements(By.CLASS_NAME, 'links')
|
2021-11-06 23:16:19 +01:00
|
|
|
assert links[0].tag_name == 'a'
|
|
|
|
assert 'Register' in links[0].text
|
|
|
|
assert links[1].tag_name == 'a'
|
|
|
|
assert 'Forgot password?' in links[1].text
|
2022-03-23 12:36:41 +01:00
|
|
|
assert links[2].tag_name == 'a'
|
|
|
|
assert "Didn't received instructions?" in links[2].text
|
2020-09-13 21:39:44 +02:00
|
|
|
|
|
|
|
def test_user_can_log_in(self, selenium):
|
2022-02-12 16:31:29 +01:00
|
|
|
user = register_valid_user_and_logout(selenium)
|
2020-09-13 21:39:44 +02:00
|
|
|
|
|
|
|
login_valid_user(selenium, user)
|
|
|
|
|
2022-07-03 15:01:21 +02:00
|
|
|
nav = selenium.find_element(By.ID, 'nav').text
|
2022-03-23 12:36:41 +01:00
|
|
|
assert 'Register' not in nav
|
|
|
|
assert 'Login' not in nav
|
|
|
|
assert 'Dashboard' in nav
|
|
|
|
assert 'Workouts' in nav
|
|
|
|
assert 'Statistics' in nav
|
|
|
|
assert 'Add a workout' in nav
|
|
|
|
assert user['username'] in nav
|
2023-07-13 21:49:27 +02:00
|
|
|
logout_button = selenium.find_elements(By.CLASS_NAME, 'logout-button')[
|
|
|
|
0
|
|
|
|
]
|
|
|
|
assert logout_button
|