本文整理汇总了Python中onadata.libs.utils.export_tools.ExportBuilder.section_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python ExportBuilder.section_by_name方法的具体用法?Python ExportBuilder.section_by_name怎么用?Python ExportBuilder.section_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类onadata.libs.utils.export_tools.ExportBuilder
的用法示例。
在下文中一共展示了ExportBuilder.section_by_name方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_build_sections_from_survey
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import section_by_name [as 别名]
def test_build_sections_from_survey(self):
survey = self._create_childrens_survey()
export_builder = ExportBuilder()
export_builder.set_survey(survey)
# test that we generate the proper sections
expected_sections = [survey.name, "children", "children/cartoons", "children/cartoons/characters"]
self.assertEqual(expected_sections, [s["name"] for s in export_builder.sections])
# main section should have split geolocations
expected_element_names = [
"name",
"age",
"geo/geolocation",
"geo/_geolocation_longitude",
"geo/_geolocation_latitude",
"geo/_geolocation_altitude",
"geo/_geolocation_precision",
"tel/tel.office",
"tel/tel.mobile",
"meta/instanceID",
]
section = export_builder.section_by_name(survey.name)
element_names = [element["xpath"] for element in section["elements"]]
# fav_colors should have its choices split
self.assertEqual(sorted(expected_element_names), sorted(element_names))
expected_element_names = [
"children/name",
"children/age",
"children/fav_colors",
"children/fav_colors/red",
"children/fav_colors/blue",
"children/fav_colors/pink",
"children/ice.creams",
"children/ice.creams/vanilla",
"children/ice.creams/strawberry",
"children/ice.creams/chocolate",
]
section = export_builder.section_by_name("children")
element_names = [element["xpath"] for element in section["elements"]]
self.assertEqual(sorted(expected_element_names), sorted(element_names))
expected_element_names = ["children/cartoons/name", "children/cartoons/why"]
section = export_builder.section_by_name("children/cartoons")
element_names = [element["xpath"] for element in section["elements"]]
self.assertEqual(sorted(expected_element_names), sorted(element_names))
expected_element_names = ["children/cartoons/characters/name", "children/cartoons/characters/good_or_evil"]
section = export_builder.section_by_name("children/cartoons/characters")
element_names = [element["xpath"] for element in section["elements"]]
self.assertEqual(sorted(expected_element_names), sorted(element_names))
示例2: test_build_sections_from_survey
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import section_by_name [as 别名]
def test_build_sections_from_survey(self):
survey = self._create_childrens_survey()
export_builder = ExportBuilder()
export_builder.set_survey(survey)
# test that we generate the proper sections
expected_sections = [
survey.name, 'children', 'children/cartoons',
'children/cartoons/characters']
self.assertEqual(
expected_sections, [s['name'] for s in export_builder.sections])
# main section should have split geolocations
expected_element_names = [
'name', 'age', 'geo/geolocation', 'geo/_geolocation_longitude',
'geo/_geolocation_latitude', 'geo/_geolocation_altitude',
'geo/_geolocation_precision', 'tel/tel.office', 'tel/tel.mobile',
'meta/instanceID']
section = export_builder.section_by_name(survey.name)
element_names = [element['xpath'] for element in section['elements']]
# fav_colors should have its choices split
self.assertEqual(
sorted(expected_element_names), sorted(element_names))
expected_element_names = [
'children/name', 'children/age', 'children/fav_colors',
'children/fav_colors/red', 'children/fav_colors/blue',
'children/fav_colors/pink', 'children/ice.creams',
'children/ice.creams/vanilla', 'children/ice.creams/strawberry',
'children/ice.creams/chocolate']
section = export_builder.section_by_name('children')
element_names = [element['xpath'] for element in section['elements']]
self.assertEqual(
sorted(expected_element_names), sorted(element_names))
expected_element_names = [
'children/cartoons/name', 'children/cartoons/why']
section = export_builder.section_by_name('children/cartoons')
element_names = [element['xpath'] for element in section['elements']]
self.assertEqual(
sorted(expected_element_names), sorted(element_names))
expected_element_names = [
'children/cartoons/characters/name',
'children/cartoons/characters/good_or_evil']
section = \
export_builder.section_by_name('children/cartoons/characters')
element_names = [element['xpath'] for element in section['elements']]
self.assertEqual(
sorted(expected_element_names), sorted(element_names))
示例3: test_delimiter_replacement_works_existing_fields
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import section_by_name [as 别名]
def test_delimiter_replacement_works_existing_fields(self):
survey = self._create_childrens_survey()
export_builder = ExportBuilder()
export_builder.GROUP_DELIMITER = "."
export_builder.set_survey(survey)
expected_sections = [{"name": "children", "elements": [{"title": "children.name", "xpath": "children/name"}]}]
children_section = export_builder.section_by_name("children")
self.assertEqual(children_section["elements"][0]["title"], expected_sections[0]["elements"][0]["title"])
示例4: test_delimiter_replacement_works_for_generated_gps_fields
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import section_by_name [as 别名]
def test_delimiter_replacement_works_for_generated_gps_fields(self):
survey = self._create_childrens_survey()
export_builder = ExportBuilder()
export_builder.GROUP_DELIMITER = "."
export_builder.set_survey(survey)
expected_section = {
"name": "childrens_survey",
"elements": [{"title": "geo._geolocation_latitude", "xpath": "geo/_geolocation_latitude"}],
}
main_section = export_builder.section_by_name("childrens_survey")
match = filter(lambda x: (expected_section["elements"][0]["xpath"] == x["xpath"]), main_section["elements"])[0]
self.assertEqual(expected_section["elements"][0]["title"], match["title"])
示例5: test_delimiter_replacement_works_generated_multi_select_fields
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import section_by_name [as 别名]
def test_delimiter_replacement_works_generated_multi_select_fields(self):
survey = self._create_childrens_survey()
export_builder = ExportBuilder()
export_builder.GROUP_DELIMITER = "."
export_builder.set_survey(survey)
expected_section = {
"name": "children",
"elements": [{"title": "children.fav_colors.red", "xpath": "children/fav_colors/red"}],
}
childrens_section = export_builder.section_by_name("children")
match = filter(lambda x: expected_section["elements"][0]["xpath"] == x["xpath"], childrens_section["elements"])[
0
]
self.assertEqual(expected_section["elements"][0]["title"], match["title"])
示例6: test_delimiter_replacement_works_generated_multi_select_fields
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import section_by_name [as 别名]
def test_delimiter_replacement_works_generated_multi_select_fields(self):
survey = self._create_childrens_survey()
export_builder = ExportBuilder()
export_builder.GROUP_DELIMITER = "."
export_builder.set_survey(survey)
expected_section =\
{
'name': 'children',
'elements': [
{
'title': 'children.fav_colors.red',
'xpath': 'children/fav_colors/red'
}
]
}
childrens_section = export_builder.section_by_name('children')
match = filter(lambda x: expected_section['elements'][0]['xpath']
== x['xpath'], childrens_section['elements'])[0]
self.assertEqual(
expected_section['elements'][0]['title'], match['title'])
示例7: test_delimiter_replacement_works_for_generated_gps_fields
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import section_by_name [as 别名]
def test_delimiter_replacement_works_for_generated_gps_fields(self):
survey = self._create_childrens_survey()
export_builder = ExportBuilder()
export_builder.GROUP_DELIMITER = "."
export_builder.set_survey(survey)
expected_section = \
{
'name': 'childrens_survey',
'elements': [
{
'title': 'geo._geolocation_latitude',
'xpath': 'geo/_geolocation_latitude'
}
]
}
main_section = export_builder.section_by_name('childrens_survey')
match = filter(
lambda x: (expected_section['elements'][0]['xpath']
== x['xpath']), main_section['elements'])[0]
self.assertEqual(
expected_section['elements'][0]['title'], match['title'])
示例8: test_delimiter_replacement_works_existing_fields
# 需要导入模块: from onadata.libs.utils.export_tools import ExportBuilder [as 别名]
# 或者: from onadata.libs.utils.export_tools.ExportBuilder import section_by_name [as 别名]
def test_delimiter_replacement_works_existing_fields(self):
survey = self._create_childrens_survey()
export_builder = ExportBuilder()
export_builder.GROUP_DELIMITER = "."
export_builder.set_survey(survey)
expected_sections =\
[
{
'name': 'children',
'elements': [
{
'title': 'children.name',
'xpath': 'children/name'
}
]
}
]
children_section = export_builder.section_by_name('children')
self.assertEqual(
children_section['elements'][0]['title'],
expected_sections[0]['elements'][0]['title'])