Exemplo n.º 1
0
def mongodb():
    try:
        edb = ElectrolyteDB()  # will fail if no DB
        edb.get_base()  # will fail if DB is not loaded
    except Exception as err:
        _log.warning(f"Could not connect to MongoDB: {err}")
    return False
Exemplo n.º 2
0
def edb(pytestconfig: Config) -> ElectrolyteDB:
    """
    Create and populate an EDB instance
    """
    mock_allowed = not pytestconfig.option.edb_no_mock
    if ElectrolyteDB.can_connect():
        _edb = ElectrolyteDB()
    else:
        if mock_allowed:
            _edb = MockDB()
        else:
            pytest.fail("EDB could not connect to a database instance, but mocking is not allowed")
    _load_bootstrap(_edb)
    yield _edb
    _reset(_edb)
Exemplo n.º 3
0
def connect_to_edb(test_invalid_host=False):
    print("connecting to " + str(ElectrolyteDB.DEFAULT_URL))
    db = ElectrolyteDB()
    connected = db.can_connect()
    return (db, connected)
Exemplo n.º 4
0
 def test_from_populated_db(self, run_from_populated_db: Outcome, edb: ElectrolyteDB):
     result, expected = run_from_populated_db
     assert result == expected, result.stdout
     assert not edb.is_empty()
Exemplo n.º 5
0
 def test_from_empty_db(self, run_from_empty_db: Outcome, edb: ElectrolyteDB):
     result, expected = run_from_empty_db
     assert result == expected, result.stdout
     if expected.success:
         assert not edb.is_empty()
Exemplo n.º 6
0
def edb(mock_edb) -> ElectrolyteDB:
    # NOTE to switch to a non-mock EDB instance, simply do not use "mock_edb" in this fixture
    edb = ElectrolyteDB()
    assert edb._client is mock_edb.instance
    return edb