Skip to content

PYTHON-2033 Unified Test Format #519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
47998d8
working changes
prashantmital Nov 16, 2020
8a188cb
skeletal solution
prashantmital Nov 17, 2020
5ed205a
preserve case in test descriptions; remove unused imports; properly s…
prashantmital Nov 17, 2020
6ed7283
tweak class name prefix specification
prashantmital Nov 17, 2020
580645f
working commit 2
prashantmital Nov 18, 2020
74a1cfe
working commit 2
prashantmital Dec 1, 2020
9d51830
working commit 3
prashantmital Dec 1, 2020
fc21f1c
fixup change streams 1
prashantmital Dec 2, 2020
bef3a1a
get crud tests working
prashantmital Dec 3, 2020
66d0148
further fleshing out
prashantmital Dec 4, 2020
5d8eeb1
get transactions tests working
prashantmital Dec 7, 2020
a431875
remove cruft
prashantmital Dec 7, 2020
2beb719
add valid-fail testing
prashantmital Dec 8, 2020
da8015f
add more operators
prashantmital Dec 8, 2020
9fbcaad
implement more ops
prashantmital Dec 10, 2020
a2a9ee8
get \$type working
prashantmital Dec 10, 2020
fdd7b69
add support for sharded-replicaset topology
prashantmital Dec 10, 2020
e8aabd5
remove cruft
prashantmital Dec 10, 2020
48e264f
ignore sensitive cmds in monitoring
prashantmital Dec 10, 2020
0878405
normalize cmd names for comparison
prashantmital Dec 11, 2020
58cae3b
ensure coll created
prashantmital Dec 11, 2020
d082993
code review 1
prashantmital Dec 15, 2020
6c49c96
improvements
prashantmital Dec 16, 2020
fd89761
more review
prashantmital Dec 17, 2020
ff4cb56
more review 2
prashantmital Dec 17, 2020
b643b2d
fix handling of hint in bulk
prashantmital Dec 18, 2020
e66abf5
fix
prashantmital Dec 18, 2020
aefb58d
check test cmds enabled
prashantmital Dec 21, 2020
4a3e066
skip mmap
prashantmital Dec 21, 2020
6a6681e
fix 2
prashantmital Dec 21, 2020
fb05c59
skip more tests on mmap
prashantmital Dec 22, 2020
5e00979
decentralize skipping code
prashantmital Dec 22, 2020
855c752
dont use find
prashantmital Dec 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,16 @@ def is_topology_type(self, topologies):
return True
if 'sharded' in topologies and self.is_mongos:
return True
if 'sharded-replicaset' in topologies and self.is_mongos:
shards = list(client_context.client.config.shards.find())
for shard in shards:
# For a 3-member RS-backed sharded cluster, shard['host']
# will be 'replicaName/ip1:port1,ip2:port2,ip3:port3'
# Otherwise it will be 'ip1:port1'
host_spec = shard['host']
if not len(host_spec.split('/')) > 1:
return False
return True
return False

def require_cluster_type(self, topologies=[]):
Expand Down
73 changes: 73 additions & 0 deletions test/test_unified_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright 2020-present MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys

sys.path[0:0] = [""]

from bson import ObjectId

from test import unittest
from test.unified_format import generate_test_classes, MatchEvaluatorUtil


_TEST_PATH = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'unified-test-format')


globals().update(generate_test_classes(
os.path.join(_TEST_PATH, 'valid-pass'),
module=__name__,
class_name_prefix='UnifiedTestFormat',
expected_failures=[
'Client side error in command starting transaction', # PYTHON-1894
]))


globals().update(generate_test_classes(
os.path.join(_TEST_PATH, 'valid-fail'),
module=__name__,
class_name_prefix='UnifiedTestFormat',
bypass_test_generation_errors=True,
expected_failures=[
'.*', # All tests expected to fail
]))


class TestMatchEvaluatorUtil(unittest.TestCase):
def setUp(self):
self.match_evaluator = MatchEvaluatorUtil(self)

def test_unsetOrMatches(self):
spec = {'$$unsetOrMatches': {'y': {'$$unsetOrMatches': 2}}}
for actual in [{}, {'y': 2}, None]:
self.match_evaluator.match_result(spec, actual)

spec = {'x': {'$$unsetOrMatches': {'y': {'$$unsetOrMatches': 2}}}}
for actual in [{}, {'x': {}}, {'x': {'y': 2}}]:
self.match_evaluator.match_result(spec, actual)

def test_type(self):
self.match_evaluator.match_result(
{'operationType': 'insert',
'ns': {'db': 'change-stream-tests', 'coll': 'test'},
'fullDocument': {'_id': {'$$type': 'objectId'}, 'x': 1}},
{'operationType': 'insert',
'fullDocument': {'_id': ObjectId('5fc93511ac93941052098f0c'), 'x': 1},
'ns': {'db': 'change-stream-tests', 'coll': 'test'}})


if __name__ == "__main__":
unittest.main()
100 changes: 100 additions & 0 deletions test/unified-test-format/example-insertOne.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"description": "example-insertOne",
"schemaVersion": "1.0",
"runOnRequirements": [
{
"minServerVersion": "2.6"
}
],
"createEntities": [
{
"client": {
"id": "client0",
"observeEvents": [
"commandStartedEvent"
]
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "test"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "coll"
}
}
],
"initialData": [
{
"collectionName": "coll",
"databaseName": "test",
"documents": [
{
"_id": 1
}
]
}
],
"tests": [
{
"description": "insertOne",
"operations": [
{
"object": "collection0",
"name": "insertOne",
"arguments": {
"document": {
"_id": 2
}
},
"expectResult": {
"insertedId": {
"$$unsetOrMatches": 2
}
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"commandName": "insert",
"databaseName": "test",
"command": {
"insert": "coll",
"documents": [
{
"_id": 2
}
]
}
}
}
]
}
],
"outcome": [
{
"collectionName": "coll",
"databaseName": "test",
"documents": [
{
"_id": 1
},
{
"_id": 2
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"description": "collectionData-additionalProperties",
"schemaVersion": "1.0",
"createEntities": [
{
"client": {
"id": "client0"
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "foo"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "foo",
"foo": 0
}
}
],
"initialData": [
{
"collectionName": "foo",
"databaseName": "foo",
"documents": [],
"foo": 0
}
],
"tests": [
{
"description": "foo",
"operations": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"description": "collectionData-collectionName-required",
"schemaVersion": "1.0",
"createEntities": [
{
"client": {
"id": "client0"
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "foo"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "foo",
"foo": 0
}
}
],
"initialData": [
{
"databaseName": "foo",
"documents": []
}
],
"tests": [
{
"description": "foo",
"operations": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"description": "collectionData-collectionName-type",
"schemaVersion": "1.0",
"createEntities": [
{
"client": {
"id": "client0"
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "foo"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "foo",
"foo": 0
}
}
],
"initialData": [
{
"collectionName": 0,
"databaseName": "foo",
"documents": []
}
],
"tests": [
{
"description": "foo",
"operations": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"description": "collectionData-databaseName-required",
"schemaVersion": "1.0",
"createEntities": [
{
"client": {
"id": "client0"
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "foo"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "foo",
"foo": 0
}
}
],
"initialData": [
{
"collectionName": "foo",
"documents": []
}
],
"tests": [
{
"description": "foo",
"operations": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"description": "collectionData-databaseName-type",
"schemaVersion": "1.0",
"createEntities": [
{
"client": {
"id": "client0"
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "foo"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "foo",
"foo": 0
}
}
],
"initialData": [
{
"collectionName": "foo",
"databaseName": 0,
"documents": []
}
],
"tests": [
{
"description": "foo",
"operations": []
}
]
}
Loading