Skip to content

Commit bedc002

Browse files
committed
PYTHON-2548 Add update description.truncated arrays field (#572)
(cherry picked from commit 4088c1c)
1 parent 621c90c commit bedc002

File tree

6 files changed

+126
-5
lines changed

6 files changed

+126
-5
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"description": "change-streams",
3+
"schemaVersion": "1.0",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
},
10+
{
11+
"database": {
12+
"id": "database0",
13+
"client": "client0",
14+
"databaseName": "database0"
15+
}
16+
},
17+
{
18+
"collection": {
19+
"id": "collection0",
20+
"database": "database0",
21+
"collectionName": "collection0"
22+
}
23+
}
24+
],
25+
"initialData": [
26+
{
27+
"collectionName": "collection0",
28+
"databaseName": "database0",
29+
"documents": []
30+
}
31+
],
32+
"tests": [
33+
{
34+
"description": "Test array truncation",
35+
"runOnRequirements": [
36+
{
37+
"minServerVersion": "4.7",
38+
"topologies": [
39+
"replicaset"
40+
]
41+
}
42+
],
43+
"operations": [
44+
{
45+
"name": "insertOne",
46+
"object": "collection0",
47+
"arguments": {
48+
"document": {
49+
"_id": 1,
50+
"a": 1,
51+
"array": [
52+
"foo",
53+
{
54+
"a": "bar"
55+
},
56+
1,
57+
2,
58+
3
59+
]
60+
}
61+
}
62+
},
63+
{
64+
"name": "createChangeStream",
65+
"object": "collection0",
66+
"arguments": {
67+
"pipeline": []
68+
},
69+
"saveResultAsEntity": "changeStream0"
70+
},
71+
{
72+
"name": "updateOne",
73+
"object": "collection0",
74+
"arguments": {
75+
"filter": {
76+
"_id": 1
77+
},
78+
"update": [
79+
{
80+
"$set": {
81+
"array": [
82+
"foo",
83+
{
84+
"a": "bar"
85+
}
86+
]
87+
}
88+
}
89+
]
90+
}
91+
},
92+
{
93+
"name": "iterateUntilDocumentOrError",
94+
"object": "changeStream0",
95+
"expectResult": {
96+
"operationType": "update",
97+
"ns": {
98+
"db": "database0",
99+
"coll": "collection0"
100+
},
101+
"updateDescription": {
102+
"updatedFields": {},
103+
"removedFields": [],
104+
"truncatedArrays": [
105+
{
106+
"field": "array",
107+
"newSize": 2
108+
}
109+
]
110+
}
111+
}
112+
}
113+
]
114+
}
115+
]
116+
}

test/test_change_stream.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from pymongo.write_concern import WriteConcern
4646

4747
from test import client_context, unittest, IntegrationTest
48+
from test.unified_format import generate_test_classes
4849
from test.utils import (
4950
EventListener, WhiteListEventListener, rs_or_single_client, wait_until)
5051

@@ -1039,7 +1040,7 @@ def test_read_concern(self):
10391040
pass
10401041

10411042

1042-
class TestAllScenarios(unittest.TestCase):
1043+
class TestAllLegacyScenarios(unittest.TestCase):
10431044

10441045
@classmethod
10451046
@client_context.require_connection
@@ -1122,8 +1123,7 @@ def tearDown(self):
11221123

11231124

11241125
_TEST_PATH = os.path.join(
1125-
os.path.dirname(os.path.realpath(__file__)), 'change_streams'
1126-
)
1126+
os.path.dirname(os.path.realpath(__file__)), 'change_streams')
11271127

11281128

11291129
def camel_to_snake(camel):
@@ -1217,7 +1217,7 @@ def run_scenario(self):
12171217

12181218

12191219
def create_tests():
1220-
for dirpath, _, filenames in os.walk(_TEST_PATH):
1220+
for dirpath, _, filenames in os.walk(os.path.join(_TEST_PATH, 'legacy')):
12211221
dirname = os.path.split(dirpath)[-1]
12221222

12231223
for filename in filenames:
@@ -1253,11 +1253,16 @@ def create_tests():
12531253
str(test['description'].replace(" ", "_")))
12541254

12551255
new_test.__name__ = test_name
1256-
setattr(TestAllScenarios, new_test.__name__, new_test)
1256+
setattr(TestAllLegacyScenarios, new_test.__name__, new_test)
12571257

12581258

12591259
create_tests()
12601260

12611261

1262+
globals().update(generate_test_classes(
1263+
os.path.join(_TEST_PATH, 'unified'),
1264+
module=__name__,))
1265+
1266+
12621267
if __name__ == '__main__':
12631268
unittest.main()

0 commit comments

Comments
 (0)