Refactor login code

This commit is contained in:
The Magician 2023-10-20 12:32:48 +01:00
parent cdd48e43dc
commit bae05021b7
2 changed files with 17 additions and 5 deletions

View File

@ -10,11 +10,14 @@ def initialize_webdriver():
def navigate_to_filegarden(browser):
browser.get("https://filegarden.com/login")
def login_with_password(browser, email, password):
def input_email(browser, email):
emailInput = browser.find_element(By.ID, "email")
emailInput.send_keys(email)
emailInput.send_keys(Keys.RETURN)
def login_with_password(browser, email, password):
input_email(browser, email)
def main():
with initialize_webdriver() as browser:
navigate_to_filegarden(browser)

View File

@ -22,11 +22,10 @@ class TestJardin(unittest.TestCase):
mockFirefox.get.assert_called_once_with("https://filegarden.com/login")
@patch("jardin.webdriver.Firefox")
def test_login_with_password_performs_login_steps(self, mockFirefox):
def test_input_email_enters_email_correctly(self, mockFirefox):
mockEmail = "email@mail.com"
mockPassword = "p4$$w0rd"
jardin.login_with_password(mockFirefox, mockEmail, mockPassword)
jardin.input_email(mockFirefox, mockEmail)
mockFirefox.find_element.assert_called_with(By.ID, "email")
mockFirefox.find_element.return_value.send_keys.assert_has_calls([
@ -34,6 +33,16 @@ class TestJardin(unittest.TestCase):
call(Keys.RETURN)
])
@patch("jardin.webdriver.Firefox")
@patch("jardin.input_email")
def test_login_with_password_performs_login_steps(self, mockInputEmail, mockFirefox):
mockEmail = "email@mail.com"
mockPassword = "p4$$w0rd"
jardin.login_with_password(mockFirefox, mockEmail, mockPassword)
mockInputEmail.assert_called_once_with(mockFirefox, mockEmail)
@patch("jardin.initialize_webdriver")
@patch("jardin.navigate_to_filegarden")
def test_main_calls_methods_in_correct_order(self,