Exemple #1
0
def test_user_status_not_exist(test_app, test_database):
    client = test_app.test_client()
    access_token = User.encode_token(999, "access").decode()
    resp = client.get(
        "/auth/status",
        headers={"Authorization": f"Bearer {access_token}"},
        content_type="application/json",
    )
    data = json.loads(resp.data.decode())
    assert resp.status_code == 401
    assert resp.content_type == "application/json"
    assert "Invalid token" in data["message"]
Exemple #2
0
def test_refresh_not_exist_user(test_app, test_database):
    client = test_app.test_client()
    refresh_token = User.encode_token(999, "refresh")
    resp = client.post(
        "/auth/refresh",
        data=json.dumps({"refresh_token": refresh_token.decode()}),
        content_type="application/json",
    )
    data = json.loads(resp.data.decode())
    assert resp.status_code == 401
    assert resp.content_type == "application/json"
    assert "Invalid token" in data["message"]
Exemple #3
0
def test_user_status_not_exist(test_app, monkeypatch):
    def mock_get_user_by_id(user_id):
        return None

    monkeypatch.setattr(src.api.users.auth, "get_user_by_id",
                        mock_get_user_by_id)

    client = test_app.test_client()
    access_token = User.encode_token(999, "access").decode()
    resp = client.get(
        "/auth/status",
        headers={"Authorization": f"Bearer {access_token}"},
        content_type="application/json",
    )
    data = json.loads(resp.data.decode())
    assert resp.status_code == 401
    assert resp.content_type == "application/json"
    assert "Invalid token" in data["message"]
Exemple #4
0
def test_refresh_not_exist_user(test_app, monkeypatch):
    def mock_get_user_by_id(user_id):
        return None

    monkeypatch.setattr(src.api.users.auth, "get_user_by_id",
                        mock_get_user_by_id)

    client = test_app.test_client()
    refresh_token = User.encode_token(999, "refresh")
    resp = client.post(
        "/auth/refresh",
        data=json.dumps({"refresh_token": refresh_token.decode()}),
        content_type="application/json",
    )
    data = json.loads(resp.data.decode())
    assert resp.status_code == 401
    assert resp.content_type == "application/json"
    assert "Invalid token" in data["message"]