def generate_instance_from_schema(cls, schema, saved_export=None): """Given an ExportDataSchema, this will generate an ExportInstance""" if saved_export: instance = saved_export else: instance = cls._new_from_schema(schema) instance.name = instance.name or instance.defaults.get_default_instance_name(schema) latest_app_ids_and_versions = get_latest_built_app_ids_and_versions( schema.domain, getattr(schema, 'app_id', None), ) for group_schema in schema.group_schemas: table = instance.get_table(group_schema.path) or TableConfiguration( path=group_schema.path, label=instance.defaults.get_default_table_name(group_schema.path), selected=instance.defaults.default_is_table_selected(group_schema.path), ) columns = [] for item in group_schema.items: column = table.get_column(item.path) or ExportColumn.create_default_from_export_item( table.path, item, latest_app_ids_and_versions, ) # Ensure that the item is up to date column.item = item # Need to rebuild tags and other flags based on new build ids column.update_properties_from_app_ids_and_versions(latest_app_ids_and_versions) columns.append(column) table.columns = columns if not instance.get_table(group_schema.path): instance.tables.append(table) return instance
def test_get_latest_built_app_ids_and_versions_with_app_id(self): build_ids_and_versions = get_latest_built_app_ids_and_versions(self.domain, self.apps[0].get_id) self.assertEqual(build_ids_and_versions, { self.apps[0].get_id: 12, })