Skip to content

Commit 0ff431c

Browse files
authored
Merge pull request #114 from unicef/feature/test-mass-update
Feature/test mass update
2 parents cef42b5 + ed081ec commit 0ff431c

File tree

4 files changed

+73
-14
lines changed

4 files changed

+73
-14
lines changed

tests/data/mass_update_hshld.xlsx

7.79 KB
Binary file not shown.

tests/functional/conftest.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from typing import Generator
22

3+
import pytest
34
from django.conf import settings
45
from seleniumbase import config as sb_config
56
from seleniumbase.core import session_helper
6-
import pytest
7-
7+
from testutils.factories import CountryProgramFactory
8+
from testutils.factories import OfficeFactory
89
from testutils.selenium import CountryWorkspaceSeleniumTC
910

1011

@@ -44,3 +45,13 @@ def browser(live_server, request) -> Generator[CountryWorkspaceSeleniumTC, None,
4445
if sb._needs_tearDown:
4546
sb.tearDown()
4647
sb._needs_tearDown = False
48+
49+
50+
@pytest.fixture
51+
def office(db, worker_id):
52+
return OfficeFactory()
53+
54+
55+
@pytest.fixture
56+
def program(office):
57+
return CountryProgramFactory(country_office=office)

tests/functional/test_f_import_data.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
import pytest
22
from django.core.management import call_command
3-
from testutils.factories import OfficeFactory
4-
from testutils.factories import CountryProgramFactory
53

64

75
@pytest.fixture(autouse=True)
86
def create_checkers() -> None:
97
call_command("upgradescripts", ["apply"])
108

119

12-
@pytest.fixture
13-
def office(db, worker_id):
14-
return OfficeFactory()
15-
16-
17-
@pytest.fixture
18-
def program(office):
19-
return CountryProgramFactory(country_office=office)
20-
21-
2210
@pytest.fixture
2311
def browser_program(browser, program):
2412
browser.login_as_user()
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

Comments
 (0)