def test_get_human_readable_type_null_boolean(self): with patch.object(SerialisableModel, "_get_field") as get_field: get_field.return_value = models.NullBooleanField() self.assertEqual( SerialisableModel.get_human_readable_type("tree"), "Either True, False or None", )
def test_get_human_readable_type_datetime_field(self): with patch.object(SerialisableModel, "_get_field") as get_field: get_field.return_value = models.DateTimeField() self.assertEqual( SerialisableModel.get_human_readable_type("tree"), "Date & Time", )
def test_build_field_schema(self): schema = SerialisableModel.build_field_schema() expected = [ { 'model': 'SerialisableModel', 'description': None, 'enum': None, 'lookup_list': None, 'type': 'string', 'name': 'pid', 'default': None, 'title': u'Pid' }, { 'model': 'SerialisableModel', 'description': None, 'enum': None, 'lookup_list': 'hat', 'type': 'string', 'name': 'hatty', 'default': None, 'title': 'Hatty' } ] self.assertEqual(schema, expected)
def test_get_fieldnames(self): names = SerialisableModel._get_fieldnames_to_serialize() expected = set([ 'id', 'pid', 'hatty', ]) self.assertEqual(expected, set(names))
def test_get_human_readable_type_numeric_field(self): numeric_fields = [ models.AutoField, models.BigIntegerField, models.IntegerField, models.FloatField, models.DecimalField ] for numeric_field in numeric_fields: with patch.object(SerialisableModel, "_get_field") as get_field: get_field.return_value = numeric_field() self.assertEqual( SerialisableModel.get_human_readable_type("tree"), "Number")
def test_get_human_readable_type_numeric_field(self): numeric_fields = [ models.AutoField, models.BigIntegerField, models.IntegerField, models.FloatField, models.DecimalField ] for numeric_field in numeric_fields: with patch.object(SerialisableModel, "_get_field") as get_field: get_field.return_value = numeric_field() self.assertEqual( SerialisableModel.get_human_readable_type("tree"), "Number" )
def test_get_field_type(self): self.assertEqual(models.ForeignKey, SerialisableModel._get_field_type('patient_id'))