-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from akutsuacts/fix/api-gateway-middleware
Fix ApiGatewayMiddleWare in Python3
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.core.exceptions import PermissionDenied | ||
from django.urls import reverse | ||
from django.test import RequestFactory, TestCase | ||
|
||
from oscarapi.middleware import ApiGatewayMiddleWare | ||
from oscarapi.models import ApiKey | ||
|
||
|
||
class ApiGatewayMiddleWareTest(TestCase): | ||
|
||
rf = RequestFactory() | ||
|
||
def setUp(self): | ||
super(ApiGatewayMiddleWareTest, self).setUp() | ||
|
||
ApiKey.objects.create(key='testapikey') | ||
|
||
def tearDown(self): | ||
ApiKey.objects.filter(key='testapikey').delete() | ||
|
||
super(ApiGatewayMiddleWareTest, self).tearDown() | ||
|
||
def test_process_request(self): | ||
basket_url = reverse('api-basket') | ||
|
||
# without Authorization header | ||
request = self.rf.get(basket_url) | ||
with self.assertRaises(PermissionDenied): | ||
ApiGatewayMiddleWare().process_request(request) | ||
|
||
# invalid Authorization header | ||
request = self.rf.get(basket_url, HTTP_AUTHORIZATION='wrongkey') | ||
with self.assertRaises(PermissionDenied): | ||
ApiGatewayMiddleWare().process_request(request) | ||
|
||
# valid Authorization header | ||
request = self.rf.get(basket_url, HTTP_AUTHORIZATION='testapikey') | ||
self.assertIsNone(ApiGatewayMiddleWare().process_request(request)) |