Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder case properties for bulk case export #34743

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions corehq/apps/export/models/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -2358,15 +2358,17 @@ def get_latest_export_schema(domain, app_id, case_type):
return get_latest_case_export_schema(domain, case_type)

@classmethod
def _process_app_build(cls, current_schema, app, case_type, for_new_export_instance=False):
def _process_app_build(cls, current_schema, app, case_type, for_new_export_instance=False,
for_bulk_export=False):
builder = ParentCasePropertyBuilder(
app.domain,
[app],
include_parent_properties=False
)
case_property_mapping = builder.get_case_property_map([case_type])

if for_new_export_instance and domain_has_privilege(app.domain, privileges.DATA_DICTIONARY):
if ((for_bulk_export or for_new_export_instance)
and domain_has_privilege(app.domain, privileges.DATA_DICTIONARY)):
case_property_mapping[case_type] = cls._reorder_case_properties_from_data_dictionary(
app.domain, case_type, case_property_mapping[case_type]
)
Expand Down Expand Up @@ -2546,6 +2548,7 @@ def _process_apps_for_bulk_export(cls, domain, schema, app_build_ids, task):
case_type_schema,
app,
case_type,
for_bulk_export=True,
)
except Exception as e:
logging.exception('Failed to process app {}. {}'.format(app._id, e))
Expand Down
35 changes: 32 additions & 3 deletions corehq/apps/export/tests/test_export_data_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,15 +1357,15 @@ def test_different_doc_types_ordering(self):
)


class TestOrderingOfCaseSchemaItemsFromDataDictionary(TestCase, TestXmlMixin):
class BaseTestOrderingOfCaseSchemaItems(TestCase, TestXmlMixin):
file_path = ['data']
root = os.path.dirname(__file__)
case_type = 'person'
domain = 'test-domain'

@classmethod
def setUpClass(cls):
super(TestOrderingOfCaseSchemaItemsFromDataDictionary, cls).setUpClass()
super(BaseTestOrderingOfCaseSchemaItems, cls).setUpClass()

factory = AppFactory(domain=cls.domain)
module1, form1 = factory.new_basic_module('update_case', cls.case_type)
Expand Down Expand Up @@ -1405,12 +1405,17 @@ def setUpClass(cls):
@classmethod
def tearDownClass(cls):
cls.current_app.delete()
super(TestOrderingOfCaseSchemaItemsFromDataDictionary, cls).tearDownClass()
super(BaseTestOrderingOfCaseSchemaItems, cls).tearDownClass()

def _get_schema_item_order(self, for_new_export_instance=True):
schema = self._generate_schema(for_new_export_instance=for_new_export_instance)
return [item.label for item in schema.group_schemas[0].items]

def _generate_schema(self):
raise NotImplementedError


class TestOrderingOfCaseSchemaItemsFromDataDictionary(BaseTestOrderingOfCaseSchemaItems):
def _generate_schema(self, for_new_export_instance=True):
return CaseExportDataSchema.generate_schema_from_builds(
self.domain,
Expand Down Expand Up @@ -1457,3 +1462,27 @@ def test_ordering_for_new_instance_with_feature_flag(self, *args):
self._get_schema_item_order(),
['weight', 'height', 'address', 'age']
)


class TestOrderingOfBulkCaseExportSchemaItemsFromDataDictionary(BaseTestOrderingOfCaseSchemaItems):
def _generate_schema(self, **kwargs):
return CaseExportDataSchema.generate_schema_from_builds(
self.domain,
None,
ALL_CASE_TYPE_EXPORT,
)

def test_default_ordering(self, *args):
with patch('corehq.apps.export.models.new.get_case_types_for_domain', return_value=(self.case_type,)):
self.assertListEqual(
self._get_schema_item_order(),
['address', 'age', 'height', 'weight']
)

@patch('corehq.apps.export.models.new.domain_has_privilege', return_value=True)
def test_ordering_for_bulk_export_with_feature_flag(self, *args):
with patch('corehq.apps.export.models.new.get_case_types_for_domain', return_value=(self.case_type,)):
self.assertListEqual(
self._get_schema_item_order(),
['weight', 'height', 'address', 'age']
)
Loading