diff --git a/xblock/fields.py b/xblock/fields.py index a44afd3..d9f672a 100644 --- a/xblock/fields.py +++ b/xblock/fields.py @@ -808,19 +808,11 @@ class String(JSONField): MUTABLE = False def from_json(self, value): - if value is None: - return '' - elif isinstance(value, basestring): + if value is None or isinstance(value, basestring): return value else: raise TypeError('Value stored in a String must be None or a string, found %s' % type(value)) - def to_json(self, value): - if value is None: - return '' - self._warn_deprecated_outside_JSONField() - return value - def from_string(self, value): """String gets serialized and deserialized without quote marks.""" return self.from_json(value) diff --git a/xblock/test/test_fields.py b/xblock/test/test_fields.py index 67d0a46..2e5cbc2 100644 --- a/xblock/test/test_fields.py +++ b/xblock/test/test_fields.py @@ -212,14 +212,7 @@ def test_json_equals(self): self.assertJSONOrSetEquals('', '') def test_none(self): - # test for NoneType for to_string and from_string methods - test_field = String(enforce_type=True) - - result_to_string = test_field.to_string(None) - self.assertEquals(result_to_string, '') - - result_from_string = test_field.from_string(None) - self.assertEquals(result_from_string, '') + self.assertJSONOrSetEquals(None, None) def test_error(self): self.assertJSONOrSetTypeError(['a'])