Ensure that list field element assignment and slicing work.
(self)
| 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): |
nothing calls this directly
no test coverage detected