# Path: tests/fixtures/build_fixture.py
# def build_fixture(modulename, data_variable_name='DATA'):
#     fixtures = deepcopy(
#         getattr(
#             importlib.import_module('..%s' % modulename, __name__),
#             data_variable_name,
#         )
#     )
# 
#     if 'submissions_xml' in fixtures:
#         # This fixture contains XML submissions, which apparently aren't used
#         # for anything yet; see
#         # `TestFormPackFixtures.test_xml_instances_loaded()`.
#         # Example XML fixture: tests/fixtures/favcolor/xml_instances.json
#         return fixtures
# 
#     title = fixtures.get('title')
# 
#     # separate the submissions from the schema
#     schemas = [dict(v) for v in fixtures['versions']]
#     submissions = []
#     for schema in schemas:
#         version = schema.get('version')
#         version_id_key = schema.get('version_id_key', '__version__')
#         for submission in schema.pop('submissions'):
#             submission.update({version_id_key: version})
#             submissions.append(submission)
#     return title, schemas, submissions


import unittest
from formpack import FormPack
from .fixtures import build_fixture
# coding: utf-8



class TestFormPackFixtures(unittest.TestCase):
    maxDiff = None

    def _reimport(self, fd):
        fd2 = FormPack(**fd.to_dict())
        return fd2

    def test_sanitation_report(self):
        """
        sanitation_report
        """
        title, schemas, submissions = build_fixture('sanitation_report')
        fp = FormPack(schemas, title)
        self.assertEqual(len(fp.versions), 1)
        v0 = fp[0]
        self.assertEqual(
            list(v0.sections['Sanitation report'].fields.keys()),
            ['restaurant_name', 'restaurant_rating', 'report_date'],
        )

    def test_grouped_questions(self):
        """
        questions groups
        """

# Path: tests/fixtures/build_fixture.py
# def build_fixture(modulename, data_variable_name='DATA'):
#     fixtures = deepcopy(
#         getattr(
#             importlib.import_module('..%s' % modulename, __name__),
#             data_variable_name,
#         )
#     )
# 
#     if 'submissions_xml' in fixtures:
#         # This fixture contains XML submissions, which apparently aren't used
#         # for anything yet; see
#         # `TestFormPackFixtures.test_xml_instances_loaded()`.
#         # Example XML fixture: tests/fixtures/favcolor/xml_instances.json
#         return fixtures
# 
#     title = fixtures.get('title')
# 
#     # separate the submissions from the schema
#     schemas = [dict(v) for v in fixtures['versions']]
#     submissions = []
#     for schema in schemas:
#         version = schema.get('version')
#         version_id_key = schema.get('version_id_key', '__version__')
#         for submission in schema.pop('submissions'):
#             submission.update({version_id_key: version})
#             submissions.append(submission)
#     return title, schemas, submissions


# Path: tests/test_fixtures_valid.py
import unittest
from formpack import FormPack
from .fixtures import build_fixture

# coding: utf-8



class TestFormPackFixtures(unittest.TestCase):
    maxDiff = None

    def _reimport(self, fd):
        fd2 = FormPack(**fd.to_dict())
        return fd2

    def test_sanitation_report(self):
        """
        sanitation_report
        """
        title, schemas, submissions = build_fixture('sanitation_report')
        fp = FormPack(schemas, title)
        self.assertEqual(len(fp.versions), 1)
        v0 = fp[0]
        self.assertEqual(
            list(v0.sections['Sanitation report'].fields.keys()),
            ['restaurant_name', 'restaurant_rating', 'report_date'],
        )

    def test_grouped_questions(self):
        """
        questions groups
        """

        title, schemas, submissions = build_fixture('grouped_questions')