2014-12-04 11:11:46 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from django.test import TestCase
|
|
|
|
|
2015-03-11 20:07:30 +00:00
|
|
|
from pokemon.models import Sprite
|
|
|
|
|
|
|
|
from rest_framework import status
|
|
|
|
from rest_framework.test import APIClient
|
|
|
|
|
2014-12-06 22:57:42 +00:00
|
|
|
|
|
|
|
class HeaderTest(TestCase):
|
|
|
|
|
|
|
|
def test_pokemon(self):
|
|
|
|
|
|
|
|
response = self.client.get(
|
2014-12-07 16:32:09 +00:00
|
|
|
'/api/v2/pokemon/1/',
|
2014-12-07 16:56:21 +00:00
|
|
|
HTTP_ORIGIN="http://pokemon.com"
|
2014-12-07 16:32:09 +00:00
|
|
|
)
|
2014-12-15 10:13:52 +00:00
|
|
|
|
2014-12-06 22:57:42 +00:00
|
|
|
self.assertEqual(response['Access-Control-Allow-Origin'], '*')
|
2014-12-07 16:38:15 +00:00
|
|
|
|
2015-03-11 20:07:30 +00:00
|
|
|
|
|
|
|
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)
|