mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-24 20:33:04 +00:00
merge with what @phalt has done so far
This commit is contained in:
commit
744193dcab
7 changed files with 157 additions and 31 deletions
4
Makefile
4
Makefile
|
@ -1,9 +1,9 @@
|
|||
install:
|
||||
sudo pip install -r requirements.txt
|
||||
pip install -r requirements.txt --upgrade
|
||||
|
||||
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
|
||||
|
|
|
@ -114,7 +114,7 @@ SECRET_KEY = os.environ.get(
|
|||
|
||||
CUSTOM_APPS = (
|
||||
'tastypie',
|
||||
# 'pokemon',
|
||||
'pokemon',
|
||||
'pokemon_v2',
|
||||
'hits',
|
||||
)
|
||||
|
@ -128,7 +128,7 @@ INSTALLED_APPS = (
|
|||
'django.contrib.admin',
|
||||
'django.contrib.humanize',
|
||||
'corsheaders',
|
||||
'rest_framework'
|
||||
'rest_framework',
|
||||
) + CUSTOM_APPS
|
||||
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
@ -22,6 +21,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()
|
||||
|
@ -44,13 +51,13 @@ api_resources.register(PokedexResource())
|
|||
|
||||
from rest_framework import routers
|
||||
from pokemon_v2.views import (
|
||||
AbilityResource, TestResource
|
||||
AbilityResource, SpriteResource
|
||||
)
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
|
||||
router.register(r"ability", AbilityResource)
|
||||
router.register(r"test", TestResource)
|
||||
router.register(r"sprite", SpriteResource)
|
||||
|
||||
|
||||
###########################
|
||||
|
|
|
@ -1,10 +1,63 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
from rest_framework import serializers
|
||||
from pokemon_v2.models import (
|
||||
Ability
|
||||
|
||||
"""
|
||||
PokeAPI v2 serializers
|
||||
"""
|
||||
|
||||
from pokemon.models import (
|
||||
Sprite
|
||||
)
|
||||
|
||||
from .models import (
|
||||
Ability,
|
||||
Move,
|
||||
Nature,
|
||||
Type
|
||||
)
|
||||
|
||||
|
||||
class AbilitySerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
Serializer for the Ability resource
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Ability
|
||||
fields = ('id', 'name', 'generation', 'is_main_series')
|
||||
|
||||
|
||||
class MoveSerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
Serializer for the Move resource
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Move
|
||||
|
||||
|
||||
class NatureSerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
Serializer for the Nature resource
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Nature
|
||||
|
||||
|
||||
class SpriteSerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
Serializer for the Type resource
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Sprite
|
||||
|
||||
|
||||
class TypeSerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
Serializer for the Type resource
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Type
|
||||
|
|
|
@ -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,30 +1,32 @@
|
|||
# from __future__ import unicode_literals
|
||||
# from django.http import HttpResponse
|
||||
#
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework.response import Response
|
||||
|
||||
from pokemon_v2.serializers import (
|
||||
AbilitySerializer
|
||||
from __future__ import unicode_literals
|
||||
from rest_framework import viewsets
|
||||
|
||||
from pokemon.models import (
|
||||
|
||||
Sprite
|
||||
)
|
||||
|
||||
from pokemon_v2.models import (
|
||||
from .models import (
|
||||
Ability
|
||||
)
|
||||
|
||||
from .serializers import (
|
||||
AbilitySerializer, SpriteSerializer
|
||||
)
|
||||
|
||||
class SpriteResource(viewsets.ReadOnlyModelViewSet):
|
||||
"""
|
||||
Views for the Sprite V2 Resource
|
||||
"""
|
||||
|
||||
queryset = Sprite.objects.all()
|
||||
serializer_class = SpriteSerializer
|
||||
|
||||
class AbilityResource(viewsets.ReadOnlyModelViewSet):
|
||||
"""
|
||||
Views for the Ability V2 Resource
|
||||
"""
|
||||
|
||||
queryset = Ability.objects.all()
|
||||
serializer_class = AbilitySerializer
|
||||
|
||||
|
||||
# @api_view(['GET', 'POST'])
|
||||
class TestResource():
|
||||
|
||||
queryset = Ability.objects.all()
|
||||
serializer_class = AbilitySerializer
|
||||
|
||||
def get(self, request, pk, format=None):
|
||||
return Response("hello Test")
|
||||
|
|
|
@ -8,7 +8,7 @@ django-cors-headers==1.0.0
|
|||
django-discover-runner==0.4
|
||||
django-imagekit==3.2.4
|
||||
django-tastypie==0.12.1
|
||||
djangorestframework==3.0.0
|
||||
djangorestframework>=3.0.0
|
||||
gunicorn==0.17.0
|
||||
mimeparse==0.1.3
|
||||
pilkit==1.1.12
|
||||
|
|
Loading…
Reference in a new issue