<s> import uuid <EOL> from couchdbkit . exceptions import BulkSaveError <EOL> from django . test import TestCase , SimpleTestCase <EOL> import os <EOL> from django . test . utils import override_settings <EOL> from casexml . apps . case . const import CASE_INDEX_EXTENSION <EOL> from casexml . apps . case . mock import CaseBlock , CaseFactory , CaseStructure , CaseIndex <EOL> from casexml . apps . case . models import CommCareCase <EOL> from casexml . apps . case . templatetags . case_tags import get_case_hierarchy <EOL> from casexml . apps . case . tests . util import delete_all_cases <EOL> from casexml . apps . case . util import post_case_blocks <EOL> from casexml . apps . case . xml import V2 , V1 <EOL> from corehq . apps . receiverwrapper import submit_form_locally <EOL> from corehq . form_processor . tests . utils import run_with_all_backends <EOL> from corehq . util . test_utils import TestFileMixin <EOL> class SimpleCaseBugTests ( SimpleTestCase ) : <EOL> def test_generate_xml_with_no_date_modified ( self ) : <EOL> for version in ( V1 , V2 ) : <EOL> CommCareCase ( _id = '<STR_LIT:test>' ) . to_xml ( version ) <EOL> @ override_settings ( CASEXML_FORCE_DOMAIN_CHECK = False ) <EOL> class CaseBugTest ( TestCase , TestFileMixin ) : <EOL> """<STR_LIT>""" <EOL> file_path = ( '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> root = os . path . dirname ( __file__ ) <EOL> def setUp ( self ) : <EOL> delete_all_cases ( ) <EOL> def test_conflicting_ids ( self ) : <EOL> """<STR_LIT>""" <EOL> xml_data = self . get_xml ( '<STR_LIT>' ) <EOL> with self . assertRaises ( BulkSaveError ) : <EOL> submit_form_locally ( xml_data , '<STR_LIT>' ) <EOL> @ run_with_all_backends <EOL> def test_empty_case_id ( self ) : <EOL> """<STR_LIT>""" <EOL> xml_data = self . get_xml ( '<STR_LIT>' ) <EOL> response , form , cases = submit_form_locally ( xml_data , '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , response . content ) <EOL> def _testCornerCaseDatatypeBugs ( self , value ) : <EOL> def _test ( custom_format_args ) : <EOL> case_id = uuid . uuid4 ( ) . hex <EOL> format_args = { <EOL> '<STR_LIT>' : case_id , <EOL> '<STR_LIT>' : uuid . uuid4 ( ) . hex , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> format_args . update ( custom_format_args ) <EOL> for filename in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> format_args [ '<STR_LIT>' ] = uuid . uuid4 ( ) . hex , <EOL> xml_data = self . get_xml ( filename ) . format ( ** format_args ) <EOL> response , form , [ case ] = submit_form_locally ( xml_data , '<STR_LIT>' ) <EOL> self . assertEqual ( format_args [ '<STR_LIT>' ] , case . user_id ) <EOL> self . assertEqual ( format_args [ '<STR_LIT>' ] , case . name ) <EOL> self . assertEqual ( format_args [ '<STR_LIT>' ] , case . type ) <EOL> _test ( { '<STR_LIT>' : value } ) <EOL> _test ( { '<STR_LIT>' : value } ) <EOL> _test ( { '<STR_LIT>' : value } ) <EOL> @ run_with_all_backends <EOL> def testDateInCasePropertyBug ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _testCornerCaseDatatypeBugs ( '<STR_LIT>' ) <EOL> @ run_with_all_backends <EOL> def testIntegerInCasePropertyBug ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _testCornerCaseDatatypeBugs ( '<STR_LIT>' ) <EOL> @ run_with_all_backends <EOL> def testDecimalInCasePropertyBug ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _testCornerCaseDatatypeBugs ( '<STR_LIT>' ) <EOL> @ run_with_all_backends <EOL> def testDuplicateCasePropertiesBug ( self ) : <EOL> """<STR_LIT>""" <EOL> xml_data = self . get_xml ( '<STR_LIT>' ) <EOL> response , form , [ case ] = submit_form_locally ( xml_data , '<STR_LIT>' ) <EOL> self . assertEqual ( "<STR_LIT>" , case . dynamic_case_properties ( ) [ '<STR_LIT:foo>' ] ) <EOL> xml_data = self . get_xml ( '<STR_LIT>' ) <EOL> response , form , [ case ] = submit_form_locally ( xml_data , '<STR_LIT>' ) <EOL> self . assertEqual ( "<STR_LIT:2>" , case . dynamic_case_properties ( ) [ '<STR_LIT:bar>' ] ) <EOL> @ run_with_all_backends <EOL> def testMultipleCaseBlocks ( self ) : <EOL> """<STR_LIT>""" <EOL> xml_data = self . get_xml ( '<STR_LIT>' ) <EOL> response , form , [ case ] = submit_form_locally ( xml_data , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , case . dynamic_case_properties ( ) [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , case . dynamic_case_properties ( ) [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( '<STR_LIT>' , case . dynamic_case_properties ( ) [ '<STR_LIT>' ] ) <EOL> ids = case . xform_ids <EOL> self . assertEqual ( <NUM_LIT:1> , len ( ids ) ) <EOL> self . assertEqual ( form . form_id , ids [ <NUM_LIT:0> ] ) <EOL> @ run_with_all_backends <EOL> def testLotsOfSubcases ( self ) : <EOL> """<STR_LIT>""" <EOL> xml_data = self . get_xml ( '<STR_LIT>' ) <EOL> response , form , cases = submit_form_locally ( xml_data , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:11> , len ( cases ) ) <EOL> @ run_with_all_backends <EOL> def testSubmitToDeletedCase ( self ) : <EOL> case_id = '<STR_LIT>' <EOL> xform , [ case ] = post_case_blocks ( [ <EOL> CaseBlock ( create = True , case_id = case_id , user_id = '<STR_LIT>' , <EOL> update = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) . as_xml ( ) <EOL> ] ) <EOL> case . soft_delete ( ) <EOL> self . assertEqual ( '<STR_LIT:bar>' , case . dynamic_case_properties ( ) [ '<STR_LIT:foo>' ] ) <EOL> self . assertTrue ( case . is_deleted ) <EOL> xform , [ case ] = post_case_blocks ( [ <EOL> CaseBlock ( create = False , case_id = case_id , user_id = '<STR_LIT>' , <EOL> update = { '<STR_LIT:foo>' : '<STR_LIT>' } ) . as_xml ( ) <EOL> ] ) <EOL> self . assertEqual ( '<STR_LIT>' , case . dynamic_case_properties ( ) [ '<STR_LIT:foo>' ] ) <EOL> self . assertTrue ( case . is_deleted ) <EOL> class TestCaseHierarchy ( TestCase ) : <EOL> def setUp ( self ) : <EOL> delete_all_cases ( ) <EOL> @ run_with_all_backends <EOL> def test_normal_index ( self ) : <EOL> factory = CaseFactory ( ) <EOL> [ cp ] = factory . create_or_update_case ( <EOL> CaseStructure ( case_id = '<STR_LIT>' , attrs = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> ) <EOL> factory . create_or_update_case ( CaseStructure ( <EOL> case_id = '<STR_LIT>' , <EOL> attrs = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> indices = [ CaseIndex ( CaseStructure ( case_id = '<STR_LIT>' ) , related_type = '<STR_LIT>' ) ] , <EOL> walk_related = False <EOL> ) ) <EOL> hierarchy = get_case_hierarchy ( cp , { } ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( hierarchy [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( hierarchy [ '<STR_LIT>' ] ) ) <EOL> @ run_with_all_backends <EOL> def test_extension_index ( self ) : <EOL> factory = CaseFactory ( ) <EOL> [ case ] = factory . create_or_update_case ( <EOL> CaseStructure ( case_id = "<STR_LIT>" , attrs = { '<STR_LIT>' : "<STR_LIT>" } ) <EOL> ) <EOL> factory . create_or_update_case ( <EOL> CaseStructure ( <EOL> case_id = "<STR_LIT>" , <EOL> attrs = { '<STR_LIT>' : "<STR_LIT>" } , <EOL> indices = [ <EOL> CaseIndex ( <EOL> CaseStructure ( case_id = "<STR_LIT>" ) , <EOL> related_type = '<STR_LIT>' , <EOL> relationship = CASE_INDEX_EXTENSION <EOL> ) <EOL> ] , <EOL> walk_related = False <EOL> ) <EOL> ) <EOL> hierarchy = get_case_hierarchy ( case , { } ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( hierarchy [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( hierarchy [ '<STR_LIT>' ] ) ) <EOL> @ run_with_all_backends <EOL> def test_recursive_indexes ( self ) : <EOL> factory = CaseFactory ( ) <EOL> [ case ] = factory . create_or_update_case ( CaseStructure ( <EOL> case_id = '<STR_LIT>' , <EOL> attrs = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> indices = [ CaseIndex ( CaseStructure ( case_id = '<STR_LIT>' ) , related_type = '<STR_LIT>' ) ] , <EOL> walk_related = False <EOL> ) ) <EOL> hierarchy = get_case_hierarchy ( case , { } ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( hierarchy [ '<STR_LIT>' ] ) ) <EOL> @ run_with_all_backends <EOL> def test_complex_index ( self ) : <EOL> factory = CaseFactory ( ) <EOL> cp = factory . create_or_update_case ( CaseStructure ( case_id = '<STR_LIT>' , attrs = { '<STR_LIT>' : '<STR_LIT>' } ) ) [ <NUM_LIT:0> ] <EOL> factory . create_or_update_case ( CaseStructure ( <EOL> case_id = '<STR_LIT>' , <EOL> attrs = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> indices = [ CaseIndex ( CaseStructure ( case_id = '<STR_LIT>' ) , related_type = '<STR_LIT>' ) ] , <EOL> walk_related = False <EOL> ) ) <EOL> factory . create_or_update_case ( CaseStructure ( <EOL> case_id = '<STR_LIT>' , <EOL> attrs = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> indices = [ <EOL> CaseIndex ( CaseStructure ( case_id = '<STR_LIT>' ) , related_type = '<STR_LIT>' , identifier = '<STR_LIT>' ) , <EOL> CaseIndex ( CaseStructure ( case_id = '<STR_LIT>' ) , related_type = '<STR_LIT>' ) <EOL> ] , <EOL> walk_related = False , <EOL> ) ) <EOL> type_info = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } , <EOL> } <EOL> hierarchy = get_case_hierarchy ( cp , type_info ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( hierarchy [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( hierarchy [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( hierarchy [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( hierarchy [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) ) </s>
