-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest_setup.py
More file actions
51 lines (41 loc) · 1.64 KB
/
test_setup.py
File metadata and controls
51 lines (41 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from rest_framework.test import APITestCase, APIClient
from django.urls import reverse
#from faker import Faker
from user.models import User, Profile
from lists.models import List, Solved, ListInfo, Enrolled
from problem.models import Problem
from lists.test_fixtures.profile_fixtures import profile1, profile2
class TestSetUp(APITestCase):
fixtures = [
"user.json", "problems.json", "lists.json", "list_info.json",
"enrolled.json", "solved.json", "userfriends.json", "editor.json"
]
@classmethod
def setUpTestData(cls):
# Set up data for the whole TestCase
Profile.objects.filter(owner=1).update(**profile1)
Profile.objects.filter(owner=2).update(**profile2)
@classmethod
def login(self, client, login_url, user_data):
user = User.objects.get(username=user_data['username'])
user.set_password(user_data['password'])
user.save()
response = client.post(login_url, user_data, format="json")
return response.data['tokens']['access']
@classmethod
def get_authenticated_client(self, token):
client = APIClient()
client.credentials(HTTP_AUTHORIZATION='Bearer ' + token)
return client
def setUp(self):
self.register_url = reverse('register')
self.login_url = reverse('login')
#self.fake = Faker()
self.user_data = {
# 'email': 'testing@gmail.com',#self.fake.email(),
'username': 'testing', #self.fake.email().split('@')[0],
'password': 'QWERTY@123' #self.fake.email(),
}
return super().setUp()
def tearDown(self):
return super().tearDown()