MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / test_list_assignment

Method test_list_assignment

tests/fields/test_fields.py:948–993  ·  view source on GitHub ↗

Ensure that list field element assignment and slicing work.

(self)

Source from the content-addressed store, hash-verified

946 assert blogLargeB.bool_info == [False, False, True, True]
947
948 def test_list_assignment(self):
949 """Ensure that list field element assignment and slicing work."""
950
951 class BlogPost(Document):
952 info = ListField()
953
954 BlogPost.drop_collection()
955
956 post = BlogPost()
957 post.info = ["e1", "e2", 3, "4", 5]
958 post.save()
959
960 post.info[0] = 1
961 post.save()
962 post.reload()
963 assert post.info[0] == 1
964
965 post.info[1:3] = ["n2", "n3"]
966 post.save()
967 post.reload()
968 assert post.info == [1, "n2", "n3", "4", 5]
969
970 post.info[-1] = "n5"
971 post.save()
972 post.reload()
973 assert post.info == [1, "n2", "n3", "4", "n5"]
974
975 post.info[-2] = 4
976 post.save()
977 post.reload()
978 assert post.info == [1, "n2", "n3", 4, "n5"]
979
980 post.info[1:-1] = [2]
981 post.save()
982 post.reload()
983 assert post.info == [1, 2, "n5"]
984
985 post.info[:-1] = [1, "n2", "n3", 4]
986 post.save()
987 post.reload()
988 assert post.info == [1, "n2", "n3", 4, "n5"]
989
990 post.info[-4:3] = [2, 3]
991 post.save()
992 post.reload()
993 assert post.info == [1, 2, 3, 4, "n5"]
994
995 def test_list_field_passed_in_value(self):
996 class Foo(Document):

Callers

nothing calls this directly

Calls 4

drop_collectionMethod · 0.80
reloadMethod · 0.80
BlogPostClass · 0.70
saveMethod · 0.45

Tested by

no test coverage detected