Skip to content

Commit 4088c1c

Browse files
Python 2548/add update description.truncated arrays field (#572)
1 parent 20d5a9c commit 4088c1c

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
@@ -43,6 +43,7 @@
4343
from pymongo.write_concern import WriteConcern
4444

4545
from test import client_context, unittest, IntegrationTest
46+
from test.unified_format import generate_test_classes
4647
from test.utils import (
4748
EventListener, WhiteListEventListener, rs_or_single_client, wait_until)
4849

@@ -1037,7 +1038,7 @@ def test_read_concern(self):
10371038
pass
10381039

10391040

1040-
class TestAllScenarios(unittest.TestCase):
1041+
class TestAllLegacyScenarios(unittest.TestCase):
10411042

10421043
@classmethod
10431044
@client_context.require_connection
@@ -1120,8 +1121,7 @@ def tearDown(self):
11201121

11211122

11221123
_TEST_PATH = os.path.join(
1123-
os.path.dirname(os.path.realpath(__file__)), 'change_streams'
1124-
)
1124+
os.path.dirname(os.path.realpath(__file__)), 'change_streams')
11251125

11261126

11271127
def camel_to_snake(camel):
@@ -1215,7 +1215,7 @@ def run_scenario(self):
12151215

12161216

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

12211221
for filename in filenames:
@@ -1251,11 +1251,16 @@ def create_tests():
12511251
str(test['description'].replace(" ", "_")))
12521252

12531253
new_test.__name__ = test_name
1254-
setattr(TestAllScenarios, new_test.__name__, new_test)
1254+
setattr(TestAllLegacyScenarios, new_test.__name__, new_test)
12551255

12561256

12571257
create_tests()
12581258

12591259

1260+
globals().update(generate_test_classes(
1261+
os.path.join(_TEST_PATH, 'unified'),
1262+
module=__name__,))
1263+
1264+
12601265
if __name__ == '__main__':
12611266
unittest.main()

0 commit comments

Comments
 (0)