-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_api_middleware.py
More file actions
34 lines (24 loc) · 988 Bytes
/
test_api_middleware.py
File metadata and controls
34 lines (24 loc) · 988 Bytes
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
"""
Unit tests for the Drycc api app.
Run the tests with "./manage.py test api"
"""
from django.contrib.auth import get_user_model
from rest_framework.authtoken.models import Token
from api.tests import DryccTestCase
from api import __version__
User = get_user_model()
class APIMiddlewareTest(DryccTestCase):
"""Tests middleware.py's business logic"""
fixtures = ['tests.json']
def setUp(self):
self.user = User.objects.get(username='autotest')
self.token = Token.objects.get(user=self.user).key
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)
def test_drycc_version_header_good(self):
"""
Test that when the version header is sent.
"""
response = self.client.get('/v2/apps')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.has_header('DRYCC_API_VERSION'), True)
self.assertEqual(response['DRYCC_API_VERSION'], __version__.rsplit('.', 1)[0])