diff --git a/zerver/migrations/0153_remove_int_float_custom_fields.py b/zerver/migrations/0153_remove_int_float_custom_fields.py new file mode 100644 index 0000000000..9bb601c95f --- /dev/null +++ b/zerver/migrations/0153_remove_int_float_custom_fields.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.6 on 2018-04-02 12:42 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('zerver', '0152_realm_default_twenty_four_hour_time'), + ] + + operations = [ + migrations.AlterField( + model_name='customprofilefield', + name='field_type', + field=models.PositiveSmallIntegerField(choices=[(1, 'Short Text'), (2, 'Long Text')], default=1), + ), + ] diff --git a/zerver/models.py b/zerver/models.py index a7a4a1fab1..a193106fe6 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -1868,15 +1868,11 @@ class CustomProfileField(models.Model): realm = models.ForeignKey(Realm, on_delete=CASCADE) # type: Realm name = models.CharField(max_length=100) # type: Text - INTEGER = 1 - FLOAT = 2 - SHORT_TEXT = 3 - LONG_TEXT = 4 + SHORT_TEXT = 1 + LONG_TEXT = 2 FIELD_TYPE_DATA = [ # Type, Name, Validator, Converter - (INTEGER, u'Integer', check_int, int), - (FLOAT, u'Float', check_float, float), (SHORT_TEXT, u'Short Text', check_short_string, str), (LONG_TEXT, u'Long Text', check_string, str), ] # type: List[Tuple[int, Text, Validator, Callable[[Any], Any]]] diff --git a/zerver/tests/test_custom_profile_data.py b/zerver/tests/test_custom_profile_data.py index 74fa009fe9..f5ecada423 100644 --- a/zerver/tests/test_custom_profile_data.py +++ b/zerver/tests/test_custom_profile_data.py @@ -126,40 +126,6 @@ class CustomProfileDataTest(ZulipTestCase): self.assert_json_error(result, u"Field id 1234 not found.") - def test_update_invalid_value(self) -> None: - self.login(self.example_email("iago")) - realm = get_realm('zulip') - age_field = try_add_realm_custom_profile_field( - realm, - u"age", - CustomProfileField.INTEGER - ) - - data = [{'id': age_field.id, 'value': 'text'}] - result = self.client_patch("/json/users/me/profile_data", { - 'data': ujson.dumps(data) - }) - self.assert_json_error( - result, - u"value[{}] is not an integer".format(age_field.id)) - - def test_update_invalid_double(self) -> None: - self.login(self.example_email("iago")) - realm = get_realm('zulip') - field = try_add_realm_custom_profile_field( - realm, - u"distance", - CustomProfileField.FLOAT - ) - - data = [{'id': field.id, 'value': 'text'}] - result = self.client_patch("/json/users/me/profile_data", { - 'data': ujson.dumps(data) - }) - self.assert_json_error( - result, - u"value[{}] is not a float".format(field.id)) - def test_update_invalid_short_text(self) -> None: self.login(self.example_email("iago")) realm = get_realm('zulip') @@ -183,7 +149,7 @@ class CustomProfileDataTest(ZulipTestCase): fields = [ ('Phone number', 'short text data'), ('Biography', 'long text data'), - ('Favorite integer', 1), + ('Favorite food', 'short text data'), ] data = [] diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py index 2e2aa8176d..6a89341696 100644 --- a/zilencer/management/commands/populate_db.py +++ b/zilencer/management/commands/populate_db.py @@ -256,20 +256,20 @@ class Command(BaseCommand): CustomProfileField.SHORT_TEXT) biography = try_add_realm_custom_profile_field(zulip_realm, "Biography", CustomProfileField.LONG_TEXT) - favorite_integer = try_add_realm_custom_profile_field(zulip_realm, "Favorite integer", - CustomProfileField.INTEGER) + favorite_food = try_add_realm_custom_profile_field(zulip_realm, "Favorite food", + CustomProfileField.SHORT_TEXT) # Fill in values for Iago and Hamlet hamlet = get_user("hamlet@zulip.com", zulip_realm) do_update_user_custom_profile_data(iago, [ {"id": phone_number.id, "value": "+1-234-567-8901"}, {"id": biography.id, "value": "Betrayer of Othello."}, - {"id": favorite_integer.id, "value": 17}, + {"id": favorite_food.id, "value": "Apples"}, ]) do_update_user_custom_profile_data(hamlet, [ {"id": phone_number.id, "value": "+0-11-23-456-7890"}, {"id": biography.id, "value": "Prince of Denmark, and other things!"}, - {"id": favorite_integer.id, "value": 12}, + {"id": favorite_food.id, "value": "Dark chocolate"}, ]) else: zulip_realm = get_realm("zulip")