feat(test): Add test for token showing
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from rest_framework.authtoken.models import Token
|
||||
|
||||
from model_bakery import baker
|
||||
|
||||
@@ -9,12 +10,12 @@ from fellchensammlung.models import AdoptionNotice, User, TrustLevel, Notificati
|
||||
class UserTest(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
test_user0 = User.objects.create_user(username='testuser0',
|
||||
first_name="Admin",
|
||||
last_name="BOFH",
|
||||
password='12345')
|
||||
test_user0.trust_level = TrustLevel.ADMIN
|
||||
test_user0.save()
|
||||
cls.test_user0 = User.objects.create_user(username='testuser0',
|
||||
first_name="Admin",
|
||||
last_name="BOFH",
|
||||
password='12345')
|
||||
cls.test_user0.trust_level = TrustLevel.ADMIN
|
||||
cls.test_user0.save()
|
||||
|
||||
cls.test_user1 = User.objects.create_user(username='testuser1',
|
||||
first_name="Max",
|
||||
@@ -26,13 +27,14 @@ class UserTest(TestCase):
|
||||
last_name="Müller",
|
||||
password='12345')
|
||||
|
||||
adoption1 = baker.make(AdoptionNotice, name="TestAdoption1", owner=test_user0)
|
||||
adoption1 = baker.make(AdoptionNotice, name="TestAdoption1", owner=cls.test_user0)
|
||||
notification1 = baker.make(Notification,
|
||||
title="TestNotification1",
|
||||
user_to_notify=test_user0,
|
||||
user_to_notify=cls.test_user0,
|
||||
adoption_notice=adoption1)
|
||||
notification2 = baker.make(Notification, title="TestNotification1", user_to_notify=cls.test_user1)
|
||||
notification3 = baker.make(Notification, title="TestNotification1", user_to_notify=cls.test_user2)
|
||||
token = baker.make(Token, user=cls.test_user0)
|
||||
|
||||
def test_detail_self(self):
|
||||
self.client.login(username='testuser1', password='12345')
|
||||
@@ -41,6 +43,20 @@ class UserTest(TestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "Max")
|
||||
|
||||
def test_detail_self_via_id(self):
|
||||
self.client.login(username='testuser1', password='12345')
|
||||
|
||||
response = self.client.post(reverse('user-detail', args=str(self.test_user1.pk)))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "Max")
|
||||
|
||||
def test_detail_admin_with_token(self):
|
||||
self.client.login(username='testuser0', password='12345')
|
||||
|
||||
response = self.client.post(reverse('user-me'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, Token.objects.get(user=self.test_user0).key)
|
||||
|
||||
def test_detail_unauthenticated(self):
|
||||
response = self.client.get(reverse('user-me'))
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
Reference in New Issue
Block a user