Skip to content

Commit 6872730

Browse files
committed
PYTHON-4925 Fix test bugs in $$matchAsDocument and $$matchAsRoot
1 parent 32269aa commit 6872730

File tree

7 files changed

+534
-13
lines changed

7 files changed

+534
-13
lines changed

test/unified-test-format/invalid/runOnRequirement-authMechanism-type.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
"tests": [
1010
{
1111
"description": "foo",
12-
"operations": [
13-
14-
]
12+
"operations": []
1513
}
1614
]
1715
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"description": "operator-matchAsDocument",
3+
"schemaVersion": "1.13",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
},
10+
{
11+
"database": {
12+
"id": "database0",
13+
"client": "client0",
14+
"databaseName": "test"
15+
}
16+
},
17+
{
18+
"collection": {
19+
"id": "collection0",
20+
"database": "database0",
21+
"collectionName": "coll0"
22+
}
23+
}
24+
],
25+
"initialData": [
26+
{
27+
"collectionName": "coll0",
28+
"databaseName": "test",
29+
"documents": [
30+
{
31+
"_id": 1,
32+
"json": "{ \"x\": 1, \"y\": 2 }"
33+
},
34+
{
35+
"_id": 2,
36+
"json": "{ \"x\" }"
37+
}
38+
]
39+
}
40+
],
41+
"tests": [
42+
{
43+
"description": "matchAsDocument with non-matching filter",
44+
"operations": [
45+
{
46+
"name": "find",
47+
"object": "collection0",
48+
"arguments": {
49+
"filter": {
50+
"_id": 1
51+
},
52+
"limit": 1
53+
},
54+
"expectResult": [
55+
{
56+
"_id": 1,
57+
"json": {
58+
"$$matchAsDocument": {
59+
"x": 1,
60+
"y": "two"
61+
}
62+
}
63+
}
64+
]
65+
}
66+
]
67+
},
68+
{
69+
"description": "matchAsDocument evaluates special operators",
70+
"operations": [
71+
{
72+
"name": "find",
73+
"object": "collection0",
74+
"arguments": {
75+
"filter": {
76+
"_id": 1
77+
},
78+
"limit": 1
79+
},
80+
"expectResult": [
81+
{
82+
"_id": 1,
83+
"json": {
84+
"$$matchAsDocument": {
85+
"x": 1,
86+
"y": {
87+
"$$exists": false
88+
}
89+
}
90+
}
91+
}
92+
]
93+
}
94+
]
95+
},
96+
{
97+
"description": "matchAsDocument does not permit extra fields",
98+
"operations": [
99+
{
100+
"name": "find",
101+
"object": "collection0",
102+
"arguments": {
103+
"filter": {
104+
"_id": 1
105+
},
106+
"limit": 1
107+
},
108+
"expectResult": [
109+
{
110+
"_id": 1,
111+
"json": {
112+
"$$matchAsDocument": {
113+
"x": 1
114+
}
115+
}
116+
}
117+
]
118+
}
119+
]
120+
},
121+
{
122+
"description": "matchAsDocument fails to decode Extended JSON",
123+
"operations": [
124+
{
125+
"name": "find",
126+
"object": "collection0",
127+
"arguments": {
128+
"filter": {
129+
"_id": 2
130+
},
131+
"limit": 1
132+
},
133+
"expectResult": [
134+
{
135+
"_id": 2,
136+
"json": {
137+
"$$matchAsDocument": {
138+
"x": 1
139+
}
140+
}
141+
}
142+
]
143+
}
144+
]
145+
}
146+
]
147+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"description": "operator-matchAsRoot",
3+
"schemaVersion": "1.13",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
},
10+
{
11+
"database": {
12+
"id": "database0",
13+
"client": "client0",
14+
"databaseName": "test"
15+
}
16+
},
17+
{
18+
"collection": {
19+
"id": "collection0",
20+
"database": "database0",
21+
"collectionName": "coll0"
22+
}
23+
}
24+
],
25+
"initialData": [
26+
{
27+
"collectionName": "coll0",
28+
"databaseName": "test",
29+
"documents": [
30+
{
31+
"_id": 1,
32+
"x": {
33+
"y": 2,
34+
"z": 3
35+
}
36+
},
37+
{
38+
"_id": 2,
39+
"x": "{ \"x\": 1, \"y\": 2.0 }"
40+
}
41+
]
42+
}
43+
],
44+
"tests": [
45+
{
46+
"description": "matchAsRoot with nested document",
47+
"operations": [
48+
{
49+
"name": "find",
50+
"object": "collection0",
51+
"arguments": {
52+
"filter": {
53+
"_id": 1
54+
},
55+
"limit": 1
56+
},
57+
"expectResult": [
58+
{
59+
"_id": 1,
60+
"x": {
61+
"$$matchAsRoot": {
62+
"y": 3
63+
}
64+
}
65+
}
66+
]
67+
}
68+
]
69+
},
70+
{
71+
"description": "matchAsRoot with matchAsDocument",
72+
"operations": [
73+
{
74+
"name": "find",
75+
"object": "collection0",
76+
"arguments": {
77+
"filter": {
78+
"_id": 1
79+
},
80+
"limit": 1
81+
},
82+
"expectResult": [
83+
{
84+
"_id": 2,
85+
"x": {
86+
"$$matchAsDocument": {
87+
"$$matchAsRoot": {
88+
"x": 1
89+
}
90+
}
91+
}
92+
}
93+
]
94+
}
95+
]
96+
}
97+
]
98+
}

test/unified-test-format/valid-pass/matches-lte-operator.json renamed to test/unified-test-format/valid-pass/operator-lte.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "matches-lte-operator",
2+
"description": "operator-lte",
33
"schemaVersion": "1.9",
44
"createEntities": [
55
{
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"description": "operator-matchAsDocument",
3+
"schemaVersion": "1.13",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
},
10+
{
11+
"database": {
12+
"id": "database0",
13+
"client": "client0",
14+
"databaseName": "test"
15+
}
16+
},
17+
{
18+
"collection": {
19+
"id": "collection0",
20+
"database": "database0",
21+
"collectionName": "coll0"
22+
}
23+
}
24+
],
25+
"initialData": [
26+
{
27+
"collectionName": "coll0",
28+
"databaseName": "test",
29+
"documents": [
30+
{
31+
"_id": 1,
32+
"json": "{ \"x\": 1, \"y\": 2.0 }"
33+
},
34+
{
35+
"_id": 2,
36+
"json": "{ \"x\": { \"$oid\": \"57e193d7a9cc81b4027498b5\" } }"
37+
}
38+
]
39+
}
40+
],
41+
"tests": [
42+
{
43+
"description": "matchAsDocument performs flexible numeric comparisons",
44+
"operations": [
45+
{
46+
"name": "find",
47+
"object": "collection0",
48+
"arguments": {
49+
"filter": {
50+
"_id": 1
51+
},
52+
"limit": 1
53+
},
54+
"expectResult": [
55+
{
56+
"_id": 1,
57+
"json": {
58+
"$$matchAsDocument": {
59+
"x": 1,
60+
"y": 2
61+
}
62+
}
63+
}
64+
]
65+
}
66+
]
67+
},
68+
{
69+
"description": "matchAsDocument evaluates special operators",
70+
"operations": [
71+
{
72+
"name": "find",
73+
"object": "collection0",
74+
"arguments": {
75+
"filter": {
76+
"_id": 1
77+
},
78+
"limit": 1
79+
},
80+
"expectResult": [
81+
{
82+
"_id": 1,
83+
"json": {
84+
"$$matchAsDocument": {
85+
"x": 1,
86+
"y": {
87+
"$$exists": true
88+
}
89+
}
90+
}
91+
}
92+
]
93+
}
94+
]
95+
},
96+
{
97+
"description": "matchAsDocument decodes Extended JSON",
98+
"operations": [
99+
{
100+
"name": "find",
101+
"object": "collection0",
102+
"arguments": {
103+
"filter": {
104+
"_id": 2
105+
},
106+
"limit": 1
107+
},
108+
"expectResult": [
109+
{
110+
"_id": 2,
111+
"json": {
112+
"$$matchAsDocument": {
113+
"x": {
114+
"$$type": "objectId"
115+
}
116+
}
117+
}
118+
}
119+
]
120+
}
121+
]
122+
}
123+
]
124+
}

0 commit comments

Comments
 (0)