|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import pytest |
| 4 | +from selenium.webdriver.support.ui import Select |
| 5 | + |
| 6 | +from tests.extras.testutils.selenium import CountryWorkspaceSeleniumTC |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +def browser_program(browser, program): |
| 11 | + browser.login_as_user() |
| 12 | + browser.select_option_by_text("select[name=tenant]", program.country_office.name) |
| 13 | + browser.select2_select("id_program", program.name) |
| 14 | + browser.click_link("Programme") |
| 15 | + browser.click("#btn-import_file_updates") |
| 16 | + return browser |
| 17 | + |
| 18 | + |
| 19 | +def _test_import_file_mass_update_success(browser_program: CountryWorkspaceSeleniumTC, target: str): |
| 20 | + browser_program.assert_element_visible("#id_description") |
| 21 | + browser_program.assert_element_visible("#id_target") |
| 22 | + browser_program.assert_element_visible("#id_file") |
| 23 | + |
| 24 | + description_tex = "This is my dummy description" |
| 25 | + browser_program.fill("#id_description", description_tex) |
| 26 | + |
| 27 | + select_element = browser_program.find_element("#id_target") |
| 28 | + select = Select(select_element) |
| 29 | + select.select_by_value(target) |
| 30 | + |
| 31 | + file_path = f"{Path.cwd()}/tests/data/mass_update_hshld.xlsx" |
| 32 | + browser_program.find_element("#id_file").send_keys(file_path) |
| 33 | + browser_program.click('input[name="_import"]') |
| 34 | + |
| 35 | + assert browser_program.driver.current_url.endswith("/workspaces/countryasyncjob/") |
| 36 | + |
| 37 | + browser_program.wait_for_element("table#result_list", timeout=10) |
| 38 | + rows = browser_program.find_elements("table#result_list tbody tr") |
| 39 | + assert any(description_tex in row.text for row in rows) |
| 40 | + |
| 41 | + |
| 42 | +@pytest.mark.selenium |
| 43 | +def test_import_file_mass_update_households_success(browser_program: CountryWorkspaceSeleniumTC): |
| 44 | + _test_import_file_mass_update_success(browser_program=browser_program, target="hh") |
| 45 | + |
| 46 | + |
| 47 | +@pytest.mark.selenium |
| 48 | +def test_import_file_mass_update_individual_success(browser_program: CountryWorkspaceSeleniumTC): |
| 49 | + _test_import_file_mass_update_success(browser_program=browser_program, target="ind") |
| 50 | + |
| 51 | + |
| 52 | +@pytest.mark.selenium |
| 53 | +def test_import_file_mass_update_without_file_selection(browser_program): |
| 54 | + browser_program.assert_element_visible("#id_description") |
| 55 | + browser_program.assert_element_visible("#id_target") |
| 56 | + browser_program.assert_element_visible("#id_file") |
| 57 | + browser_program.click('input[name="_import"]') |
| 58 | + |
| 59 | + is_valid = browser_program.execute_script("return document.querySelector('#id_file').checkValidity();") |
| 60 | + assert not is_valid |
0 commit comments