11from typing import TYPE_CHECKING
22
33import pytest
4+ from django .core .management import call_command
5+ from testutils .factories import OfficeFactory
6+ from testutils .factories .program import BeneficiaryGroupFactory
7+ from testutils .factories import CountryProgramFactory
48
59if TYPE_CHECKING :
610 from country_workspace .workspaces .models import CountryHousehold
711
812pytestmark = pytest .mark .xdist_group ("selenium" )
913
1014
15+ @pytest .fixture (autouse = True )
16+ def create_checkers () -> None :
17+ call_command ("upgradescripts" , ["apply" ])
18+
19+
1120@pytest .fixture
1221def office (db , worker_id ):
13- from testutils .factories import OfficeFactory
14-
1522 return OfficeFactory ()
1623
1724
1825@pytest .fixture
19- def program (office , worker_id ):
20- from testutils .factories import CountryProgramFactory
26+ def beneficiary_group ():
27+ return BeneficiaryGroupFactory (
28+ group_label_plural = "Households" ,
29+ member_label_plural = "Individuals" ,
30+ master_detail = True ,
31+ )
32+
2133
34+ @pytest .fixture
35+ def program (office , household_checker , individual_checker , beneficiary_group ):
2236 return CountryProgramFactory (
2337 country_office = office ,
24- household_columns = "__str__\n id\n xx" ,
25- individual_columns = "__str__\n id\n xx" ,
26- household_checker__name = f"HH Checker { worker_id } " ,
27- individual_checker__name = f"IND Checker { worker_id } " ,
38+ household_columns = "name\n id\n " ,
39+ individual_columns = "name\n id\n " ,
40+ household_checker = household_checker ,
41+ individual_checker = individual_checker ,
42+ beneficiary_group = beneficiary_group ,
2843 )
2944
3045
@@ -36,27 +51,31 @@ def household(program):
3651
3752
3853@pytest .mark .selenium
39- @pytest .mark .xfail
40- def test_list_household (browser , admin_user , household : "CountryHousehold" ):
41- from testutils .perms import user_grant_permissions
42-
43- with user_grant_permissions (
44- admin_user ,
45- [
46- "workspaces.view_countryhousehold" ,
47- "workspaces.view_countryindividual" ,
48- "workspaces.view_countryprogram" ,
49- ],
50- household .program .country_office ,
51- ):
52- browser .login ()
53- # Select Tenant
54- browser .select_option_by_text ("select[name=tenant]" , household .program .country_office .name )
55- browser .select2_select ("id_program" , household .program .name )
56-
57- browser .click_link ("Households" )
58- browser .click_link (str (household .name ))
59- browser .assert_current_url (household .get_change_url ())
60-
61- browser .click ("a.closelink" )
62- browser .assert_current_url ("/workspaces/countryhousehold/" )
54+ def test_list_household (browser , household : "CountryHousehold" ):
55+ browser .login_as_user ()
56+ browser .select_option_by_text ("select[name=tenant]" , household .program .country_office .name )
57+ browser .select2_select ("id_program" , household .program .name )
58+
59+ browser .click_link ("Households" )
60+ browser .click_link (str (household .name ))
61+ browser .assert_url (f"{ browser .live_server_url } { household .get_change_url ()} " )
62+
63+ browser .click ("a.closelink" )
64+ browser .assert_url (f"{ browser .live_server_url } /workspaces/countryhousehold/" )
65+
66+
67+ @pytest .mark .selenium
68+ def test_list_household_select_all_fields (browser , household : "CountryHousehold" ):
69+ browser .login_as_user ()
70+ browser .select_option_by_text ("select[name=tenant]" , household .program .country_office .name )
71+ browser .select2_select ("id_program" , household .program .name )
72+ browser .click_link ("Households" )
73+
74+ browser .click ("#action-toggle" )
75+ browser .select_option_by_value ("select[name=action]" , "bulk_update_export" )
76+ browser .click ('button[type="submit"][name="index"]' )
77+
78+ browser .click ("#select-all" )
79+ checkboxes = browser .find_elements ('input[type="checkbox"][name="fields"]' )
80+ for cb in checkboxes :
81+ assert cb .is_selected ()
0 commit comments