# Path: pyxform/builder.py
# def create_survey_element_from_dict(self, d):
#     """
#     Convert from a nested python dictionary/array structure (a json dict I
#     call it because it corresponds directly with a json object)
#     to a survey object
#     """
#     if "add_none_option" in d:
#         self._add_none_option = d["add_none_option"]
#     if d["type"] in self.SECTION_CLASSES:
#         section = self._create_section_from_dict(d)
# 
#         if d["type"] == "survey":
#             section.setvalues_by_triggering_ref = self.setvalues_by_triggering_ref
# 
#         return section
#     elif d["type"] == "loop":
#         return self._create_loop_from_dict(d)
#     elif d["type"] == "include":
#         section_name = d["name"]
#         if section_name not in self._sections:
#             raise PyXFormError(
#                 "This section has not been included.",
#                 section_name,
#                 self._sections.keys(),
#             )
#         d = self._sections[section_name]
#         full_survey = self.create_survey_element_from_dict(d)
#         return full_survey.children
#     elif d["type"] in ["xml-external", "csv-external"]:
#         return ExternalInstance(**d)
#     else:
#         self._save_trigger_as_setvalue_and_remove_calculate(d)
# 
#         return self._create_question_from_dict(
#             d, copy_json_dict(QUESTION_TYPE_DICT), self._add_none_option
#         )


from unittest import TestCase
from pyxform.builder import create_survey_element_from_dict
# -*- coding: utf-8 -*-
"""
Testing our ability to import from a JSON text file.
"""



class Json2XformTestJsonImport(TestCase):
    def test_simple_questions_can_be_imported_from_json(self):
        json_text = {
            "type": "survey",
            "name": "Exchange rate",
            "children": [
                {
                    "label": {"French": "Combien?", "English": "How many?"},
                    "type": "decimal",
                    "name": "exchange_rate",
                }
            ],
        }

# Path: pyxform/builder.py
# def create_survey_element_from_dict(self, d):
#     """
#     Convert from a nested python dictionary/array structure (a json dict I
#     call it because it corresponds directly with a json object)
#     to a survey object
#     """
#     if "add_none_option" in d:
#         self._add_none_option = d["add_none_option"]
#     if d["type"] in self.SECTION_CLASSES:
#         section = self._create_section_from_dict(d)
# 
#         if d["type"] == "survey":
#             section.setvalues_by_triggering_ref = self.setvalues_by_triggering_ref
# 
#         return section
#     elif d["type"] == "loop":
#         return self._create_loop_from_dict(d)
#     elif d["type"] == "include":
#         section_name = d["name"]
#         if section_name not in self._sections:
#             raise PyXFormError(
#                 "This section has not been included.",
#                 section_name,
#                 self._sections.keys(),
#             )
#         d = self._sections[section_name]
#         full_survey = self.create_survey_element_from_dict(d)
#         return full_survey.children
#     elif d["type"] in ["xml-external", "csv-external"]:
#         return ExternalInstance(**d)
#     else:
#         self._save_trigger_as_setvalue_and_remove_calculate(d)
# 
#         return self._create_question_from_dict(
#             d, copy_json_dict(QUESTION_TYPE_DICT), self._add_none_option
#         )


# Path: tests/js2x_test_import_from_json.py
from unittest import TestCase
from pyxform.builder import create_survey_element_from_dict

# -*- coding: utf-8 -*-
"""
Testing our ability to import from a JSON text file.
"""



class Json2XformTestJsonImport(TestCase):
    def test_simple_questions_can_be_imported_from_json(self):
        json_text = {
            "type": "survey",
            "name": "Exchange rate",
            "children": [
                {
                    "label": {"French": "Combien?", "English": "How many?"},
                    "type": "decimal",
                    "name": "exchange_rate",
                }
            ],
        }

        s = create_survey_element_from_dict(json_text)