This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(controller): add django middleware tests
- Loading branch information
Matthew Fisher
committed
Jun 20, 2014
1 parent
d66e7d1
commit 47cce0d
Showing
3 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" | ||
Unit tests for the Deis api app. | ||
Run the tests with "./manage.py test api" | ||
""" | ||
from __future__ import unicode_literals | ||
|
||
from django.test import TestCase | ||
|
||
from deis import __version__ | ||
|
||
|
||
class APIMiddlewareTest(TestCase): | ||
|
||
"""Tests middleware.py's business logic""" | ||
|
||
fixtures = ['tests.json'] | ||
|
||
def setUp(self): | ||
self.assertTrue( | ||
self.client.login(username='autotest', password='password')) | ||
|
||
def test_x_deis_version_header_good(self): | ||
""" | ||
Test that when the version header is sent, the request is accepted. | ||
""" | ||
response = self.client.get( | ||
'/api/apps', | ||
HTTP_X_DEIS_VERSION=__version__.rsplit('.', 1)[0] | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_x_deis_version_header_bad(self): | ||
""" | ||
Test that when an improper version header is sent, the request is declined. | ||
""" | ||
response = self.client.get( | ||
'/api/apps', | ||
HTTP_X_DEIS_VERSION='1234.5678' | ||
) | ||
self.assertEqual(response.status_code, 405) | ||
|
||
def test_x_deis_version_header_not_present(self): | ||
""" | ||
Test that when the version header is not present, the request is accepted. | ||
""" | ||
response = self.client.get('/api/apps') | ||
self.assertEqual(response.status_code, 200) |