|
1 | 1 | from typing import TYPE_CHECKING |
| 2 | +from unittest.mock import patch |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 | from django.core.management import call_command |
5 | 6 | from testutils.factories import OfficeFactory |
6 | 7 | from testutils.factories.program import BeneficiaryGroupFactory |
7 | 8 | from testutils.factories import CountryProgramFactory |
8 | 9 |
|
| 10 | +from tests.extras.testutils.selenium import CountryWorkspaceSeleniumTC |
| 11 | + |
9 | 12 | if TYPE_CHECKING: |
10 | 13 | from country_workspace.workspaces.models import CountryHousehold |
11 | 14 |
|
@@ -79,3 +82,40 @@ def test_list_household_select_all_fields(browser, household: "CountryHousehold" |
79 | 82 | checkboxes = browser.find_elements('input[type="checkbox"][name="fields"]') |
80 | 83 | for cb in checkboxes: |
81 | 84 | assert cb.is_selected() |
| 85 | + |
| 86 | + |
| 87 | +def _test_export_generation(browser: CountryWorkspaceSeleniumTC, household: "CountryHousehold", link: str): |
| 88 | + browser.login_as_user() |
| 89 | + browser.select_option_by_text("select[name=tenant]", household.program.country_office.name) |
| 90 | + browser.select2_select("id_program", household.program.name) |
| 91 | + browser.click_link(link) |
| 92 | + |
| 93 | + browser.click("#action-toggle") |
| 94 | + browser.select_option_by_text("select[name=action]", "Export records as .xlsx for bulk updates") |
| 95 | + |
| 96 | + browser.click("button[name='index'][value='0']") |
| 97 | + browser.click("#select-all") |
| 98 | + browser.click("input[name='_export']") |
| 99 | + |
| 100 | + browser.click('//a[div[text()="Async Jobs"]]') |
| 101 | + browser.wait_for_element("table#result_list", timeout=10) |
| 102 | + rows = browser.find_elements("table#result_list tbody tr") |
| 103 | + assert any("Export records as .xlsx for bulk updates" in row.text for row in rows) |
| 104 | + |
| 105 | + |
| 106 | +@pytest.mark.selenium |
| 107 | +@patch("country_workspace.workspaces.admin.cleaners.bulk_update.bulk_update_export_template") |
| 108 | +def test_households_export_generation( |
| 109 | + mocked_exporter, browser: CountryWorkspaceSeleniumTC, household: "CountryHousehold" |
| 110 | +): |
| 111 | + mocked_exporter.return_value = None |
| 112 | + _test_export_generation(browser=browser, household=household, link="Households") |
| 113 | + |
| 114 | + |
| 115 | +@pytest.mark.selenium |
| 116 | +@patch("country_workspace.workspaces.admin.cleaners.bulk_update.bulk_update_export_template") |
| 117 | +def test_individuals_export_generation( |
| 118 | + mocked_exporter, browser: CountryWorkspaceSeleniumTC, household: "CountryHousehold" |
| 119 | +): |
| 120 | + mocked_exporter.return_value = None |
| 121 | + _test_export_generation(browser=browser, household=household, link="Individuals") |
0 commit comments