Skip to content
Snippets Groups Projects
Commit ec8d745f authored by Haakon Gunleiksrud's avatar Haakon Gunleiksrud
Browse files

get further statement testing efforts of permissions

parent fbbc62c5
No related branches found
No related tags found
3 merge requests!15Dev,!10Dev,!9Fr5 bb testing
......@@ -5,6 +5,8 @@ from django.test import TestCase
from workouts.models import Workout
from users.models import User
from rest_framework.test import RequestsClient
from requests.auth import HTTPBasicAuth
import requests
# Create your tests here.
"""
......@@ -22,18 +24,26 @@ class IsOwnerTestCase(TestCase):
user_2 = User.objects.get(id="2")
workout = Workout.objects.get(name="workout")
client1 = RequestsClient()
client1.login(username="Bill",password="secret")
client2 = RequestsClient()
client2.login(username="Alice",password="supersecret")
client_1 = RequestsClient()
#client_1.auth = HTTPBasicAuth('user', 'pass')
#print("client_1.headers:\n\n",client_1.headers,"\n\n")
#client_1.headers.update({'Cookie': 'access=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjE0MzI3ODA4LCJqdGkiOiI2N2JmNzQ5YjQ1ZWY0Njg1YTM4MTc1MDMwZTZiNTNiMSIsInVzZXJfaWQiOjJ9.I7hOEFPqmWSgCa7CMa5INmeUhAuerIpBD3ps4WBykZ0; refresh=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTYxNDQxMzkwOCwianRpIjoiN2E3ZjQ1ODFhOWQ3NGU4NmE5NWUzYzlhZWIwNTExMWYiLCJ1c2VyX2lkIjoyfQ.FCHh4rKkKr4AhnC_ZGk3dvn3EyJeu7-thhbevD4u9WM'})
#client_1.headers.update({'authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjE0MzI3ODA4LCJqdGkiOiI2N2JmNzQ5YjQ1ZWY0Njg1YTM4MTc1MDMwZTZiNTNiMSIsInVzZXJfaWQiOjJ9.I7hOEFPqmWSgCa7CMa5INmeUhAuerIpBD3ps4WBykZ0'})
#print("client_1.headers:\n\n",client_1.headers,"\n\n")
#client2 = RequestsClient()
#client2.login(username="Alice",password="supersecret")
#Disse må fort endres når vi setter de inn i CI.
request1 = client1.get("/api/workouts/1")
request2 = client2.get("/api/workouts/1")
request_1 = client_1.get("http://testserver/api/workouts/1/", auth=('Bill','secret'))
#request2 = client2.get("/api/workouts/1")¨
#print(request_1.__dict__)
#self.assertEqual(user_1.username,client1.)
self.assertEqual(request1.client, client1)
print("request1.status_code:",request_1.status_code)
print("request_1:\n\n",request_1.__dict__,"\n\n")
self.assertTrue(request_1.status_code == 200)
#self.assertEqual(request_1.client, client_1)
self.assertTrue(workout.owner_id == user_1.id)
self.assertFalse(workout.owner_id == user_2.id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment