<s> from unittest import TestCase <EOL> from datetime import date , datetime <EOL> from couchforms . models import XFormInstance <EOL> from . . constants import InvalidRow <EOL> from . case_reports import ( OPMCaseReportTestBase , OPMCase , MockCaseRow , Report , <EOL> offset_date , MockDataProvider ) <EOL> class TestPregnancyWindowAndMonths ( OPMCaseReportTestBase ) : <EOL> def _offset_date ( self , offset ) : <EOL> """<STR_LIT>""" <EOL> return offset_date ( self . report_date , offset ) <EOL> def test_valid_month_not_yet_delivered ( self ) : <EOL> month_mapping = { <EOL> <NUM_LIT:0> : <NUM_LIT:9> , <EOL> <NUM_LIT:1> : <NUM_LIT:8> , <EOL> <NUM_LIT:2> : <NUM_LIT:7> , <EOL> <NUM_LIT:3> : <NUM_LIT:6> , <EOL> <NUM_LIT:4> : <NUM_LIT:5> , <EOL> <NUM_LIT:5> : <NUM_LIT:4> , <EOL> } <EOL> for i , month in month_mapping . items ( ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> edd = self . _offset_date ( i ) , <EOL> ) <EOL> row = MockCaseRow ( case , self . report ) <EOL> self . assertEqual ( '<STR_LIT>' , row . status ) <EOL> self . assertEqual ( month , row . preg_month ) <EOL> def test_not_yet_in_range ( self ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> edd = self . _offset_date ( <NUM_LIT:6> ) , <EOL> ) <EOL> mock_case = MockCaseRow ( case , self . report ) <EOL> self . assertTrue ( mock_case . case_is_out_of_range ) <EOL> def test_not_yet_in_range_by_a_lot ( self ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> edd = self . _offset_date ( <NUM_LIT:12> ) , <EOL> ) <EOL> mock_case = MockCaseRow ( case , self . report ) <EOL> self . assertTrue ( mock_case . case_is_out_of_range ) <EOL> def test_past_range ( self ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> edd = self . _offset_date ( - <NUM_LIT:1> ) , <EOL> ) <EOL> mock_case = MockCaseRow ( case , self . report ) <EOL> self . assertTrue ( mock_case . case_is_out_of_range ) <EOL> def test_child_first_month_not_valid ( self ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> dod = self . report_date , <EOL> ) <EOL> mock_case = MockCaseRow ( case , self . report ) <EOL> self . assertTrue ( mock_case . case_is_out_of_range ) <EOL> def test_valid_child_month ( self ) : <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT> ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> dod = self . _offset_date ( - i ) , <EOL> ) <EOL> row = MockCaseRow ( case , self . report ) <EOL> self . assertEqual ( '<STR_LIT>' , row . status ) <EOL> self . assertEqual ( i , row . child_age ) <EOL> def test_child_outside_window ( self ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> dod = self . _offset_date ( - <NUM_LIT:50> ) , <EOL> ) <EOL> mock_case = MockCaseRow ( case , self . report ) <EOL> self . assertTrue ( mock_case . case_is_out_of_range ) <EOL> class TestPregnancyFirstMonthWindow ( OPMCaseReportTestBase ) : <EOL> def test_first_of_month_counts ( self ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> edd = date ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:1> ) , <EOL> ) <EOL> row = MockCaseRow ( case , self . report ) <EOL> self . assertEqual ( <NUM_LIT:4> , row . preg_month ) <EOL> def test_last_of_month_counts ( self ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> edd = date ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:30> ) , <EOL> ) <EOL> row = MockCaseRow ( case , self . report ) <EOL> self . assertEqual ( <NUM_LIT:4> , row . preg_month ) <EOL> def test_vhnd_after_checkpoint_pregnancy ( self ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> edd = date ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:15> ) , <EOL> ) <EOL> data_provider = MockDataProvider ( default_date = date ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT> ) ) <EOL> row = MockCaseRow ( case , self . report , data_provider = data_provider ) <EOL> self . assertEqual ( <NUM_LIT:4> , row . preg_month ) <EOL> def test_vhnd_before_checkpoint_pregnancy ( self ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> edd = date ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:15> ) , <EOL> ) <EOL> data_provider = MockDataProvider ( default_date = date ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:5> ) ) <EOL> mock_case = MockCaseRow ( case , self . report , data_provider = data_provider ) <EOL> self . assertTrue ( mock_case . case_is_out_of_range ) <EOL> row = MockCaseRow ( case , Report ( month = <NUM_LIT:7> , year = <NUM_LIT> , block = "<STR_LIT>" ) , data_provider = data_provider ) <EOL> self . assertEqual ( <NUM_LIT:4> , row . preg_month ) <EOL> row = MockCaseRow ( case , Report ( month = <NUM_LIT:9> , year = <NUM_LIT> , block = "<STR_LIT>" ) , data_provider = data_provider ) <EOL> self . assertEqual ( <NUM_LIT:6> , row . preg_month ) <EOL> class TestChildFirstMonthWindow ( OPMCaseReportTestBase ) : <EOL> def test_first_of_month_counts ( self ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> dod = date ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:1> ) , <EOL> ) <EOL> row = MockCaseRow ( case , self . report ) <EOL> self . assertEqual ( <NUM_LIT:1> , row . child_age ) <EOL> def test_last_of_month_counts ( self ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> dod = date ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> ) , <EOL> ) <EOL> row = MockCaseRow ( case , self . report ) <EOL> self . assertEqual ( <NUM_LIT:1> , row . child_age ) <EOL> def test_vhnd_after_checkpoint_child ( self ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> dod = date ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:15> ) , <EOL> ) <EOL> data_provider = MockDataProvider ( default_date = date ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT> ) ) <EOL> row = MockCaseRow ( case , self . report , data_provider = data_provider ) <EOL> self . assertEqual ( <NUM_LIT:1> , row . child_age ) <EOL> def test_vhnd_before_checkpoint_pregnancy ( self ) : <EOL> case = OPMCase ( <EOL> forms = [ ] , <EOL> dod = date ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:15> ) , <EOL> ) <EOL> data_provider = MockDataProvider ( default_date = date ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:5> ) ) <EOL> mock_case = MockCaseRow ( case , self . report , data_provider = data_provider ) <EOL> self . assertTrue ( mock_case . case_is_out_of_range ) <EOL> row = MockCaseRow ( case , Report ( month = <NUM_LIT:7> , year = <NUM_LIT> , block = "<STR_LIT>" ) , data_provider = data_provider ) <EOL> self . assertEqual ( <NUM_LIT:1> , row . child_age ) <EOL> row = MockCaseRow ( case , Report ( month = <NUM_LIT:9> , year = <NUM_LIT> , block = "<STR_LIT>" ) , data_provider = data_provider ) <EOL> self . assertEqual ( <NUM_LIT:3> , row . child_age ) <EOL> class TestFormFiltering ( TestCase ) : <EOL> def check_form ( self , received = None , months_before = None , months_after = None , xmlns = None ) : <EOL> form = XFormInstance ( received_on = received or datetime ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:15> ) , <EOL> form = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , <EOL> xmlns = xmlns or '<STR_LIT>' ) <EOL> case = OPMCase ( [ form ] , dod = date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:10> ) ) <EOL> row = MockCaseRow ( case , Report ( month = <NUM_LIT:6> , year = <NUM_LIT> , block = "<STR_LIT>" ) ) <EOL> return len ( row . filtered_forms ( xmlns , months_before , months_after ) ) == <NUM_LIT:1> <EOL> def assertInRange ( self , y , m , d , months_before = None , months_after = None ) : <EOL> self . assertTrue ( self . check_form ( datetime ( y , m , d , <NUM_LIT:10> ) , months_before , months_after ) ) <EOL> def assertNotInRange ( self , y , m , d , months_before = None , months_after = None ) : <EOL> self . assertFalse ( self . check_form ( datetime ( y , m , d , <NUM_LIT:10> ) , months_before , months_after ) ) <EOL> def test_forms_in_range ( self ) : <EOL> self . assertInRange ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:15> , <NUM_LIT:1> ) <EOL> self . assertInRange ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:15> , <NUM_LIT:5> ) <EOL> def test_form_higher ( self ) : <EOL> self . assertNotInRange ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:15> , <NUM_LIT:3> ) <EOL> def test_form_lower ( self ) : <EOL> self . assertNotInRange ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:15> , <NUM_LIT:3> ) <EOL> def test_xmlns_list ( self ) : <EOL> self . assertTrue ( self . check_form ( xmlns = '<STR_LIT>' ) ) <EOL> def test_last_day ( self ) : <EOL> self . assertInRange ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:30> ) <EOL> def test_one_day_late ( self ) : <EOL> self . assertNotInRange ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:1> ) <EOL> def test_first_day ( self ) : <EOL> self . assertInRange ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:1> , months_before = <NUM_LIT:1> ) <EOL> self . assertInRange ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> , months_before = <NUM_LIT:3> ) <EOL> def test_one_day_early ( self ) : <EOL> self . assertNotInRange ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , months_before = <NUM_LIT:1> ) <EOL> self . assertNotInRange ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> , months_before = <NUM_LIT:3> ) <EOL> def test_months_after ( self ) : <EOL> self . assertInRange ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:4> , months_after = <NUM_LIT:1> ) <EOL> def test_months_after_doesnt_affect_before ( self ) : <EOL> self . assertNotInRange ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:4> , months_before = <NUM_LIT:1> , months_after = <NUM_LIT:1> ) </s>
