Get list of filenames in File Garden
This commit is contained in:
parent
a60ca8eb52
commit
68d37afec7
23
jardin.py
23
jardin.py
|
@ -2,9 +2,12 @@
|
|||
|
||||
import sys
|
||||
|
||||
import bs4
|
||||
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
from selenium.webdriver.common.action_chains import ActionChains
|
||||
|
||||
def initialize_webdriver():
|
||||
return webdriver.Firefox()
|
||||
|
@ -31,15 +34,29 @@ def login_with_password(browser, email, password):
|
|||
click_password_button(browser)
|
||||
input_password(browser, password)
|
||||
|
||||
def click_go_to_your_garden(browser):
|
||||
browser.implicitly_wait(100)
|
||||
goToYourGardenButton = browser.find_element(By.LINK_TEXT, "GO TO YOUR GARDEN")
|
||||
goToYourGardenButton.click()
|
||||
|
||||
def get_garden_filenames(browser):
|
||||
titles = []
|
||||
soup = bs4.BeautifulSoup(browser.page_source, "lxml")
|
||||
|
||||
for item in soup.find_all(attrs={"class": "name"}):
|
||||
titles.append(item.text)
|
||||
|
||||
return titles
|
||||
|
||||
def main(email, password):
|
||||
browser = initialize_webdriver()
|
||||
navigate_to_filegarden(browser)
|
||||
login_with_password(browser, email, password)
|
||||
# Go To Your Garden
|
||||
# Get list of filenames in File Garden
|
||||
click_go_to_your_garden(browser)
|
||||
garden_filenames = get_garden_filenames(browser)
|
||||
# Get list of files in target upload directory that don't exist in File Garden (test based on filename? size? file contents?)
|
||||
# For each file in the second list, go through the file upload process
|
||||
browser.close()
|
||||
#browser.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1], sys.argv[2])
|
||||
|
|
|
@ -66,10 +66,62 @@ class TestJardin(unittest.TestCase):
|
|||
mockClickPasswordButton.assert_called_once_with(mockFirefox)
|
||||
mockInputPassword.assert_called_once_with(mockFirefox, mockPassword)
|
||||
|
||||
@patch("jardin.webdriver.Firefox")
|
||||
def test_click_go_to_your_garden_clicks_button(self, mockFirefox):
|
||||
jardin.click_go_to_your_garden(mockFirefox)
|
||||
|
||||
mockFirefox.find_element.assert_called_with(By.LINK_TEXT, "GO TO YOUR GARDEN")
|
||||
mockFirefox.find_element.return_value.click.assert_called_once()
|
||||
|
||||
@patch("jardin.webdriver.Firefox")
|
||||
@patch("jardin.bs4.BeautifulSoup")
|
||||
def test_get_garden_filenames_creates_beautifulsoup_and_finds_names(self, mockBeautifulSoup, mockFirefox):
|
||||
jardin.get_garden_filenames(mockFirefox)
|
||||
|
||||
mockBeautifulSoup.assert_called_once_with(mockFirefox.page_source, "lxml")
|
||||
mockBeautifulSoup.return_value.find_all.assert_called_once_with(attrs={"class": "name"})
|
||||
|
||||
@patch("jardin.webdriver.Firefox")
|
||||
def test_get_garden_filenames_returns_filenames_correctly(self, mockFirefox):
|
||||
mockFirefox.page_source = """
|
||||
<html lang="en">
|
||||
<body class="mdc-typography">
|
||||
<div id="items" class="items">
|
||||
<a class="item typeFile selected" draggable="false" ondragstart="return false;" href="https://file.garden/fakeid/file1.jpg">
|
||||
<div class="cell icon">
|
||||
<button class="mdc-icon-button material-icons" type="button">image</button>
|
||||
</div>
|
||||
<div class="cell name" title="file1.jpg">file1.jpg</div>
|
||||
<div class="cell size" title="10 B">10 B</div>
|
||||
<div class="cell type" title="image/jpeg">image/jpeg</div>
|
||||
<div class="cell date" title="Wed Aug 30 2023 13:04:10 GMT+0100 (British Summer Time)">Aug 30 2023 13:04:10</div>
|
||||
</a>
|
||||
<a class="item typeFile" draggable="false" ondragstart="return false;" href="https://file.garden/fakeid/file2.jpg">
|
||||
<div class="cell icon">
|
||||
<button class="mdc-icon-button material-icons" type="button">image</button>
|
||||
</div>
|
||||
<div class="cell name" title="file2.jpg">file2.jpg</div>
|
||||
<div class="cell size" title="20 B">20 B</div>
|
||||
<div class="cell type" title="image/jpeg">image/jpeg</div>
|
||||
<div class="cell date" title="Wed Jun 29 2022 17:37:14 GMT+0100 (British Summer Time)">Jun 29 2022 17:37:14</div>
|
||||
</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
filenames = jardin.get_garden_filenames(mockFirefox)
|
||||
|
||||
self.assertEqual(filenames, ["file1.jpg", "file2.jpg"])
|
||||
|
||||
@patch("jardin.initialize_webdriver")
|
||||
@patch("jardin.navigate_to_filegarden")
|
||||
@patch("jardin.login_with_password")
|
||||
@patch("jardin.click_go_to_your_garden")
|
||||
@patch("jardin.get_garden_filenames")
|
||||
def test_main_calls_methods_in_correct_order(self,
|
||||
mockGetGardenFilenames,
|
||||
mockClickGoToYourGarden,
|
||||
mockLoginWithPassword,
|
||||
mockNavigateToFilegarden,
|
||||
mockInitializeWebdriver):
|
||||
|
@ -81,8 +133,10 @@ class TestJardin(unittest.TestCase):
|
|||
mockInitializeWebdriver.assert_called_once()
|
||||
mockNavigateToFilegarden.assert_called_once_with(mockInitializeWebdriver.return_value)
|
||||
mockLoginWithPassword.assert_called_once_with(mockInitializeWebdriver.return_value, mockEmail, mockPassword)
|
||||
mockClickGoToYourGarden.assert_called_once_with(mockInitializeWebdriver.return_value)
|
||||
mockGetGardenFilenames.assert_called_once_with(mockInitializeWebdriver.return_value)
|
||||
|
||||
mockInitializeWebdriver.return_value.close.assert_called_once()
|
||||
#mockInitializeWebdriver.return_value.close.assert_called_once()
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue