Beispiel #1
0
def test_setup_database_bad():
    """Test how setup fails when configuring with non-existant backends"""
    update_singletons()
    with pytest.raises(NotImplementedError) as exc:
        setup_database({"type": "idontexist"})

    assert exc.match("idontexist")
Beispiel #2
0
def test_get_database():
    """Test that get database gets the singleton"""
    update_singletons()
    setup_database({"type": "pickleddb", "host": "test.pkl"})
    database = get_database()
    assert isinstance(database, PickledDB)
    assert get_database() == database
Beispiel #3
0
def test_setup_database_custom():
    """Test setup with local configuration"""
    update_singletons()
    setup_database({"type": "pickleddb", "host": "test.pkl"})
    database = database_factory.create()
    assert isinstance(database, PickledDB)
    assert database.host == os.path.abspath("test.pkl")
Beispiel #4
0
def test_setup_database_bad_config_override():
    """Test setup with different config than existing singleton"""
    update_singletons()
    setup_database({"type": "pickleddb", "host": "test.pkl"})
    database = database_factory.create()
    assert isinstance(database, PickledDB)
    with pytest.raises(SingletonAlreadyInstantiatedError):
        setup_database({"type": "pickleddb", "host": "other.pkl"})
Beispiel #5
0
def test_setup_database_bad_override():
    """Test setup with different type than existing singleton"""
    update_singletons()
    setup_database({"type": "pickleddb", "host": "test.pkl"})
    database = database_factory.create()
    assert isinstance(database, PickledDB)
    with pytest.raises(SingletonAlreadyInstantiatedError) as exc:
        setup_database({"type": "mongodb"})

    assert exc.match("A singleton instance of \(type: Database\)")
Beispiel #6
0
def test_setup_database_default(monkeypatch):
    """Test that database is setup using default config"""
    update_singletons()
    setup_database()
    database = database_factory.create()
    assert isinstance(database, PickledDB)