Beispiel #1
0
    def to_representation(self, instance):
        request = self.context['request']
        data_url = request.build_absolute_uri(
            reverse('flow-results-responses', kwargs={'uuid': instance.uuid}))
        package = survey_to_floip_package(
            json.loads(instance.json), instance.uuid, instance.date_created,
            instance.date_modified, data_url)

        data = package.descriptor
        if data['profile'] != 'flow-results-package':
            data['profile'] = 'flow-results-package'

        return data
Beispiel #2
0
    def to_representation(self, instance):
        request = self.context['request']
        data_url = request.build_absolute_uri(
            reverse('flow-results-responses', kwargs={'uuid': instance.uuid}))
        package = survey_to_floip_package(
            json.loads(instance.json), instance.uuid, instance.date_created,
            instance.date_modified, data_url)

        data = package.descriptor
        if data['profile'] != 'flow-results-package':
            data['profile'] = 'flow-results-package'

        return data
Beispiel #3
0
def test_xform_to_floip_descriptor():
    """
    Test FloipSurvey - converting a flow result descriptor to an XForm xml.
    """
    survey = FloipSurvey('data/flow-results-example-1.json')
    with codecs.open('data/flow-results-example-1.xml') as xform_file:
        assert survey.xml() == xform_file.read()

    with codecs.open('data/flow-results-example-1.json') as descriptor_file:
        package = survey_to_floip_package(
            survey.survey_dict(), survey.descriptor['id'],
            survey.descriptor['created'], survey.descriptor['modified'],
            'data/flow-results-example-1-data.json')
        assert package.descriptor == json.load(descriptor_file)
        assert package.valid is True
Beispiel #4
0
def test_floip_descriptor_to_xform_questions_as_list():  # pylint: disable=C0103
    """
    Test FloipSurvey - converting a flow result descriptor to an XForm xml when
    resource questions is a list.
    """
    survey = FloipSurvey('data/flow-results-example-2.json')
    with codecs.open('data/flow-results-example-1.xml') as xform_file:
        assert survey.xml() == xform_file.read()

    with codecs.open('data/flow-results-example-1.json') as descriptor_file:
        package = survey_to_floip_package(
            survey.survey_dict(), survey.descriptor['id'],
            survey.descriptor['created'], survey.descriptor['modified'],
            'data/flow-results-example-1-data.json')
        assert package.descriptor == json.load(descriptor_file)
        assert package.valid is True