File tree Expand file tree Collapse file tree 3 files changed +43
-2
lines changed
Expand file tree Collapse file tree 3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 1+ from unittest import mock
2+ from unittest .mock import Mock
3+
4+ import pytest
5+
6+ from country_workspace .workspaces .admin .cleaners .validate import validate_program
7+
8+
9+ @pytest .fixture
10+ def household ():
11+ from testutils .factories import CountryHouseholdFactory , ProgramFactory
12+
13+ program = ProgramFactory ()
14+ return CountryHouseholdFactory (batch__program = program , batch__country_office = program .country_office )
15+
16+
17+ def test_validate_program (household ):
18+ assert validate_program (Mock (program = household .program )) == {"invalid" : 0 , "total" : 0 , "valid" : 1 }
19+ with mock .patch (
20+ "country_workspace.workspaces.admin.cleaners.validate.Household.validate_with_checker" , return_value = False
21+ ):
22+ assert validate_program (Mock (program = household .program )) == {"invalid" : 1 , "total" : 0 , "valid" : 0 }
Original file line number Diff line number Diff line change 11from typing import TYPE_CHECKING
2+ from unittest import mock
3+ from unittest .mock import Mock
24
35import pytest
46
7+
58if TYPE_CHECKING :
6- from country_workspace .workspaces .models import CountryHousehold
9+ from country_workspace .workspaces .models import CountryHousehold , CountryIndividual
10+ from country_workspace .models import Household
711
812
913@pytest .fixture
@@ -13,6 +17,22 @@ def household() -> "CountryHousehold":
1317 return CountryHouseholdFactory ()
1418
1519
20+ @pytest .fixture
21+ def individual (household ) -> "CountryIndividual" :
22+ from testutils .factories import CountryIndividualFactory
23+
24+ return CountryIndividualFactory (household = household )
25+
26+
1627def test_properties (household : "CountryHousehold" ):
1728 assert household .program == household .batch .program
1829 assert household .country_office == household .batch .country_office
30+
31+
32+ def test_validate_with_checker (individual : "CountryHousehold" ):
33+ household : Household = individual .household
34+ assert household .validate_with_checker ()
35+ assert household .errors == {}
36+ with mock .patch .object (household .program .beneficiary_validator , "validate" , Mock (return_value = ["Error" ])):
37+ assert not household .validate_with_checker ()
38+ assert household .errors == {"dct" : ["Error" ]}
Original file line number Diff line number Diff line change 44import freezegun
55import pytest
66from django .urls import reverse
7-
87from testutils .utils import select_office
98
109from country_workspace .state import state
You can’t perform that action at this time.
0 commit comments