github.com/blystad/deis@v0.11.0/controller/api/tests/test_api_middleware.py (about) 1 """ 2 Unit tests for the Deis api app. 3 4 Run the tests with "./manage.py test api" 5 """ 6 from __future__ import unicode_literals 7 8 from django.test import TestCase 9 10 from deis import __version__ 11 12 13 class APIMiddlewareTest(TestCase): 14 15 """Tests middleware.py's business logic""" 16 17 fixtures = ['tests.json'] 18 19 def setUp(self): 20 self.assertTrue( 21 self.client.login(username='autotest', password='password')) 22 23 def test_x_deis_version_header_good(self): 24 """ 25 Test that when the version header is sent, the request is accepted. 26 """ 27 response = self.client.get( 28 '/api/apps', 29 HTTP_X_DEIS_VERSION=__version__.rsplit('.', 1)[0] 30 ) 31 self.assertEqual(response.status_code, 200) 32 33 def test_x_deis_version_header_bad(self): 34 """ 35 Test that when an improper version header is sent, the request is declined. 36 """ 37 response = self.client.get( 38 '/api/apps', 39 HTTP_X_DEIS_VERSION='1234.5678' 40 ) 41 self.assertEqual(response.status_code, 405) 42 43 def test_x_deis_version_header_not_present(self): 44 """ 45 Test that when the version header is not present, the request is accepted. 46 """ 47 response = self.client.get('/api/apps') 48 self.assertEqual(response.status_code, 200)