Refactor login code
This commit is contained in:
parent
cdd48e43dc
commit
bae05021b7
|
@ -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)
|
||||
|
|
|
@ -22,17 +22,26 @@ 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([
|
||||
call(mockEmail),
|
||||
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")
|
||||
|
|
Loading…
Reference in New Issue