Commit 3ca5494e authored by Erlend Ydse's avatar Erlend Ydse
Browse files

Add remember me test

parent ec80d4da
Pipeline #128437 failed with stage
in 12 seconds
from django.test.client import RequestFactory
from rest_framework.test import APIClient, APITestCase
from users.views import RememberMe
def pretty_print_response(response):
print(response.data)
print(response.status_code)
class OffersAPITests(APITestCase):
def setUp(self):
self.path = "/api/offers/"
self.client = APIClient()
# Creating users
self.alice_r_data = {
"username": "alice",
"email": "aa@aa.aa",
"password": "aliceisok",
"password1": "aliceisok",
"phone_number": "12345678",
"country": "",
"city": "",
"street_address": ""}
response = self.client.post(path="/api/users/", data=self.alice_r_data)
self.alice_data = response.data
def test_can_get_rememberme_token(self):
# Logging in as alice
self.login_data = {"username": self.alice_r_data["username"], "password": self.alice_r_data["password"]}
response = self.client.post(path="/api/token/", data=self.login_data, format="json")
self.access_token = response.data["access"]
self.client.credentials(HTTP_AUTHORIZATION=f"Bearer {self.access_token}")
response = self.client.get(path="/api/remember_me/")
self.assertGreater(len(response.data["remember_me"]), 0)
def test_can_post_rememberme(self):
# Logging in as alice
self.login_data = {"username": self.alice_r_data["username"], "password": self.alice_r_data["password"]}
response = self.client.post(path="/api/token/", data=self.login_data, format="json")
self.access_token = response.data["access"]
self.client.credentials(HTTP_AUTHORIZATION=f"Bearer {self.access_token}")
response = self.client.get(path="/api/remember_me/")
request = RequestFactory().post('/api/remember_me/')
request.COOKIES['remember_me'] = response.data["remember_me"]
response = RememberMe.as_view()(request)
pretty_print_response(response)
self.assertGreater(len(response.data["access"]), 0)
self.assertGreater(len(response.data["refresh"]), 0)
......@@ -10,6 +10,7 @@ from rest_framework import generics, mixins, permissions
from rest_framework.parsers import FormParser, MultiPartParser
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from rest_framework.response import Response
from rest_framework.status import HTTP_400_BAD_REQUEST
from rest_framework_simplejwt.tokens import RefreshToken
from users.models import AthleteFile, Offer
......@@ -20,8 +21,6 @@ from users.serializers import (AthleteFileSerializer, OfferSerializer,
from workouts.mixins import CreateListModelMixin
from workouts.parsers import MultipartJsonParser
from workouts.permissions import IsOwner, IsReadOnly
from rest_framework.response import Response
from rest_framework.status import HTTP_400_BAD_REQUEST
class UserList(mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment