def test_can_delete_item(): field = ListField(list_type=StringField()) list = field.parse([]) list.append("Hello") list.append("World") list.append("Test") del list[2] assert [l for l in list] == ['Hello', 'World']
def test_list_get_accessor_returns_list_of_internal_values(): field = ListField(list_type=StringField()) value = FieldValue(field=field) value.set(["Hello", "World"]) assert list(value.get()) == ["Hello", "World"]
def test_list_str_representation(): field = ListField(list_type=StringField()) list = field.parse(['Hello', 'World']) assert str(list) == "['Hello', 'World']"
def test_can_replace_item(): field = ListField(list_type=StringField()) l = field.parse(['Hello', 'Wrong']) l[1] = 'World' assert list(l) == ['Hello', 'World']
def test_setters(input, expected_output): field = StringField() assert field.parse(input) == expected_output
class SimpleList(Model): list = ListField(list_type=StringField())
class Person(Model): first_name = StringField() last_name = StringField() contacts = ListField(list_type=ModelField(model_class=Contact))
class Contact(Model): name = StringField() number = StringField()