mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-12-05 18:59:51 +00:00
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
import pytest
|
|
from rest_framework import status
|
|
from rest_framework.test import APIClient
|
|
|
|
|
|
class TestTotpView:
|
|
def test_options_does_not_fail(self, admin_client: APIClient) -> None:
|
|
"""
|
|
GIVEN:
|
|
- An authenticated client
|
|
WHEN:
|
|
- OPTIONS is sent to the TOTP endpoint
|
|
THEN:
|
|
- The request succeeds, DRF's metadata needs a serializer on the view
|
|
"""
|
|
response = admin_client.options("/api/profile/totp/")
|
|
|
|
assert response.status_code == status.HTTP_200_OK
|
|
|
|
@pytest.mark.parametrize(
|
|
"body",
|
|
[{}, {"secret": "abc"}, {"code": "123456"}, {"secret": None, "code": None}],
|
|
)
|
|
def test_activation_with_missing_fields_is_a_400(
|
|
self,
|
|
admin_client: APIClient,
|
|
body: dict[str, str | None],
|
|
) -> None:
|
|
"""
|
|
GIVEN:
|
|
- An authenticated client
|
|
WHEN:
|
|
- TOTP is activated without both the secret and the code
|
|
THEN:
|
|
- The response is a 400, not a server error
|
|
"""
|
|
response = admin_client.post("/api/profile/totp/", body, format="json")
|
|
|
|
assert response.status_code == status.HTTP_400_BAD_REQUEST
|