mirror of https://github.com/zulip/zulip.git
profile: Remove integer and float fields.
This commit is contained in:
parent
c473ce0919
commit
c30a282dd9
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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]]]
|
||||
|
|
|
@ -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 = []
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue