Skip to content

Commit e80141e

Browse files
authored
PYTHON-2992 Implement unified test format loop operation (#773)
1 parent b05ac0e commit e80141e

15 files changed

+613
-38
lines changed

test/test_create_entities.py

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Copyright 2021-present MongoDB, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import unittest
15+
16+
from test.unified_format import UnifiedSpecTestMixinV1
17+
18+
from pymongo.monitoring import PoolCreatedEvent
19+
20+
21+
class TestCreateEntities(unittest.TestCase):
22+
def test_store_events_as_entities(self):
23+
self.scenario_runner = UnifiedSpecTestMixinV1()
24+
spec = {
25+
"description": "blank",
26+
"schemaVersion": "1.2",
27+
"createEntities": [
28+
{
29+
"client": {
30+
"id": "client0",
31+
"storeEventsAsEntities": [
32+
{
33+
"id": "events1",
34+
"events": [
35+
"PoolCreatedEvent",
36+
]
37+
}
38+
]
39+
}
40+
},
41+
],
42+
"tests": [
43+
{
44+
"description": "foo",
45+
"operations": []
46+
}
47+
]
48+
}
49+
self.scenario_runner.TEST_SPEC = spec
50+
self.scenario_runner.setUp()
51+
self.scenario_runner.run_scenario(spec["tests"][0])
52+
final_entity_map = self.scenario_runner.entity_map
53+
self.assertIn("events1", final_entity_map)
54+
self.assertGreater(len(final_entity_map["events1"]), 0)
55+
for event in final_entity_map["events1"]:
56+
self.assertEqual(type(event), PoolCreatedEvent)
57+
58+
def test_store_all_others_as_entities(self):
59+
self.scenario_runner = UnifiedSpecTestMixinV1()
60+
spec = {
61+
"description": "Find",
62+
"schemaVersion": "1.2",
63+
"createEntities": [
64+
{
65+
"client": {
66+
"id": "client0",
67+
"uriOptions": {
68+
"retryReads": True
69+
},
70+
}
71+
},
72+
{
73+
"database": {
74+
"id": "database0",
75+
"client": "client0",
76+
"databaseName": "dat"
77+
}
78+
},
79+
{
80+
"collection": {
81+
"id": "collection0",
82+
"database": "database0",
83+
"collectionName": "dat"
84+
}
85+
}
86+
],
87+
88+
"tests": [
89+
{
90+
"description": "test loops",
91+
"operations": [
92+
{
93+
"name": "loop",
94+
"object": "testRunner",
95+
"arguments": {
96+
"storeIterationsAsEntity": "iterations",
97+
"storeSuccessesAsEntity": "successes",
98+
"storeFailuresAsEntity": "failures",
99+
"storeErrorsAsEntity": "errors",
100+
"numIterations": 5,
101+
"operations": [
102+
{
103+
"name": "insertOne",
104+
"object": "collection0",
105+
"arguments": {
106+
"document": {
107+
"_id": 1,
108+
"x": 44
109+
}
110+
}
111+
112+
},
113+
{
114+
"name": "insertOne",
115+
"object": "collection0",
116+
"arguments": {
117+
"document": {
118+
"_id": 1,
119+
"x": 44
120+
}
121+
}
122+
123+
}
124+
]
125+
}
126+
}
127+
]
128+
}
129+
]
130+
}
131+
132+
self.scenario_runner.TEST_SPEC = spec
133+
self.scenario_runner.setUp()
134+
self.scenario_runner.run_scenario(spec["tests"][0])
135+
final_entity_map = self.scenario_runner.entity_map
136+
for entity in ["errors", "failures"]:
137+
self.assertIn(entity, final_entity_map)
138+
self.assertGreaterEqual(len(final_entity_map[entity]), 0)
139+
self.assertEqual(type(final_entity_map[entity]), list)
140+
for entity in ["successes", "iterations"]:
141+
self.assertIn(entity, final_entity_map)
142+
self.assertEqual(type(final_entity_map[entity]), int)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"description": "entity-client-storeEventsAsEntities-minItems",
3+
"schemaVersion": "1.2",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"storeEventsAsEntities": []
9+
}
10+
}
11+
],
12+
"tests": [
13+
{
14+
"description": "foo",
15+
"operations": []
16+
}
17+
]
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"description": "entity-client-storeEventsAsEntities-type",
3+
"schemaVersion": "1.2",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"storeEventsAsEntities": 0
9+
}
10+
}
11+
],
12+
"tests": [
13+
{
14+
"description": "foo",
15+
"operations": []
16+
}
17+
]
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"description": "expectedCommandEvent-commandFailedEvent-hasServerConnectionId-type",
3+
"schemaVersion": "1.6",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
}
10+
],
11+
"tests": [
12+
{
13+
"description": "foo",
14+
"operations": [],
15+
"expectEvents": [
16+
{
17+
"client": "client0",
18+
"events": [
19+
{
20+
"commandFailedEvent": {
21+
"hasServerConnectionId": "foo"
22+
}
23+
}
24+
]
25+
}
26+
]
27+
}
28+
]
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"description": "expectedCommandEvent-commandStartedEvent-hasServerConnectionId-type",
3+
"schemaVersion": "1.6",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
}
10+
],
11+
"tests": [
12+
{
13+
"description": "foo",
14+
"operations": [],
15+
"expectEvents": [
16+
{
17+
"client": "client0",
18+
"events": [
19+
{
20+
"commandStartedEvent": {
21+
"hasServerConnectionId": "foo"
22+
}
23+
}
24+
]
25+
}
26+
]
27+
}
28+
]
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"description": "expectedCommandEvent-commandSucceededEvent-hasServerConnectionId-type",
3+
"schemaVersion": "1.6",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
}
10+
],
11+
"tests": [
12+
{
13+
"description": "foo",
14+
"operations": [],
15+
"expectEvents": [
16+
{
17+
"client": "client0",
18+
"events": [
19+
{
20+
"commandSucceededEvent": {
21+
"hasServerConnectionId": "foo"
22+
}
23+
}
24+
]
25+
}
26+
]
27+
}
28+
]
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"description": "entity-client-storeEventsAsEntities-conflict_with_client_id",
3+
"schemaVersion": "1.2",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"storeEventsAsEntities": [
9+
{
10+
"id": "client0",
11+
"events": [
12+
"PoolCreatedEvent",
13+
"PoolReadyEvent",
14+
"PoolClearedEvent",
15+
"PoolClosedEvent"
16+
]
17+
}
18+
]
19+
}
20+
}
21+
],
22+
"tests": [
23+
{
24+
"description": "foo",
25+
"operations": []
26+
}
27+
]
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"description": "entity-client-storeEventsAsEntities-conflict_within_different_array",
3+
"schemaVersion": "1.2",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"storeEventsAsEntities": [
9+
{
10+
"id": "events",
11+
"events": [
12+
"PoolCreatedEvent",
13+
"PoolReadyEvent",
14+
"PoolClearedEvent",
15+
"PoolClosedEvent"
16+
]
17+
}
18+
]
19+
}
20+
},
21+
{
22+
"client": {
23+
"id": "client1",
24+
"storeEventsAsEntities": [
25+
{
26+
"id": "events",
27+
"events": [
28+
"CommandStartedEvent",
29+
"CommandSucceededEvent",
30+
"CommandFailedEvent"
31+
]
32+
}
33+
]
34+
}
35+
}
36+
],
37+
"tests": [
38+
{
39+
"description": "foo",
40+
"operations": []
41+
}
42+
]
43+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"description": "entity-client-storeEventsAsEntities-conflict_within_same_array",
3+
"schemaVersion": "1.2",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"storeEventsAsEntities": [
9+
{
10+
"id": "events",
11+
"events": [
12+
"PoolCreatedEvent",
13+
"PoolReadyEvent",
14+
"PoolClearedEvent",
15+
"PoolClosedEvent"
16+
]
17+
},
18+
{
19+
"id": "events",
20+
"events": [
21+
"CommandStartedEvent",
22+
"CommandSucceededEvent",
23+
"CommandFailedEvent"
24+
]
25+
}
26+
]
27+
}
28+
}
29+
],
30+
"tests": [
31+
{
32+
"description": "foo",
33+
"operations": []
34+
}
35+
]
36+
}

0 commit comments

Comments
 (0)