def test_project_name_should_be_case_insensitively_unique(self): questionnaire = Project(self.manager, name=project2_name.upper(), goals="Testing", devices=['web']) with self.assertRaises(Exception) as cm: questionnaire.save() the_exception = cm.exception self.assertEqual( the_exception.message, "Questionnaire with Name = '%s' already exists." % project2_name.upper())
def test_project_name_should_be_unique(self): questionnaire = Project(dbm=self.manager, name=project2_name, goals="Testing", devices=['web'], form_code="name_form", fields=[]) with self.assertRaises(Exception) as cm: questionnaire.save() the_exception = cm.exception self.assertEqual( the_exception.message, "Questionnaire with Name = '%s' already exists." % project2_name)
def test_get_associated_data_senders(self): contact = Contact(self.manager, entity_type=["reporter"], short_code="rep1") entity_id = contact.save() project = Project(dbm=self.manager, name="TestDS", goals="Testing", devices=['web'], form_code="ds_form", fields=[]) project.data_senders = ["rep1"] project.save() result = project.get_associated_datasenders(self.manager) self.assertEquals(result[0].short_code, contact.short_code) self.assertEquals(result[0].id, entity_id)
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