Skip to content

Commit 6269bf0

Browse files
committed
cleanup tests
load fixtures declaratively we don't need to call_command('loaddata') by hand remove unused imports
1 parent 360fd74 commit 6269bf0

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

project/resources/tests.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
from rest_framework import status, serializers
1+
from rest_framework import status
22
from rest_framework.test import APITestCase
33
from rest_framework_jwt.settings import api_settings
4-
from django.core.management import call_command
54

65
jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
76
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
87

98
class ResourcesTests(APITestCase):
109

11-
def setUp(self):
12-
call_command('loaddata', 'users.json', verbosity=0)
13-
call_command('loaddata', 'resources.json', verbosity=0)
14-
call_command('loaddata', 'tagging.json', verbosity=0)
15-
call_command('loaddata', 'taggeditems.json', verbosity=0)
10+
fixtures = [
11+
'users',
12+
'resources',
13+
'tagging',
14+
'taggeditems'
15+
]
1616

17+
def setUp(self):
1718
url = '/auth/obtain_token/'
1819
#to do: choose a user at random from loaded users.json
1920
data = {"username": "JuJu", "password": "codebuddies"}

project/userauth/tests.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import unittest
21
from unittest.mock import patch
32
from rest_framework import status, serializers
43
from rest_framework.test import APITestCase
54
from rest_framework_jwt.settings import api_settings
6-
from django.core.management import call_command
75
from django.contrib.auth import get_user_model
86

97

@@ -12,14 +10,16 @@
1210

1311
class UserauthTests(APITestCase):
1412

13+
fixtures = ['users']
14+
1515
def setUp(self):
16-
"""
17-
Loads users.json fixture into test DB and directly creates a new user.
18-
"""
19-
call_command('loaddata', 'users.json', verbosity=0)
16+
# create a new user
2017
model = get_user_model()
21-
self.person = model.objects.create_user(username='PetuniaPig', email='[email protected]',
22-
password='codebuddies')
18+
self.person = model.objects.create_user(
19+
username='PetuniaPig',
20+
21+
password='codebuddies'
22+
)
2323

2424

2525
def test_jwt_not_authed(self):

0 commit comments

Comments
 (0)