class_docstr: Create a :class:`orion.core.io.database.mongodb.MongoDB`, check connection cases.
class_docstr_tok: ["Create","a",":","class",":","`","orion.core.io.database.mongodb.MongoDB","`",",","check","connection","cases","."]
docstr: Raise when connection cannot be achieved.
docstr_tok: ["Raise","when","connection","can","not","be","achieved","."]
code: def test_bad_connection(self, monkeypatch):
      """Raise when connection cannot be achieved."""
      monkeypatch.setattr(
          MongoDB,
          "initiate_connection",
          MongoDB.initiate_connection.__wrapped__,
      )
      with pytest.raises(pymongo.errors.ConnectionFailure) as exc_info:
          MongoDB(
              host="asdfada",
              port=123,
              name="orion",
              username="uasdfaf",
              password="paasdfss",
          )
  
      monkeypatch.undo()
  
      # Verify that the wrapper converts it properly to DatabaseError
      with pytest.raises(DatabaseError) as exc_info:
          MongoDB(
              host="asdfada",
              port=123,
              name="orion",
              username="uasdfaf",
              password="paasdfss",
          )
      assert "Connection" in str(exc_info.value)
  
imports: import functools
  from timeit import timeit
  import pymongo
  import pytest
  from pymongo import MongoClient
  from orion.core.io.database import Database, DatabaseError, DuplicateKeyError
  from orion.core.io.database.mongodb import AUTH_FAILED_MESSAGES, MongoDB
  from .conftest import insert_test_collection
  from .test_database import get_db
label_desc: Use image node_id 1 for calling the TestConnection obj's underlying member method code with example usage: obj.test_bad_connection(monkeypatch) without return types