mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-22 03:13:06 +00:00
added CORS middleware with basic installation / tests for v1 & v2 apis
This commit is contained in:
parent
42d70ce599
commit
3337817bf9
5 changed files with 41 additions and 3 deletions
3
Makefile
3
Makefile
|
@ -12,7 +12,8 @@ serve:
|
|||
python manage.py runserver --settings=config.local
|
||||
|
||||
test:
|
||||
python manage.py test pokemon --settings=config.local
|
||||
python manage.py test pokemon_v1 --settings=config.local
|
||||
python manage.py test pokemon_v2 --settings=config.local
|
||||
|
||||
clean:
|
||||
rm -rf *.pyc
|
||||
|
|
|
@ -4,8 +4,7 @@ import os
|
|||
|
||||
PROJECT_ROOT = Path(__file__).ancestor(2)
|
||||
|
||||
|
||||
DEBUG = False
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
ADMINS = (
|
||||
|
@ -62,6 +61,7 @@ TEMPLATE_LOADERS = (
|
|||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'corsheaders.middleware.CorsMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
|
@ -119,9 +119,15 @@ INSTALLED_APPS = (
|
|||
'django.contrib.staticfiles',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.humanize',
|
||||
'corsheaders'
|
||||
) + CUSTOM_APPS
|
||||
|
||||
|
||||
API_LIMIT_PER_PAGE = 1
|
||||
|
||||
TASTYPIE_DEFAULT_FORMATS = ['json']
|
||||
|
||||
CORS_ORIGIN_ALLOW_ALL = True
|
||||
CORS_ALLOW_METHODS = (
|
||||
'GET'
|
||||
)
|
||||
|
|
|
@ -1,2 +1,17 @@
|
|||
from __future__ import unicode_literals
|
||||
from django.test import TestCase
|
||||
|
||||
class HeaderTest(TestCase):
|
||||
|
||||
def test_pokemon(self):
|
||||
|
||||
response = self.client.get(
|
||||
'/api/v1/pokemon/1/',
|
||||
HTTP_ORIGIN="http://anpeterse.me")
|
||||
|
||||
print response.request
|
||||
print response.status_code
|
||||
print response
|
||||
print "checking for Access-Control-Allow-Origin header...";
|
||||
|
||||
self.assertEqual(response['Access-Control-Allow-Origin'], '*')
|
|
@ -2,3 +2,18 @@ from __future__ import unicode_literals
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
|
||||
class HeaderTest(TestCase):
|
||||
|
||||
def test_pokemon(self):
|
||||
|
||||
response = self.client.get(
|
||||
'/api/v1/pokemon/1/',
|
||||
HTTP_ORIGIN="http://anpeterse.me")
|
||||
|
||||
print response.request
|
||||
print response.status_code
|
||||
print response
|
||||
print "checking for Access-Control-Allow-Origin header...";
|
||||
|
||||
self.assertEqual(response['Access-Control-Allow-Origin'], '*')
|
||||
|
|
|
@ -17,3 +17,4 @@ python-mimeparse==0.1.4
|
|||
simplejson==3.6.5
|
||||
six==1.8.0
|
||||
wsgiref==0.1.2
|
||||
django-cors-headers=0.13
|
||||
|
|
Loading…
Reference in a new issue