-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into bugfix/gov_search_irrelevant
- Loading branch information
Showing
6 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.contrib.auth import get_user_model | ||
from rest_framework.decorators import api_view, permission_classes | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.response import Response | ||
|
||
from redbox_app.redbox_core.serializers import UserSerializer | ||
|
||
User = get_user_model() | ||
|
||
|
||
@api_view(["GET"]) | ||
@permission_classes([IsAuthenticated]) | ||
def user_view_pre_alpha(request): | ||
"""this is for testing and evaluation only | ||
this *will* change so that not all data is returned! | ||
""" | ||
serializer = UserSerializer(request.user) | ||
return Response(serializer.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
from http import HTTPStatus | ||
|
||
import pytest | ||
from django.contrib.auth import get_user_model | ||
from django.test import Client | ||
from django.urls import reverse | ||
|
||
User = get_user_model() | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.mark.django_db() | ||
def test_api_view(user_with_chats_with_messages_over_time: User, client: Client): | ||
# Given | ||
client.force_login(user_with_chats_with_messages_over_time) | ||
|
||
# When | ||
url = reverse("user-view") | ||
response = client.get(url) | ||
|
||
# Then | ||
assert response.status_code == HTTPStatus.OK | ||
assert response.json()["email"] == user_with_chats_with_messages_over_time.email | ||
|
||
|
||
@pytest.mark.django_db() | ||
def test_api_view_fail(client: Client): | ||
# Given that the user is not logged in | ||
|
||
# When | ||
url = reverse("user-view") | ||
response = client.get(url) | ||
|
||
# Then | ||
assert response.status_code == HTTPStatus.FORBIDDEN | ||
assert response.json() == {"detail": "Authentication credentials were not provided."} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import logging | ||
from http import HTTPStatus | ||
|
||
import pytest | ||
from django.contrib.auth import get_user_model | ||
from django.test import Client | ||
from django.urls import reverse | ||
|
||
User = get_user_model() | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.mark.django_db() | ||
def test_sign_in_view_redirect_to_sign_in(alice: User, client: Client, mailoutbox): | ||
# Given a user that does exist in the db Alice | ||
|
||
# When | ||
url = reverse("sign-in") | ||
response = client.post(url, data={"email": alice.email}) | ||
|
||
# Then | ||
assert response.status_code == HTTPStatus.FOUND | ||
assert response.url == "/sign-in-link-sent/" | ||
link = next(line for line in mailoutbox[-1].body.splitlines() if line.startswith("http")) | ||
signed_in_response = client.get(link) | ||
assert signed_in_response.status_code == HTTPStatus.OK | ||
|
||
|
||
@pytest.mark.django_db() | ||
def test_sign_in_view_redirect_sign_up(client: Client): | ||
# Given a user that does not exist in the database | ||
|
||
# When | ||
url = reverse("sign-in") | ||
response = client.post(url, data={"email": "[email protected]"}) | ||
|
||
# Then | ||
assert response.status_code == HTTPStatus.FOUND | ||
assert response.url == "/sign-up-page-1" |