def test_config_empty_datavalue_map(self):
        config = {
            'form_configs':
            json.dumps([{
                'xmlns': 'test_xmlns',
                'program_id': 'test program',
                'event_date': {
                    'doc_type': 'FormQuestion',
                    'form_question': '/data/event_date'
                },
                'event_status': 'COMPLETED',
                'org_unit_id': {
                    'doc_type': 'ConstantString',
                    'value': 'dhis2_location_id'
                },
                'datavalue_maps': [{}]
            }])
        }
        form = Dhis2ConfigForm(data=config)
        self.assertTrue(form.is_valid())

        repeater = Dhis2Repeater()
        repeater.dhis2_config = Dhis2Config.wrap(form.cleaned_data)
        with self.assertRaises(BadValueError) as e:
            repeater.save()
        self.assertEqual(str(e.exception),
                         "Property data_element_id is required.")
    def test_org_unit_id_migration(self):
        config = {
            'form_configs':
            json.dumps([{
                'xmlns':
                'test_xmlns',
                'program_id':
                'test program',
                'org_unit_id':
                'dhis2_location_id',
                'event_date': {
                    'doc_type': 'FormQuestion',
                    'form_question': '/data/event_date'
                },
                'datavalue_maps': [{
                    'data_element_id': 'dhis2_element_id',
                    'value': {
                        'doc_type': 'FormQuestion',
                        'form_question': '/data/example_question'
                    }
                }]
            }])
        }
        form = Dhis2ConfigForm(data=config)
        self.assertTrue(form.is_valid())

        repeater = Dhis2Repeater()
        repeater.dhis2_config = Dhis2Config.wrap(form.cleaned_data)
        repeater.save()
        org_unit_value_source = dict(
            repeater.dhis2_config.form_configs[0].org_unit_id)
        self.assertDictEqual(org_unit_value_source,
                             {'value': 'dhis2_location_id'})
 def test_empty_json(self):
     config = {'form_configs': [{}]}
     repeater = Dhis2Repeater()
     repeater.dhis2_config = Dhis2Config.wrap(config)
     with self.assertRaises(BadValueError) as e:
         repeater.save()
     self.assertEqual(str(e.exception), "Property xmlns is required.")
    def test_config_empty_datavalue_map(self):
        config = {
            'form_configs': json.dumps([{
                'xmlns': 'test_xmlns',
                'program_id': 'test program',
                'event_date': {
                    'doc_type': 'FormQuestion',
                    'form_question': '/data/event_date'
                },
                'event_status': 'COMPLETED',
                'org_unit_id': {
                    'doc_type': 'ConstantString',
                    'value': 'dhis2_location_id'
                },
                'datavalue_maps': [
                    {}
                ]
            }])
        }
        form = Dhis2ConfigForm(data=config)
        self.assertTrue(form.is_valid())

        repeater = Dhis2Repeater()
        repeater.dhis2_config = Dhis2Config.wrap(form.cleaned_data)
        with self.assertRaises(BadValueError) as e:
            repeater.save()
        self.assertEqual(
            six.text_type(e.exception),
            "Property data_element_id is required."
        )
    def test_full_config(self):
        config = {
            'form_configs':
            json.dumps([{
                'xmlns':
                'test_xmlns',
                'program_id':
                'test program',
                'event_date': {
                    'doc_type': 'FormQuestion',
                    'form_question': '/data/event_date'
                },
                'event_status':
                'COMPLETED',
                'org_unit_id': {
                    'doc_type': 'ConstantString',
                    'value': 'dhis2_location_id'
                },
                'datavalue_maps': [{
                    'data_element_id': 'dhis2_element_id',
                    'value': {
                        'doc_type': 'FormQuestion',
                        'form_question': '/data/example_question'
                    }
                }]
            }])
        }
        form = Dhis2ConfigForm(data=config)
        self.assertTrue(form.is_valid())

        repeater = Dhis2Repeater()
        repeater.dhis2_config = Dhis2Config.wrap(form.cleaned_data)
        repeater.save()
    def test_org_unit_id_migration(self):
        config = {
            'form_configs': json.dumps([{
                'program_id': 'test program',
                'org_unit_id': 'dhis2_location_id',
                'event_date': {
                    'doc_type': 'FormQuestion',
                    'form_question': '/data/event_date'
                },
                'datavalue_maps': [
                    {
                        'data_element_id': 'dhis2_element_id',
                        'value': {
                            'doc_type': 'FormQuestion',
                            'form_question': '/data/example_question'
                        }
                    }
                ]
            }])
        }
        form = Dhis2ConfigForm(data=config)
        self.assertTrue(form.is_valid())

        repeater = Dhis2Repeater()
        repeater.dhis2_config = Dhis2Config.wrap(form.cleaned_data)
        repeater.save()
        org_unit_value_source = dict(repeater.dhis2_config.form_configs[0].org_unit_id)
        self.assertDictEqual(org_unit_value_source, {
            'doc_type': 'ConstantString',
            'value': 'dhis2_location_id',
            'commcare_data_type': None,
            'external_data_type': None,
            'direction': None,
        })
    def test_minimal_config(self):
        config = {
            'form_configs': json.dumps([{
                'program_id': 'test program',
                'event_date': {
                    'doc_type': 'FormQuestion',
                    'form_question': '/data/event_date'
                },
                'datavalue_maps': [
                    {
                        'data_element_id': 'dhis2_element_id',
                        'value': {
                            'doc_type': 'FormQuestion',
                            'form_question': '/data/example_question'
                        }
                    }
                ]
            }])
        }
        form = Dhis2ConfigForm(data=config)
        self.assertTrue(form.is_valid())

        repeater = Dhis2Repeater()
        repeater.dhis2_config = Dhis2Config.wrap(form.cleaned_data)
        repeater.save()
    def test_full_config(self):
        config = {
            'form_configs': json.dumps([{
                'xmlns': 'test_xmlns',
                'program_id': 'test program',
                'event_date': {
                    'doc_type': 'FormQuestion',
                    'form_question': '/data/event_date'
                },
                'event_status': 'COMPLETED',
                'org_unit_id': {
                    'doc_type': 'ConstantString',
                    'value': 'dhis2_location_id'
                },
                'datavalue_maps': [
                    {
                        'data_element_id': 'dhis2_element_id',
                        'value': {
                            'doc_type': 'FormQuestion',
                            'form_question': '/data/example_question'
                        }
                    }
                ]
            }])
        }
        form = Dhis2ConfigForm(data=config)
        self.assertTrue(form.is_valid())

        repeater = Dhis2Repeater()
        repeater.dhis2_config = Dhis2Config.wrap(form.cleaned_data)
        repeater.save()
Exemple #9
0
    def test_minimal_config(self):
        config = {
            'form_configs':
            json.dumps([{
                'program_id':
                'test program',
                'event_date': {
                    'doc_type': 'FormQuestion',
                    'form_question': '/data/event_date'
                },
                'datavalue_maps': [{
                    'data_element_id': 'dhis2_element_id',
                    'value': {
                        'doc_type': 'FormQuestion',
                        'form_question': '/data/example_question'
                    }
                }]
            }])
        }
        form = Dhis2ConfigForm(data=config)
        self.assertTrue(form.is_valid())

        repeater = Dhis2Repeater()
        repeater.dhis2_config = Dhis2Config.wrap(form.cleaned_data)
        repeater.save()
Exemple #10
0
 def test_missing_event_date(self):
     config = {'form_configs': [{'program_id': 'test program'}]}
     repeater = Dhis2Repeater()
     repeater.dhis2_config = Dhis2Config.wrap(config)
     with self.assertRaises(BadValueError) as e:
         repeater.save()
     self.assertEqual(str(e.exception), 'Property event_date is required.')
 def test_empty_json(self):
     config = {
         'form_configs': [{}]
     }
     repeater = Dhis2Repeater()
     repeater.dhis2_config = Dhis2Config.wrap(config)
     with self.assertRaises(BadValueError) as e:
         repeater.save()
     self.assertEqual(
         six.text_type(e.exception),
         "Property program_id is required."
     )
 def test_missing_event_date(self):
     config = {
         'form_configs': [{
             'program_id': 'test program'
         }]
     }
     repeater = Dhis2Repeater()
     repeater.dhis2_config = Dhis2Config.wrap(config)
     with self.assertRaises(BadValueError) as e:
         repeater.save()
     self.assertEqual(
         six.text_type(e.exception),
         'Property event_date is required.'
     )