def test_should_return_date_format(self): field = DateField(name="What is the date?", code="dat", label="naam", date_format="dd/mm/yyyy") preview = helper.get_preview_for_field(field) self.assertEqual("dd/mm/yyyy", preview["constraints"])
def questionnaire_preview(request, project_id=None, sms_preview=False): manager = get_database_manager(request.user) if request.method == 'GET': dashboard_page = settings.HOME_PAGE + "?deleted=true" questionnaire = Project.get(manager, project_id) if questionnaire.is_void(): return HttpResponseRedirect(dashboard_page) #if form_model.is_entity_type_reporter(): # fields = helper.hide_entity_question(form_model.fields) project_links = make_project_links(questionnaire) questions = [] fields = questionnaire.fields for field in fields: question = helper.get_preview_for_field(field) questions.append(question) example_sms = "%s" % (questionnaire.form_code) example_sms += get_example_sms(fields) template = 'project/questionnaire_preview.html' if sms_preview else 'project/questionnaire_preview_list.html' return render_to_response( template, { "questions": questions, 'questionnaire_code': questionnaire.form_code, 'project': questionnaire, 'project_links': project_links, 'is_quota_reached': is_quota_reached(request), 'example_sms': example_sms, 'org_number': get_organization_telephone_number(request) }, context_instance=RequestContext(request))
def test_should_add_constraint_text_for_numeric_field_with_min(self): type = DataDictType(Mock(DatabaseManager), name="age type") constraint = NumericConstraint(min=10) field = IntegerField(name="What's in the age?", code="nam", label="naam", ddtype=type, range=constraint) preview = helper.get_preview_for_field(field) self.assertEqual("Minimum 10", preview["constraint"]) self.assertEqual("integer", preview["type"])
def test_should_return_choices(self): type = DataDictType(Mock(DatabaseManager), name="color type") field = SelectField(name="What's the color?", code="nam", label="naam", ddtype=type, options=[("Red", "a"), ("Green", "b"), ("Blue", "c")]) preview = helper.get_preview_for_field(field) self.assertEqual("select1", preview["type"]) self.assertEqual(["Red", "Green", "Blue"], preview["constraint"])
def test_should_add_constraint_text_for_numeric_field_with_max(self): constraint = NumericRangeConstraint(max=100) field = IntegerField(name="What's in the age?", code="nam", label="naam", constraints=[constraint]) preview = helper.get_preview_for_field(field) self.assertEqual("Upto 100", preview["constraints"])
def test_should_add_constraint_text_for_text_field_with_max(self): constraints = [TextLengthConstraint(max=100)] field = TextField(name="What's in a name?", code="nam", label="naam", constraints=constraints) preview = helper.get_preview_for_field(field) self.assertEqual("Upto 100 characters", preview["constraints"])
def test_should_create_basic_fields_in_preview(self): type = DataDictType(Mock(DatabaseManager), name="Name type") field = TextField(name="What's in a name?", code="nam", label="naam", ddtype=type, instruction="please write more tests") preview = helper.get_preview_for_field(field) self.assertEquals("What's in a name?", preview["description"]) self.assertEquals("nam", preview["code"]) self.assertEquals("text", preview["type"]) self.assertEquals("please write more tests", preview["instruction"])
def test_should_return_geocode_format(self): type = DataDictType(Mock(DatabaseManager), name="date type") field = GeoCodeField(name="What is the place?", code="dat", label="naam", ddtype=type) preview = helper.get_preview_for_field(field) self.assertEqual("xx.xxxx yy.yyyy", preview["constraints"])
def test_should_add_constraint_text_for_numeric_field_without_constraint( self): field = IntegerField( name="What's in the age?", code="nam", label="naam", ) preview = helper.get_preview_for_field(field) self.assertEqual("", preview["constraints"])
def test_should_return_choices_type_as_select(self): field = SelectField(name="What's the color?", code="nam", label="naam", options=[("Red", "a"), ("Green", "b"), ("Blue", "c")], single_select_flag=False) preview = helper.get_preview_for_field(field) self.assertEqual("select", preview["type"])
def test_should_return_date_format(self): type = DataDictType(Mock(DatabaseManager), name="date type") field = DateField(name="What is the date?", code="dat", label="naam", ddtype=type, date_format="dd/mm/yyyy") preview = helper.get_preview_for_field(field) self.assertEqual("dd/mm/yyyy", preview["constraints"])
def test_should_add_constraint_text_for_numeric_field_without_constraint( self): type = DataDictType(Mock(DatabaseManager), name="age type") field = IntegerField(name="What's in the age?", code="nam", label="naam", ddtype=type) preview = helper.get_preview_for_field(field) self.assertEqual("", preview["constraints"])
def test_should_create_basic_fields_in_preview(self): field = TextField(name="naam", code="nam", label="What's in a name?", instruction="please write more tests") preview = helper.get_preview_for_field(field) self.assertEquals("What's in a name?", preview["description"]) self.assertEquals("nam", preview["code"]) self.assertEquals("text", preview["type"]) self.assertEquals("please write more tests", preview["instruction"])
def test_should_add_constraint_text_for_numeric_field_with_max(self): type = DataDictType(Mock(DatabaseManager), name="age type") constraint = NumericRangeConstraint(max=100) field = IntegerField(name="What's in the age?", code="nam", label="naam", ddtype=type, constraints=[constraint]) preview = helper.get_preview_for_field(field) self.assertEqual("Upto 100", preview["constraints"])
def test_should_return_choices(self): field = SelectField(name="What's the color?", code="nam", label="naam", options=[("Red", "a"), ("Green", "b"), ("Blue", "c")]) preview = helper.get_preview_for_field(field) self.assertEqual("select1", preview["type"]) self.assertEqual([("Red", "a"), ("Green", "b"), ("Blue", "c")], preview["constraints"])
def test_should_add_constraint_text_for_text_field_with_max(self): type = DataDictType(Mock(DatabaseManager), name="Name type") constraints = [TextLengthConstraint(max=100)] field = TextField(name="What's in a name?", code="nam", label="naam", ddtype=type, constraints=constraints) preview = helper.get_preview_for_field(field) self.assertEqual("Upto 100 characters", preview["constraints"])
def questionnaire_preview(request, project_id=None, sms_preview=False): manager = get_database_manager(request.user) if request.method == 'GET': project = Project.load(manager.database, project_id) form_model = FormModel.get(manager, project.qid) fields = form_model.fields if form_model.is_entity_type_reporter(): fields = helper.hide_entity_question(form_model.fields) project_links = make_project_links(project, form_model.form_code) questions = [] for field in fields: question = helper.get_preview_for_field(field) questions.append(question) example_sms = "%s" % ( form_model.form_code) example_sms += get_example_sms(fields) template = 'project/questionnaire_preview.html' if sms_preview else 'project/questionnaire_preview_list.html' return render_to_response(template, {"questions": questions, 'questionnaire_code': form_model.form_code, 'project': project, 'project_links': project_links, 'is_quota_reached': is_quota_reached(request), 'example_sms': example_sms, 'org_number': get_organization_telephone_number(request)}, context_instance=RequestContext(request))
def test_should_add_constraint_text_for_text_field_without_constraint( self): field = TextField(name="What's in a name?", code="nam", label="naam") preview = helper.get_preview_for_field(field) self.assertEqual("", preview["constraints"])
def test_should_add_constraint_text_for_numeric_field_without_constraint(self): type = DataDictType(Mock(DatabaseManager), name="age type") field = IntegerField(name="What's in the age?", code="nam", label="naam", ddtype=type) preview = helper.get_preview_for_field(field) self.assertEqual("", preview["constraint"])
def get_questions(form_model): fields = form_model.fields if form_model.is_entity_type_reporter(): fields = hide_entity_question(form_model.fields) return [get_preview_for_field(field) for field in fields]
def test_should_add_constraint_text_for_text_field_with_max_and_min(self): type = DataDictType(Mock(DatabaseManager), name="Name type") constraint = TextConstraint(min=10, max=100) field = TextField(name="What's in a name?", code="nam", label="naam", ddtype=type, length=constraint) preview = helper.get_preview_for_field(field) self.assertEqual("Between 10 - 100 characters", preview["constraint"])
def test_should_return_date_format(self): type = DataDictType(Mock(DatabaseManager), name="date type") field = DateField(name="What is the date?", code="dat", label="naam", ddtype=type, date_format="dd/mm/yyyy") preview = helper.get_preview_for_field(field) self.assertEqual("dd/mm/yyyy", preview["constraint"])
def test_should_return_geocode_format(self): field = GeoCodeField(name="What is the place?", code="dat", label="naam") preview = helper.get_preview_for_field(field) self.assertEqual("xx.xxxx yy.yyyy", preview["constraints"])
def test_should_return_geocode_format(self): type = DataDictType(Mock(DatabaseManager), name="date type") field = GeoCodeField(name="What is the place?", code="dat", label="naam", ddtype=type) preview = helper.get_preview_for_field(field) self.assertEqual("xx.xxxx yy.yyyy", preview["constraint"])
def get_questions(form_model): fields = form_model.fields return [get_preview_for_field(field) for field in fields]