Пример #1
0
    def test_should_batch_get_form_models(self):
        fields = [ShortCodeField('name', 'eid', 'label')]
        form = EntityFormModel(
            self.manager,
            'test_form',
            'label',
            'form_code1',
            fields=fields,
            entity_type=['Clinic'],
            validators=[
                MandatoryValidator(),
                MobileNumberValidationsForReporterRegistrationValidator()
            ])
        form.save()

        fields = [ShortCodeField('name', 'eid', 'label')]
        form = EntityFormModel(
            self.manager,
            'test_form',
            'label',
            'form_code2',
            fields=fields,
            entity_type=['Clinic'],
            validators=[
                MandatoryValidator(),
                MobileNumberValidationsForReporterRegistrationValidator()
            ])
        form.save()

        forms = list_form_models_by_code(self.manager,
                                         ['form_code1', 'form_code2'])

        self.assertEqual(2, len(forms))
        self.assertEqual('form_code1', forms[0].form_code)
        self.assertEqual('form_code2', forms[1].form_code)
Пример #2
0
class FilePlayerTest(TestCase):

    fixtures = ['test_data.json']

    def setUp(self):
        organization = Organization.objects.get(pk=DEFAULT_TEST_ORG_ID)
        self.manager = utils.get_database_manager_for_org(organization)

    @attr('functional_test')
    def test_should_import_xls_file(self):
        self._init_xls_data()
        self._build_fixtures()

        with open(self.file_name) as f:
            response = FilePlayer(self.manager, self.parser,
                                  Channel.XLS).accept(file_contents=f.read())

        self.assertEqual([True, True, False, True, True],
                         [item.success for item in response])
        self._cleanup_xls_data()

    def _init_xls_data(self):
        self.parser = XlsParser()
        self.file_name = 'test.xls'
        wb = xlwt.Workbook()
        ws = wb.add_sheet('test')
        for row_number, row in enumerate(UPLOAD_DATA.split('\n')):
            for col_number, val in enumerate(row.split(',')):
                ws.write(row_number, col_number, val)
        wb.save(self.file_name)

    def _cleanup_xls_data(self):
        os.remove(self.file_name)

    def _build_fixtures(self):
        entity_type = ["clinic"]
        fields = []
        fields.append(IntegerField('beds', 'BEDS', 'beds label'))
        fields.append(IntegerField('meds', 'MEDS', 'meds label'))
        fields.append(TextField('doctor', 'DOCTOR', 'doctor label'))
        fields.append(ShortCodeField('clinic', 'ID', 'clinic label'))

        try:
            self.form_model = EntityFormModel(self.manager,
                                              entity_type=entity_type,
                                              name='form_model_name',
                                              label='form_model_label',
                                              form_code='clf12',
                                              fields=fields,
                                              is_registration_model=True)
            form_model_id = self.form_model.save()
            self.form_model = FormModel.get(self.manager, form_model_id)
        except DataObjectAlreadyExists:
            pass

        [
            EntityBuilder(self.manager, entity_type,
                          'cl00%d' % i).build().save() for i in range(1, 6)
        ]
Пример #3
0
 def test_should_save_form_model_with_validators(self):
     fields = [ShortCodeField('name', 'eid', 'label')]
     form = EntityFormModel(
         self.manager,
         'test_form',
         'label',
         'foo',
         fields=fields,
         entity_type=['Clinic'],
         validators=[
             MandatoryValidator(),
             MobileNumberValidationsForReporterRegistrationValidator()
         ])
     form.save()
     form = get_form_model_by_code(self.manager, 'foo')
     self.assertEqual(2, len(form.validators))
     self.assertTrue(isinstance(form.validators[0], MandatoryValidator))
     self.assertTrue(
         isinstance(
             form.validators[1],
             MobileNumberValidationsForReporterRegistrationValidator))
Пример #4
0
 def test_should_get_entity_form_model(self):
     entity_form_model = EntityFormModel(
         self.manager,
         name='entity_form_model',
         label='Entity Form Model',
         form_code='entity_form_code',
         fields=[TextField('name', 'code', 'label')],
         language="en",
         is_registration_model=True,
         enforce_unique_labels=True,
         entity_type=['clinic'])
     id = entity_form_model.save()
     saved_entity = EntityFormModel.get(self.manager, id)
     self.assertEquals(saved_entity.entity_type, ['clinic'])
Пример #5
0
    def _create_project(self):
        registration_form = construct_global_registration_form(self.manager)
        registration_form.save()

        self.check_uniqueness_patch = patch.object(
            Project, '_check_if_project_name_unique')
        self.check_uniqueness_patch.start()
        clinic_form_model = EntityFormModel(
            self.manager,
            name='clinic',
            label='Entity Form Model',
            form_code='clin',
            fields=[TextField('name', 'code', 'label')],
            language="en",
            is_registration_model=True,
            enforce_unique_labels=True,
            entity_type=['clinic'])
        clinic_form_model.save()

        hf_form_model = EntityFormModel(self.manager,
                                        name='health',
                                        label='Entity Form Model',
                                        form_code='hf1',
                                        fields=[
                                            TextField('name', 'code', 'label'),
                                            TextField('location', 'loc',
                                                      'Where is it?')
                                        ],
                                        language="en",
                                        is_registration_model=True,
                                        enforce_unique_labels=True,
                                        entity_type=['healthfacility'])
        hf_form_model.save()

        entity_type = ["HealthFacility", "Clinic"]
        question1 = UniqueIdField('clinic',
                                  name="entity_question",
                                  code="ID",
                                  label="What is associated Clinic")
        question2 = TextField(
            name="question1_Name",
            code="Q1",
            label="What is your name",
            defaultValue="some default value",
            constraints=[TextLengthConstraint(5, 10),
                         RegexConstraint("\w+")])
        question3 = IntegerField(
            name="Father's age",
            code="Q2",
            label="What is your Father's Age",
            constraints=[NumericRangeConstraint(min=15, max=120)])
        question4 = SelectField(name="Color",
                                code="Q3",
                                label="What is your favourite color",
                                options=[("RED", 'a'), ("YELLOW", 'b')])
        question5 = UniqueIdField('healthfacility',
                                  name="health facility",
                                  code="hf",
                                  label="For which HF is it?")
        fields = [question1, question2, question3, question4, question5]
        project = Project(self.manager,
                          name='test project',
                          form_code='test01',
                          fields=fields)

        project.save()
        return project