From 819f8cd92fb6c172afd9c1b5a7270457308a997d Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 20 Oct 2023 12:25:19 +0100 Subject: [PATCH] Start adding login method --- jardin.py | 7 +++++++ test_jardin.py | 22 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/jardin.py b/jardin.py index 5462b77..c1e61ef 100755 --- a/jardin.py +++ b/jardin.py @@ -1,6 +1,8 @@ #!/usr/bin/python3 from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys def initialize_webdriver(): return webdriver.Firefox() @@ -8,6 +10,11 @@ def initialize_webdriver(): def navigate_to_filegarden(browser): browser.get("https://filegarden.com/login") +def login_with_password(browser, email, password): + emailInput = browser.find_element(By.ID, "email") + emailInput.send_keys(email) + emailInput.send_keys(Keys.RETURN) + def main(): with initialize_webdriver() as browser: navigate_to_filegarden(browser) diff --git a/test_jardin.py b/test_jardin.py index a8b7f1d..080c6a6 100755 --- a/test_jardin.py +++ b/test_jardin.py @@ -1,23 +1,39 @@ #!/usr/bin/python3 import unittest -from unittest.mock import patch +from unittest.mock import patch, call + +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys import jardin class TestJardin(unittest.TestCase): - @patch("selenium.webdriver.Firefox") + @patch("jardin.webdriver.Firefox") def test_initialize_webdriver_calls_Firefox(self, mockFirefox): jardin.initialize_webdriver() mockFirefox.assert_called_once() - @patch("selenium.webdriver.Firefox") + @patch("jardin.webdriver.Firefox") def test_navigate_to_filegarden(self, mockFirefox): jardin.navigate_to_filegarden(mockFirefox) mockFirefox.get.assert_called_once_with("https://filegarden.com/login") + @patch("jardin.webdriver.Firefox") + def test_login_with_password_performs_login_steps(self, mockFirefox): + mockEmail = "email@mail.com" + mockPassword = "p4$$w0rd" + + jardin.login_with_password(mockFirefox, mockEmail, mockPassword) + + 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.initialize_webdriver") @patch("jardin.navigate_to_filegarden") def test_main_calls_methods_in_correct_order(self,