test_api.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:django-sysinfo 作者: saxix 项目源码 文件源码
def test_broken_database(settings, monkeypatch):
    settings.DATABASES = {
        "default": {
            "ENGINE": "django.db.backends.sqlite3",
            "NAME": ":memory:"},

        "broken": {
            "ENGINE": "django.db.backends.postgresql_psycopg2",
            "NAME": "not-existent-db",
            "HOST": "127.0.0.1",
            "PORT": "21",
            "USER": "",
            "PASSWORD": ""
        },

    }
    monkeypatch.setattr(connections, "_databases", None)
    del connections.databases

    ret = get_databases()
    assert sorted(ret.keys()) == ["broken", "default"]
    # assert ret["default"]["engine"] == "django.db.backends.sqlite3"
    assert ret["broken"]["engine"] == "django.db.backends.postgresql_psycopg2"
    assert ret["broken"]["host"] == "127.0.0.1:21"
    assert ret["broken"]["name"] == "not-existent-db"
    assert ret["broken"]["error"] == """could not connect to server: Connection refused
\tIs the server running on host "127.0.0.1" and accepting
\tTCP/IP connections on port 21?
"""
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号