|
| 1 | +# Copyright 2020-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 | + |
| 15 | +"""v2 format CRUD test runner. |
| 16 | +
|
| 17 | +https://github.com/mongodb/specifications/blob/master/source/crud/tests/README.rst |
| 18 | +""" |
| 19 | + |
| 20 | +from test.utils_spec_runner import SpecRunner |
| 21 | + |
| 22 | + |
| 23 | +class TestCrudV2(SpecRunner): |
| 24 | + # Default test database and collection names. |
| 25 | + TEST_DB = None |
| 26 | + TEST_COLLECTION = None |
| 27 | + |
| 28 | + def get_scenario_db_name(self, scenario_def): |
| 29 | + """Crud spec says database_name is optional.""" |
| 30 | + return scenario_def.get('database_name', self.TEST_DB) |
| 31 | + |
| 32 | + def get_scenario_coll_name(self, scenario_def): |
| 33 | + """Crud spec says collection_name is optional.""" |
| 34 | + return scenario_def.get('collection_name', self.TEST_COLLECTION) |
| 35 | + |
| 36 | + def get_object_name(self, op): |
| 37 | + """Crud spec says object is optional and defaults to 'collection'.""" |
| 38 | + return op.get('object', 'collection') |
| 39 | + |
| 40 | + def get_outcome_coll_name(self, outcome, collection): |
| 41 | + """Crud spec says outcome has an optional 'collection.name'.""" |
| 42 | + return outcome['collection'].get('name', collection.name) |
| 43 | + |
| 44 | + def setup_scenario(self, scenario_def): |
| 45 | + """Allow specs to override a test's setup.""" |
| 46 | + # PYTHON-1935 Only create the collection if there is data to insert. |
| 47 | + if scenario_def['data']: |
| 48 | + super(TestCrudV2, self).setup_scenario(scenario_def) |
0 commit comments