コード例 #1
0
    def run_scenario(self):
        # Load data.
        assert scenario_def['data'], "tests must have non-empty data"
        client_context.client.pymongo_test.test.drop()
        client_context.client.pymongo_test.test.insert_many(
            scenario_def['data'])

        # Set the failPoint
        self.set_fail_point(test['failPoint'])
        self.addCleanup(
            self.set_fail_point, {
                'configureFailPoint': test['failPoint']['configureFailPoint'],
                'mode': 'off'
            })

        test_outcome = test['outcome']
        should_fail = test_outcome.get('error')
        result = None
        error = None

        db = rs_or_single_client(**test['clientOptions']).pymongo_test
        # Close the client explicitly to avoid having too many threads open.
        self.addCleanup(db.client.close)
        try:
            result = run_operation(db.test, test)
        except (ConnectionFailure, OperationFailure) as exc:
            error = exc

        if should_fail:
            self.assertIsNotNone(error, 'should have raised an error')
        else:
            self.assertIsNone(error)

        # Assert final state is expected.
        expected_c = test_outcome.get('collection')
        if expected_c is not None:
            expected_name = expected_c.get('name')
            if expected_name is not None:
                db_coll = db[expected_name]
            else:
                db_coll = db.test
            self.assertEqual(list(db_coll.find()), expected_c['data'])
        expected_result = test_outcome.get('result')
        # We can't test the expected result when the test should fail because
        # the BulkWriteResult is not reported when raising a network error.
        if not should_fail:
            self.assertTrue(check_result(expected_result, result),
                            "%r != %r" % (expected_result, result))
コード例 #2
0
    def run_scenario(self):
        # Load data.
        assert scenario_def['data'], "tests must have non-empty data"
        client_context.client.pymongo_test.test.drop()
        client_context.client.pymongo_test.test.insert_many(scenario_def['data'])

        # Set the failPoint
        self.set_fail_point(test['failPoint'])
        self.addCleanup(self.set_fail_point, {
            'configureFailPoint': test['failPoint']['configureFailPoint'],
            'mode': 'off'})

        test_outcome = test['outcome']
        should_fail = test_outcome.get('error')
        result = None
        error = None

        db = rs_or_single_client(**test['clientOptions']).pymongo_test
        try:
            result = run_operation(db.test, test)
        except (ConnectionFailure, OperationFailure) as exc:
            error = exc

        if should_fail:
            self.assertIsNotNone(error, 'should have raised an error')
        else:
            self.assertIsNone(error)

        # Assert final state is expected.
        expected_c = test_outcome.get('collection')
        if expected_c is not None:
            expected_name = expected_c.get('name')
            if expected_name is not None:
                db_coll = db[expected_name]
            else:
                db_coll = db.test
            self.assertEqual(list(db_coll.find()), expected_c['data'])
        expected_result = test_outcome.get('result')
        # We can't test the expected result when the test should fail because
        # the BulkWriteResult is not reported when raising a network error.
        if not should_fail:
            self.assertTrue(check_result(expected_result, result),
                            "%r != %r" % (expected_result, result))
コード例 #3
0
    def run_scenario(self):
        # Load data.
        assert scenario_def['data'], "tests must have non-empty data"
        self.db.test.drop()
        self.db.test.insert_many(scenario_def['data'])

        # Set the failPoint
        self.set_fail_point(test['failPoint'])

        test_outcome = test['outcome']
        should_fail = test_outcome.get('error')
        result = None
        error = None
        try:
            result = run_operation(self.db.test, test)
        except ConnectionFailure as exc:
            error = exc

        if should_fail:
            self.assertIsNotNone(error, 'should have raised an error')
        else:
            self.assertIsNone(error, 'should not have raised an error')

        # Assert final state is expected.
        expected_c = test_outcome.get('collection')
        if expected_c is not None:
            expected_name = expected_c.get('name')
            if expected_name is not None:
                db_coll = self.db[expected_name]
            else:
                db_coll = self.db.test
            self.assertEqual(list(db_coll.find()), expected_c['data'])
        expected_result = test_outcome.get('result')
        # We can't test the expected result when the test should fail because
        # the BulkWriteResult is not reported when raising a network error.
        if not should_fail:
            self.assertTrue(check_result(expected_result, result),
                            "%r != %r" % (expected_result, result))