Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
da466b74f4 | |||
76ae576717 | |||
9da7cec1f5 | |||
2d0a8dbcd8 | |||
a3bc807192 |
@ -2,6 +2,14 @@ Change Log
|
||||
==========
|
||||
|
||||
|
||||
Version 0.7.1
|
||||
-------------
|
||||
|
||||
Released 2024/12/9
|
||||
|
||||
Fix test cases for compatibility with httpx 0.28.0.
|
||||
|
||||
|
||||
Version 0.7.0
|
||||
-------------
|
||||
|
||||
|
@ -199,70 +199,3 @@ In your ``my_app/views.py``:
|
||||
The views only depend on Flask-Login, but not the actual
|
||||
authentication mechanism. You can change the actual authentication
|
||||
mechanism without changing the views.
|
||||
|
||||
|
||||
.. _example-unittest:
|
||||
|
||||
A unittest Test Case
|
||||
--------------------
|
||||
|
||||
::
|
||||
|
||||
from flask import Flask
|
||||
from flask_digest_auth import Client
|
||||
from flask_testing import TestCase
|
||||
from my_app import create_app
|
||||
|
||||
class MyTestCase(TestCase):
|
||||
|
||||
def create_app(self):
|
||||
app: Flask = create_app({
|
||||
"TESTING": True,
|
||||
"SECRET_KEY": token_urlsafe(32),
|
||||
"DIGEST_AUTH_REALM": "admin",
|
||||
})
|
||||
app.test_client_class = Client
|
||||
return app
|
||||
|
||||
def test_admin(self):
|
||||
response = self.client.get("/admin")
|
||||
self.assertEqual(response.status_code, 401)
|
||||
response = self.client.get(
|
||||
"/admin", digest_auth=(USERNAME, PASSWORD))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
|
||||
.. _example-pytest:
|
||||
|
||||
A pytest Test
|
||||
-------------
|
||||
|
||||
::
|
||||
|
||||
import pytest
|
||||
from flask import Flask
|
||||
from flask_digest_auth import Client
|
||||
from my_app import create_app
|
||||
|
||||
@pytest.fixture()
|
||||
def app():
|
||||
app: Flask = create_app({
|
||||
"TESTING": True,
|
||||
"SECRET_KEY": token_urlsafe(32),
|
||||
"DIGEST_AUTH_REALM": "admin",
|
||||
})
|
||||
app.test_client_class = Client
|
||||
yield app
|
||||
|
||||
@pytest.fixture()
|
||||
def client(app):
|
||||
return app.test_client()
|
||||
|
||||
def test_admin(app: Flask, client: Client):
|
||||
with app.app_context():
|
||||
response = client.get("/admin")
|
||||
assert response.status_code == 401
|
||||
response = client.get(
|
||||
"/admin", digest_auth=(USERNAME, PASSWORD))
|
||||
assert response.status_code == 200
|
||||
|
@ -137,17 +137,6 @@ new username and password.
|
||||
See :meth:`flask_digest_auth.auth.DigestAuth.logout`.
|
||||
|
||||
|
||||
Test Client
|
||||
-----------
|
||||
|
||||
Flask-DigestAuth comes with a test client that supports HTTP digest
|
||||
authentication.
|
||||
|
||||
See :class:`flask_digest_auth.test.Client`.
|
||||
|
||||
Also see :ref:`example-unittest` and :ref:`example-pytest`.
|
||||
|
||||
|
||||
.. _HTTP Digest Authentication: https://en.wikipedia.org/wiki/Digest_access_authentication
|
||||
.. _RFC 2617: https://www.rfc-editor.org/rfc/rfc2617
|
||||
.. _Flask: https://flask.palletsprojects.com
|
||||
|
@ -1,7 +1,7 @@
|
||||
# The Flask HTTP Digest Authentication Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2022/11/23
|
||||
|
||||
# Copyright (c) 2022-2023 imacat.
|
||||
# Copyright (c) 2022-2024 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -34,13 +34,12 @@ classifiers = [
|
||||
"Intended Audience :: Developers",
|
||||
]
|
||||
dependencies = [
|
||||
"flask",
|
||||
"Flask",
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
test = [
|
||||
"unittest",
|
||||
"httpx",
|
||||
devel = [
|
||||
"httpx >= 0.20.0",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
|
@ -21,5 +21,5 @@
|
||||
from flask_digest_auth.algo import make_password_hash, calc_response
|
||||
from flask_digest_auth.auth import DigestAuth
|
||||
|
||||
VERSION: str = "0.7.0"
|
||||
VERSION: str = "0.7.1"
|
||||
"""The package version."""
|
||||
|
@ -66,7 +66,8 @@ class AuthenticationTestCase(unittest.TestCase):
|
||||
"DIGEST_AUTH_REALM": REALM,
|
||||
})
|
||||
self.__client: httpx.Client = httpx.Client(
|
||||
app=app, base_url="https://testserver")
|
||||
transport=httpx.WSGITransport(app=app),
|
||||
base_url="https://testserver")
|
||||
"""The testing client."""
|
||||
|
||||
auth: DigestAuth = DigestAuth()
|
||||
|
@ -91,7 +91,8 @@ class FlaskLoginTestCase(unittest.TestCase):
|
||||
"DIGEST_AUTH_REALM": REALM,
|
||||
})
|
||||
self.__client: httpx.Client = httpx.Client(
|
||||
app=self.app, base_url="https://testserver")
|
||||
transport=httpx.WSGITransport(app=self.app),
|
||||
base_url="https://testserver")
|
||||
"""The testing client."""
|
||||
|
||||
self.__has_flask_login: bool = True
|
||||
|
Reference in New Issue
Block a user