<s> import os <EOL> from mock import patch <EOL> from django . test import SimpleTestCase , TestCase <EOL> from corehq . apps . export . models . new import MAIN_TABLE , PathNode , _question_path_to_path_nodes <EOL> from dimagi . utils . couch . database import safe_delete <EOL> from corehq . apps . app_manager . tests . util import TestXmlMixin <EOL> from corehq . apps . app_manager . models import XForm , Application <EOL> from corehq . apps . export . models import ( <EOL> FormExportDataSchema , <EOL> CaseExportDataSchema , <EOL> ExportDataSchema , <EOL> PARENT_CASE_TABLE , <EOL> ) <EOL> from corehq . apps . export . const import PROPERTY_TAG_UPDATE <EOL> class TestFormExportDataSchema ( SimpleTestCase , TestXmlMixin ) : <EOL> file_path = [ '<STR_LIT:data>' ] <EOL> root = os . path . dirname ( __file__ ) <EOL> app_id = '<STR_LIT>' <EOL> def test_basic_xform_parsing ( self ) : <EOL> form_xml = self . get_xml ( '<STR_LIT>' ) <EOL> schema = FormExportDataSchema . _generate_schema_from_xform ( <EOL> XForm ( form_xml ) , <EOL> [ ] , <EOL> [ '<STR_LIT>' ] , <EOL> self . app_id , <EOL> <NUM_LIT:1> <EOL> ) <EOL> self . assertEqual ( len ( schema . group_schemas ) , <NUM_LIT:1> ) <EOL> group_schema = schema . group_schemas [ <NUM_LIT:0> ] <EOL> self . assertEqual ( len ( group_schema . items ) , <NUM_LIT:2> ) <EOL> form_items = filter ( lambda item : item . tag is None , group_schema . items ) <EOL> self . assertEqual ( form_items [ <NUM_LIT:0> ] . path , [ PathNode ( name = '<STR_LIT>' ) , PathNode ( name = '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( form_items [ <NUM_LIT:1> ] . path , [ PathNode ( name = '<STR_LIT>' ) , PathNode ( name = '<STR_LIT>' ) ] ) <EOL> def test_xform_parsing_with_repeat_group ( self ) : <EOL> form_xml = self . get_xml ( '<STR_LIT>' ) <EOL> schema = FormExportDataSchema . _generate_schema_from_xform ( <EOL> XForm ( form_xml ) , <EOL> [ ] , <EOL> [ '<STR_LIT>' ] , <EOL> self . app_id , <EOL> <NUM_LIT:1> <EOL> ) <EOL> self . assertEqual ( len ( schema . group_schemas ) , <NUM_LIT:2> ) <EOL> group_schema = schema . group_schemas [ <NUM_LIT:0> ] <EOL> self . assertEqual ( len ( group_schema . items ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( group_schema . path , MAIN_TABLE ) <EOL> form_items = filter ( lambda item : item . tag is None , group_schema . items ) <EOL> self . assertEqual ( form_items [ <NUM_LIT:0> ] . path , [ PathNode ( name = '<STR_LIT>' ) , PathNode ( name = '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( form_items [ <NUM_LIT:1> ] . path , [ PathNode ( name = '<STR_LIT>' ) , PathNode ( name = '<STR_LIT>' ) ] ) <EOL> group_schema = schema . group_schemas [ <NUM_LIT:1> ] <EOL> self . assertEqual ( len ( group_schema . items ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( <EOL> group_schema . path , <EOL> [ PathNode ( name = '<STR_LIT>' ) , PathNode ( name = '<STR_LIT>' , is_repeat = True ) ] <EOL> ) <EOL> self . assertEqual ( <EOL> group_schema . items [ <NUM_LIT:0> ] . path , <EOL> [ PathNode ( name = '<STR_LIT>' ) , PathNode ( name = '<STR_LIT>' , is_repeat = True ) , PathNode ( name = '<STR_LIT>' ) ] <EOL> ) <EOL> def test_xform_parsing_with_multiple_choice ( self ) : <EOL> form_xml = self . get_xml ( '<STR_LIT>' ) <EOL> schema = FormExportDataSchema . _generate_schema_from_xform ( <EOL> XForm ( form_xml ) , <EOL> [ ] , <EOL> [ '<STR_LIT>' ] , <EOL> self . app_id , <EOL> <NUM_LIT:1> <EOL> ) <EOL> self . assertEqual ( len ( schema . group_schemas ) , <NUM_LIT:1> ) <EOL> group_schema = schema . group_schemas [ <NUM_LIT:0> ] <EOL> self . assertEqual ( len ( group_schema . items ) , <NUM_LIT:2> ) <EOL> form_items = filter ( lambda item : item . tag is None , group_schema . items ) <EOL> self . assertEqual ( form_items [ <NUM_LIT:0> ] . path , [ PathNode ( name = '<STR_LIT>' ) , PathNode ( name = '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( form_items [ <NUM_LIT:1> ] . path , [ PathNode ( name = '<STR_LIT>' ) , PathNode ( name = '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( form_items [ <NUM_LIT:1> ] . options [ <NUM_LIT:0> ] . value , '<STR_LIT>' ) <EOL> self . assertEqual ( form_items [ <NUM_LIT:1> ] . options [ <NUM_LIT:1> ] . value , '<STR_LIT>' ) <EOL> def test_question_path_to_path_nodes ( self ) : <EOL> """<STR_LIT>""" <EOL> repeat_groups = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> self . assertEqual ( <EOL> _question_path_to_path_nodes ( "<STR_LIT>" , repeat_groups ) , <EOL> [ PathNode ( name = '<STR_LIT>' , is_repeat = False ) , PathNode ( name = '<STR_LIT>' , is_repeat = True ) ] <EOL> ) <EOL> self . assertEqual ( <EOL> _question_path_to_path_nodes ( "<STR_LIT>" , repeat_groups ) , <EOL> [ PathNode ( name = '<STR_LIT>' , is_repeat = False ) , PathNode ( name = '<STR_LIT>' , is_repeat = False ) ] <EOL> ) <EOL> self . assertEqual ( <EOL> _question_path_to_path_nodes ( "<STR_LIT>" , repeat_groups ) , <EOL> [ <EOL> PathNode ( name = '<STR_LIT>' , is_repeat = False ) , <EOL> PathNode ( name = '<STR_LIT>' , is_repeat = False ) , <EOL> PathNode ( name = '<STR_LIT>' , is_repeat = True ) , <EOL> ] <EOL> ) <EOL> self . assertEqual ( <EOL> _question_path_to_path_nodes ( "<STR_LIT>" , repeat_groups ) , <EOL> [ <EOL> PathNode ( name = '<STR_LIT>' , is_repeat = False ) , <EOL> PathNode ( name = '<STR_LIT>' , is_repeat = False ) , <EOL> PathNode ( name = '<STR_LIT>' , is_repeat = True ) , <EOL> PathNode ( name = '<STR_LIT>' , is_repeat = True ) , <EOL> ] <EOL> ) <EOL> self . assertEqual ( <EOL> _question_path_to_path_nodes ( "<STR_LIT>" , repeat_groups ) , <EOL> [ <EOL> PathNode ( name = '<STR_LIT>' , is_repeat = False ) , <EOL> PathNode ( name = '<STR_LIT>' , is_repeat = False ) , <EOL> PathNode ( name = '<STR_LIT>' , is_repeat = True ) , <EOL> PathNode ( name = '<STR_LIT>' , is_repeat = True ) , <EOL> PathNode ( name = '<STR_LIT>' , is_repeat = False ) , <EOL> ] <EOL> ) <EOL> class TestCaseExportDataSchema ( SimpleTestCase , TestXmlMixin ) : <EOL> app_id = '<STR_LIT>' <EOL> def test_case_type_metadata_parsing ( self ) : <EOL> case_property_mapping = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> } <EOL> schema = CaseExportDataSchema . _generate_schema_from_case_property_mapping ( <EOL> case_property_mapping , <EOL> [ ] , <EOL> self . app_id , <EOL> <NUM_LIT:1> , <EOL> ) <EOL> self . assertEqual ( len ( schema . group_schemas ) , <NUM_LIT:1> ) <EOL> group_schema = schema . group_schemas [ <NUM_LIT:0> ] <EOL> my_case_property_item = group_schema . items [ <NUM_LIT:0> ] <EOL> my_second_case_property_item = group_schema . items [ <NUM_LIT:1> ] <EOL> self . assertEqual ( my_case_property_item . path , [ PathNode ( name = '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( my_case_property_item . last_occurrences [ self . app_id ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( my_second_case_property_item . path , [ PathNode ( name = '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( my_second_case_property_item . last_occurrences [ self . app_id ] , <NUM_LIT:1> ) <EOL> def test_case_history_parsing ( self ) : <EOL> schema = CaseExportDataSchema . _generate_schema_for_case_history ( { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> } , self . app_id , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( schema . group_schemas ) , <NUM_LIT:1> ) <EOL> group_schema = schema . group_schemas [ <NUM_LIT:0> ] <EOL> update_items = filter ( lambda item : item . tag == PROPERTY_TAG_UPDATE , group_schema . items ) <EOL> self . assertEqual ( len ( update_items ) , <NUM_LIT:2> ) <EOL> def test_get_app_build_ids_to_process ( self ) : <EOL> from corehq . apps . app_manager . dbaccessors import AppBuildVersion <EOL> results = [ <EOL> AppBuildVersion ( app_id = '<STR_LIT:1>' , build_id = '<STR_LIT:2>' , version = <NUM_LIT:3> ) , <EOL> AppBuildVersion ( app_id = '<STR_LIT:1>' , build_id = '<STR_LIT:4>' , version = <NUM_LIT:5> ) , <EOL> AppBuildVersion ( app_id = '<STR_LIT:2>' , build_id = '<STR_LIT:2>' , version = <NUM_LIT:3> ) , <EOL> ] <EOL> last_app_versions = { <EOL> '<STR_LIT:1>' : <NUM_LIT:3> <EOL> } <EOL> with patch ( <EOL> '<STR_LIT>' , <EOL> return_value = results ) : <EOL> build_ids = CaseExportDataSchema . _get_app_build_ids_to_process ( <EOL> '<STR_LIT>' , <EOL> last_app_versions <EOL> ) <EOL> self . assertEqual ( sorted ( build_ids ) , [ '<STR_LIT:2>' , '<STR_LIT:4>' ] ) <EOL> class TestMergingFormExportDataSchema ( SimpleTestCase , TestXmlMixin ) : <EOL> file_path = [ '<STR_LIT:data>' ] <EOL> root = os . path . dirname ( __file__ ) <EOL> app_id = '<STR_LIT>' <EOL> def _get_merged_schema ( self , form_name1 , form_name2 ) : <EOL> form_xml = self . get_xml ( form_name1 ) <EOL> form_xml2 = self . get_xml ( form_name2 ) <EOL> schema = FormExportDataSchema . _generate_schema_from_xform ( <EOL> XForm ( form_xml ) , <EOL> [ ] , <EOL> [ '<STR_LIT>' ] , <EOL> self . app_id , <EOL> <NUM_LIT:1> <EOL> ) <EOL> schema2 = FormExportDataSchema . _generate_schema_from_xform ( <EOL> XForm ( form_xml2 ) , <EOL> [ ] , <EOL> [ '<STR_LIT>' ] , <EOL> self . app_id , <EOL> <NUM_LIT:2> <EOL> ) <EOL> return FormExportDataSchema . _merge_schemas ( schema , schema2 ) <EOL> def test_simple_merge ( self ) : <EOL> """<STR_LIT>""" <EOL> merged = self . _get_merged_schema ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( merged . group_schemas ) , <NUM_LIT:1> ) <EOL> group_schema = merged . group_schemas [ <NUM_LIT:0> ] <EOL> self . assertEqual ( len ( group_schema . items ) , <NUM_LIT:3> ) <EOL> self . assertTrue ( all ( map ( <EOL> lambda item : item . last_occurrences [ self . app_id ] == <NUM_LIT:2> , <EOL> group_schema . items , <EOL> ) ) ) <EOL> def test_merge_deleted ( self ) : <EOL> """<STR_LIT>""" <EOL> merged = self . _get_merged_schema ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( merged . group_schemas ) , <NUM_LIT:1> ) <EOL> group_schema = merged . group_schemas [ <NUM_LIT:0> ] <EOL> self . assertEqual ( len ( group_schema . items ) , <NUM_LIT:2> ) <EOL> v1items = filter ( lambda item : item . last_occurrences [ self . app_id ] == <NUM_LIT:1> , group_schema . items ) <EOL> v2items = filter ( lambda item : item . last_occurrences [ self . app_id ] == <NUM_LIT:2> , group_schema . items ) <EOL> self . assertEqual ( <EOL> len ( v2items ) , <EOL> <NUM_LIT:1> , <EOL> '<STR_LIT>' . format ( len ( v2items ) ) <EOL> ) <EOL> self . assertEqual ( <EOL> len ( v1items ) , <EOL> <NUM_LIT:1> , <EOL> '<STR_LIT>' . format ( len ( v1items ) ) <EOL> ) <EOL> def test_multiple_choice_merge ( self ) : <EOL> """<STR_LIT>""" <EOL> merged = self . _get_merged_schema ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( merged . group_schemas ) , <NUM_LIT:1> ) <EOL> group_schema = merged . group_schemas [ <NUM_LIT:0> ] <EOL> self . assertEqual ( len ( group_schema . items ) , <NUM_LIT:2> ) <EOL> v2items = filter ( lambda item : item . last_occurrences [ self . app_id ] == <NUM_LIT:2> , group_schema . items ) <EOL> self . assertEqual ( len ( v2items ) , <NUM_LIT:2> ) <EOL> multichoice = filter ( <EOL> lambda item : item . path == [ PathNode ( name = '<STR_LIT>' ) , PathNode ( name = '<STR_LIT>' ) ] , <EOL> group_schema . items <EOL> ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( len ( multichoice . options ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( <EOL> len ( filter ( lambda o : o . last_occurrences [ self . app_id ] == <NUM_LIT:2> , multichoice . options ) ) , <EOL> <NUM_LIT:2> , <EOL> ) <EOL> self . assertEqual ( <EOL> len ( filter ( lambda o : o . last_occurrences [ self . app_id ] == <NUM_LIT:1> , multichoice . options ) ) , <EOL> <NUM_LIT:1> , <EOL> ) <EOL> def test_merge_repeat_group_changed_id ( self ) : <EOL> """<STR_LIT>""" <EOL> merged = self . _get_merged_schema ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( merged . group_schemas ) , <NUM_LIT:2> ) <EOL> group_schema1 = merged . group_schemas [ <NUM_LIT:0> ] <EOL> group_schema2 = merged . group_schemas [ <NUM_LIT:1> ] <EOL> self . assertEqual ( group_schema1 . last_occurrences [ self . app_id ] , <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( group_schema1 . items ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( group_schema2 . last_occurrences [ self . app_id ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( group_schema2 . items ) , <NUM_LIT:1> ) <EOL> class TestMergingCaseExportDataSchema ( SimpleTestCase , TestXmlMixin ) : <EOL> def test_basic_case_prop_merge ( self ) : <EOL> app_id = '<STR_LIT>' <EOL> case_property_mapping = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> } <EOL> schema1 = CaseExportDataSchema . _generate_schema_from_case_property_mapping ( <EOL> case_property_mapping , <EOL> [ ] , <EOL> app_id , <EOL> <NUM_LIT:1> , <EOL> ) <EOL> case_property_mapping = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> } <EOL> schema2 = CaseExportDataSchema . _generate_schema_from_case_property_mapping ( <EOL> case_property_mapping , <EOL> [ ] , <EOL> app_id , <EOL> <NUM_LIT:2> , <EOL> ) <EOL> schema3 = CaseExportDataSchema . _generate_schema_for_case_history ( <EOL> case_property_mapping , <EOL> app_id , <EOL> <NUM_LIT:2> , <EOL> ) <EOL> merged = CaseExportDataSchema . _merge_schemas ( schema1 , schema2 , schema3 ) <EOL> self . assertEqual ( len ( merged . group_schemas ) , <NUM_LIT:2> ) <EOL> group_schema1 = merged . group_schemas [ <NUM_LIT:0> ] <EOL> group_schema2 = merged . group_schemas [ <NUM_LIT:1> ] <EOL> self . assertEqual ( group_schema1 . last_occurrences [ app_id ] , <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( group_schema1 . items ) , <NUM_LIT:3> ) <EOL> items = filter ( lambda i : i . last_occurrences [ app_id ] == <NUM_LIT:1> , group_schema1 . items ) <EOL> self . assertEqual ( len ( items ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( group_schema2 . last_occurrences [ app_id ] , <NUM_LIT:2> ) <EOL> self . assertEqual ( <EOL> len ( group_schema2 . items ) , <EOL> len ( case_property_mapping [ '<STR_LIT>' ] ) <EOL> ) <EOL> class TestBuildingSchemaFromApplication ( TestCase , TestXmlMixin ) : <EOL> file_path = [ '<STR_LIT:data>' ] <EOL> root = os . path . dirname ( __file__ ) <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . current_app = Application . wrap ( cls . get_json ( '<STR_LIT>' ) ) <EOL> cls . first_build = Application . wrap ( cls . get_json ( '<STR_LIT>' ) ) <EOL> cls . first_build . _id = '<STR_LIT>' <EOL> cls . first_build . copy_of = cls . current_app . get_id <EOL> cls . first_build . version = <NUM_LIT:3> <EOL> cls . apps = [ <EOL> cls . current_app , <EOL> cls . first_build , <EOL> ] <EOL> for app in cls . apps : <EOL> app . save ( ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> for app in cls . apps : <EOL> app . delete ( ) <EOL> def tearDown ( self ) : <EOL> db = ExportDataSchema . get_db ( ) <EOL> for row in db . view ( '<STR_LIT>' , reduce = False ) : <EOL> doc_id = row [ '<STR_LIT:id>' ] <EOL> safe_delete ( db , doc_id ) <EOL> def test_basic_application_schema ( self ) : <EOL> app = self . current_app <EOL> schema = FormExportDataSchema . generate_schema_from_builds ( <EOL> app . domain , <EOL> app . _id , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( len ( schema . group_schemas ) , <NUM_LIT:1> ) <EOL> def test_build_from_saved_schema ( self ) : <EOL> app = self . current_app <EOL> schema = FormExportDataSchema . generate_schema_from_builds ( <EOL> app . domain , <EOL> app . _id , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( len ( schema . group_schemas ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( schema . last_app_versions [ app . _id ] , <NUM_LIT:3> ) <EOL> second_build = Application . wrap ( self . get_json ( '<STR_LIT>' ) ) <EOL> second_build . _id = '<STR_LIT>' <EOL> second_build . copy_of = app . get_id <EOL> second_build . version = <NUM_LIT:6> <EOL> second_build . save ( ) <EOL> self . addCleanup ( second_build . delete ) <EOL> new_schema = FormExportDataSchema . generate_schema_from_builds ( <EOL> app . domain , <EOL> app . _id , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( new_schema . _id , schema . _id ) <EOL> self . assertEqual ( new_schema . last_app_versions [ app . _id ] , <NUM_LIT:6> ) <EOL> self . assertEqual ( len ( new_schema . group_schemas ) , <NUM_LIT:1> ) <EOL> class TestBuildingCaseSchemaFromApplication ( TestCase , TestXmlMixin ) : <EOL> file_path = [ '<STR_LIT:data>' ] <EOL> root = os . path . dirname ( __file__ ) <EOL> domain = '<STR_LIT>' <EOL> case_type = '<STR_LIT>' <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . current_app = Application . wrap ( cls . get_json ( '<STR_LIT>' ) ) <EOL> cls . first_build = Application . wrap ( cls . get_json ( '<STR_LIT>' ) ) <EOL> cls . first_build . _id = '<STR_LIT>' <EOL> cls . first_build . copy_of = cls . current_app . get_id <EOL> cls . first_build . version = <NUM_LIT:3> <EOL> cls . apps = [ <EOL> cls . current_app , <EOL> cls . first_build , <EOL> ] <EOL> for app in cls . apps : <EOL> app . save ( ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> for app in cls . apps : <EOL> app . delete ( ) <EOL> def tearDown ( self ) : <EOL> db = ExportDataSchema . get_db ( ) <EOL> for row in db . view ( '<STR_LIT>' , reduce = False ) : <EOL> doc_id = row [ '<STR_LIT:id>' ] <EOL> safe_delete ( db , doc_id ) <EOL> def test_basic_application_schema ( self ) : <EOL> schema = CaseExportDataSchema . generate_schema_from_builds ( self . domain , self . case_type ) <EOL> self . assertEqual ( len ( schema . group_schemas ) , <NUM_LIT:2> ) <EOL> group_schema = schema . group_schemas [ <NUM_LIT:0> ] <EOL> self . assertEqual ( group_schema . last_occurrences [ self . current_app . _id ] , <NUM_LIT:3> ) <EOL> self . assertEqual ( len ( group_schema . items ) , <NUM_LIT:2> ) <EOL> def test_build_from_saved_schema ( self ) : <EOL> app = self . current_app <EOL> schema = CaseExportDataSchema . generate_schema_from_builds ( <EOL> app . domain , <EOL> self . case_type , <EOL> ) <EOL> self . assertEqual ( schema . last_app_versions [ app . _id ] , <NUM_LIT:3> ) <EOL> self . assertEqual ( len ( schema . group_schemas ) , <NUM_LIT:2> ) <EOL> second_build = Application . wrap ( self . get_json ( '<STR_LIT>' ) ) <EOL> second_build . _id = '<STR_LIT>' <EOL> second_build . copy_of = app . get_id <EOL> second_build . version = <NUM_LIT:6> <EOL> second_build . save ( ) <EOL> self . addCleanup ( second_build . delete ) <EOL> new_schema = CaseExportDataSchema . generate_schema_from_builds ( <EOL> app . domain , <EOL> self . case_type , <EOL> ) <EOL> self . assertEqual ( new_schema . _id , schema . _id ) <EOL> self . assertEqual ( new_schema . last_app_versions [ app . _id ] , <NUM_LIT:6> ) <EOL> self . assertEqual ( len ( new_schema . group_schemas ) , <NUM_LIT:2> ) <EOL> class TestBuildingParentCaseSchemaFromApplication ( TestCase , TestXmlMixin ) : <EOL> file_path = [ '<STR_LIT:data>' ] <EOL> root = os . path . dirname ( __file__ ) <EOL> domain = '<STR_LIT>' <EOL> case_type = '<STR_LIT>' <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . current_app = Application . wrap ( cls . get_json ( '<STR_LIT>' ) ) <EOL> cls . apps = [ <EOL> cls . current_app , <EOL> ] <EOL> for app in cls . apps : <EOL> app . save ( ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> for app in cls . apps : <EOL> app . delete ( ) <EOL> def tearDown ( self ) : <EOL> db = ExportDataSchema . get_db ( ) <EOL> for row in db . view ( '<STR_LIT>' , reduce = False ) : <EOL> doc_id = row [ '<STR_LIT:id>' ] <EOL> safe_delete ( db , doc_id ) <EOL> def test_parent_case_table_generation ( self ) : <EOL> """<STR_LIT>""" <EOL> schema = CaseExportDataSchema . generate_schema_from_builds ( self . domain , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( schema . group_schemas ) , <NUM_LIT:3> ) <EOL> main_table = filter ( lambda gs : gs . path == MAIN_TABLE , schema . group_schemas ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( <EOL> len ( filter ( lambda item : item . doc_type == '<STR_LIT>' , main_table . items ) ) , <EOL> <NUM_LIT:1> <EOL> ) <EOL> self . assertEqual ( <EOL> len ( filter ( lambda gs : gs . path == PARENT_CASE_TABLE , schema . group_schemas ) ) , <EOL> <NUM_LIT:1> <EOL> ) <EOL> def test_parent_case_table_generation_for_parent_case ( self ) : <EOL> """<STR_LIT>""" <EOL> schema = CaseExportDataSchema . generate_schema_from_builds ( self . domain , self . case_type ) <EOL> self . assertEqual ( len ( schema . group_schemas ) , <NUM_LIT:2> ) </s>
