mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-10 06:04:18 +00:00
Progress - sprite resource implemented and testing
This commit is contained in:
parent
9adcec8eac
commit
5818918622
5 changed files with 103 additions and 5 deletions
4
Makefile
4
Makefile
|
@ -1,9 +1,9 @@
|
|||
install:
|
||||
sudo pip install -r requirements.txt
|
||||
pip install -r requirements.txt
|
||||
|
||||
setup:
|
||||
python manage.py migrate --settings=config.local
|
||||
python manage.py loaddata dev_data.json --settings=config.local
|
||||
python manage.py loaddata dev-data.json --settings=config.local
|
||||
|
||||
wipe_db:
|
||||
rm -rf db.sqlite3
|
||||
|
|
|
@ -111,6 +111,7 @@ SECRET_KEY = os.environ.get(
|
|||
CUSTOM_APPS = (
|
||||
'tastypie',
|
||||
'pokemon',
|
||||
'pokemon_v2',
|
||||
'hits',
|
||||
)
|
||||
INSTALLED_APPS = (
|
||||
|
@ -133,3 +134,15 @@ CORS_ORIGIN_ALLOW_ALL = True
|
|||
CORS_ALLOW_METHODS = (
|
||||
'GET'
|
||||
)
|
||||
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_RENDERER_CLASSES': (
|
||||
'rest_framework.renderers.JSONRenderer',
|
||||
),
|
||||
'DEFAULT_PARSER_CLASSES': (
|
||||
'rest_framework.parsers.JSONParser',
|
||||
),
|
||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
|
||||
'PAGE_SIZE': 20,
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ from django.conf.urls import patterns, include, url
|
|||
from django.conf.urls.static import static
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
|
@ -18,6 +17,14 @@ from pokemon.api import (
|
|||
PokedexResource
|
||||
)
|
||||
|
||||
from rest_framework import routers
|
||||
|
||||
from pokemon_v2 import views
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
|
||||
router.register(r"sprites", views.SpriteResource)
|
||||
|
||||
from tastypie.api import Api
|
||||
|
||||
api_resources = Api()
|
||||
|
@ -40,6 +47,7 @@ urlpatterns = patterns(
|
|||
name="documentation"),
|
||||
url(r'^about/$', 'config.views.about'),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^api/v2/', include(router.urls)),
|
||||
url(r'^api/', include(api_resources.urls)),
|
||||
url(r'^media/(?P<path>.*)',
|
||||
'django.views.static.serve',
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
from __future__ import unicode_literals
|
||||
from django.test import TestCase
|
||||
|
||||
from pokemon.models import Sprite
|
||||
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
|
||||
class HeaderTest(TestCase):
|
||||
|
||||
|
@ -13,3 +18,62 @@ class HeaderTest(TestCase):
|
|||
|
||||
self.assertEqual(response['Access-Control-Allow-Origin'], '*')
|
||||
|
||||
|
||||
class SpriteV2Resource(TestCase):
|
||||
"""
|
||||
All tests for the Sprite V2 resource.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(self):
|
||||
self.client = APIClient()
|
||||
|
||||
def test_get_sprite(self):
|
||||
"""
|
||||
Get a single sprite.
|
||||
"""
|
||||
|
||||
sp = Sprite.objects.create(
|
||||
name='test_sprite_image',
|
||||
image='image_url.jpg'
|
||||
)
|
||||
sp.save()
|
||||
|
||||
url = '/api/v2/sprites/{}/'.format(sp.pk)
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data['name'], sp.name)
|
||||
|
||||
|
||||
def test_get_sprite_not_found(self):
|
||||
"""
|
||||
Get a single sprite that doesn't exist, expects a 404 response
|
||||
"""
|
||||
|
||||
|
||||
url = '/api/v2/sprites/{}/'.format(12344556)
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
||||
|
||||
|
||||
def test_get_all_sprites(self):
|
||||
"""
|
||||
Try to get all the sprites!
|
||||
"""
|
||||
|
||||
sp = Sprite.objects.create(
|
||||
name='test_sprite_image',
|
||||
image='image_url.jpg'
|
||||
)
|
||||
sp.save()
|
||||
|
||||
sp_2 = Sprite.objects.create(
|
||||
name='test_sprite_image_two',
|
||||
image='image_url_second.jpg'
|
||||
)
|
||||
sp_2.save()
|
||||
|
||||
url = '/api/v2/sprites/'
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(len(response.data), 2)
|
||||
|
|
|
@ -1,4 +1,17 @@
|
|||
from __future__ import unicode_literals
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
|
||||
from pokemon.models import Sprite
|
||||
|
||||
from .serializers import SpriteSerializer
|
||||
|
||||
from rest_framework import viewsets
|
||||
|
||||
|
||||
class SpriteResource(viewsets.ReadOnlyModelViewSet):
|
||||
"""
|
||||
Views for the Sprite V2 Resource
|
||||
"""
|
||||
|
||||
queryset = Sprite.objects.all()
|
||||
serializer_class = SpriteSerializer
|
||||
|
|
Loading…
Reference in a new issue