async def test_get_no_key_500(patched_send, opsdroid_matrix):
    patched_send.side_effect = MatrixRequestError(code=500)

    db = DatabaseMatrix({"single_state_key": False}, opsdroid=opsdroid_matrix)

    data = await db.get("twim")

    assert data is None
async def test_get_no_key_single_state_key(patched_send, opsdroid_matrix):
    patched_send.return_value = {"wibble": "wobble"}

    db = DatabaseMatrix({"single_state_key": True}, opsdroid=opsdroid_matrix)

    data = await db.get("twim")

    assert data is None
async def test_default_not_a_dict(patched_send, opsdroid_matrix):
    patched_send.return_value = {}

    value = "world"
    db = DatabaseMatrix({"single_state_key": False}, opsdroid=opsdroid_matrix)

    with pytest.raises(ValueError):
        await db.put("twim", value)
async def test_default_update_same_key_value_single_state_key(patched_send, opsdroid_matrix):
    patched_send.return_value = {"twim": {"hello": "world"}}

    value = {"hello": "world"}
    db = DatabaseMatrix({"single_state_key": True}, opsdroid=opsdroid_matrix)

    await db.put("twim", value)

    patched_send.assert_called_once_with("GET", "/rooms/%21notaroomid/state/opsdroid.database")
async def test_get(patched_send, opsdroid_matrix):
    patched_send.return_value = {"hello": "world"}

    db = DatabaseMatrix({"single_state_key": False}, opsdroid=opsdroid_matrix)

    data = await db.get("twim")

    patched_send.assert_called_once_with("GET", "/rooms/%21notaroomid/state/opsdroid.database/twim")

    assert data == {"hello": "world"}
async def test_single_state_key_false(patched_send, opsdroid_matrix):
    patched_send.return_value = {}

    db = DatabaseMatrix({"single_state_key": False}, opsdroid=opsdroid_matrix)
    await db.put("twim", {"hello": "world"})

    patched_send.assert_has_calls(
        [
            call("GET", "/rooms/%21notaroomid/state/opsdroid.database/twim"),
            call(
                "PUT",
                "/rooms/%21notaroomid/state/opsdroid.database/twim",
                {"hello": "world"},
                query_params={},
            ),
        ]
    )
async def test_default_config(patched_send, opsdroid_matrix):
    patched_send.return_value = {}

    db = DatabaseMatrix({}, opsdroid=opsdroid_matrix)
    await db.put("twim", {"hello": "world"})

    patched_send.assert_has_calls(
        [
            call("GET", "/rooms/%21notaroomid/state/opsdroid.database"),
            call(
                "PUT",
                "/rooms/%21notaroomid/state/opsdroid.database",
                {"twim": {"hello": "world"}},
                query_params={},
            ),
        ]
    )
async def test_single_state_not_a_dict(patched_send, opsdroid_matrix):
    patched_send.return_value = {}

    value = "world"
    db = DatabaseMatrix({"single_state_key": True}, opsdroid=opsdroid_matrix)
    await db.put("twim", value)

    patched_send.assert_has_calls(
        [
            call("GET", "/rooms/%21notaroomid/state/opsdroid.database"),
            call(
                "PUT",
                "/rooms/%21notaroomid/state/opsdroid.database",
                {"twim": value},
                query_params={},
            ),
        ]
    )
async def test_default_update_single_state_key(patched_send, opsdroid_matrix):
    patched_send.return_value = {"twim": "hello"}

    value = {"pill": "red"}
    db = DatabaseMatrix({"single_state_key": True}, opsdroid=opsdroid_matrix)

    await db.put("pill", "red")


    patched_send.assert_has_calls(
        [
            call("GET", "/rooms/%21notaroomid/state/opsdroid.database"),
            call(
                "PUT",
                "/rooms/%21notaroomid/state/opsdroid.database",
                {"twim": "hello", "pill": "red"},
                query_params={},
            ),
        ]
    )
async def test_connect(patched_send, opsdroid_matrix):
    db = DatabaseMatrix({}, opsdroid=opsdroid_matrix)

    await db.connect()