Browse Source

Add a small (125x125px) square thumbnail

This is going to be used by a "similar images" feature #74
tags/v1.0.0
Krzysztof Klimonda 11 years ago
parent
commit
a0e11a949e
3 changed files with 42 additions and 3 deletions
  1. +2
    -0
      pinry/core/api.py
  2. +39
    -3
      pinry/core/tests.py
  3. +1
    -0
      pinry/settings/__init__.py

+ 2
- 0
pinry/core/api.py View File

@@ -41,6 +41,8 @@ class ImageResource(ModelResource):
attribute=lambda bundle: filter_generator_for('standard')(bundle))
thumbnail = fields.ToOneField(ThumbnailResource, full=True,
attribute=lambda bundle: filter_generator_for('thumbnail')(bundle))
square = fields.ToOneField(ThumbnailResource, full=True,
attribute=lambda bundle: filter_generator_for('square')(bundle))

class Meta:
fields = ['image', 'width', 'height']


+ 39
- 3
pinry/core/tests.py View File

@@ -37,12 +37,14 @@ class ImageResourceTest(ResourceTestCase):
self.client = Client()

def test_list_detail(self):
self.maxDiff = None
image = Image.objects.get(pk=1)
thumbnail = filter_generator_for('thumbnail')(image)
standard = filter_generator_for('standard')(image)
square = filter_generator_for('square')(image)
response = self.api_client.get('/api/v1/image/', format='json')
self.assertDictEqual(self.deserialize(response)['objects'][0], {
u'image': image.image.url,
u'image': unicode(image.image.url),
u'height': image.height,
u'width': image.width,
u'standard': {
@@ -54,7 +56,12 @@ class ImageResourceTest(ResourceTestCase):
u'image': unicode(thumbnail.image.url),
u'width': thumbnail.width,
u'height': thumbnail.height,
}
},
u'square': {
u'image': unicode(square.image.url),
u'width': square.width,
u'height': square.height,
},
})


@@ -100,6 +107,29 @@ class PinResourceTest(ResourceTestCase):
self.assertEqual(Pin.objects.count(), 3)
self.assertEquals(Tag.objects.count(), 4)

def test_put_details_unauthenticated(self):
uri = '/api/v1/pin/{}/'.format(self.pin_1.pk)
response = self.api_client.put(uri, format='json', data={})
self.assertHttpUnauthorized(response)

def test_put_details_unauthorized(self):
uri = '/api/v1/pin/{}/'.format(self.pin_1.pk)
User.objects.create_user('test', 'test@example.com', 'test')
self.api_client.client.login(username='test', password='test')
response = self.api_client.put(uri, format='json', data={})
self.assertHttpUnauthorized(response)

# def test_put_details(self):
# uri = '/api/v1/pin/{}/'.format(self.pin_1.pk)
# original = self.deserialize(self.api_client.get(uri, format='json'))
# new = original.copy()
# new['description'] = 'Updated description'
#
# self.assertEqual(Pin.objects.count(), 2)
# response = self.api_client.put(uri, format='json', data=new)
# self.assertHttpAccepted(response)
# self.assertEqual(Pin.objects.count(), 2)

def test_get_list_json_ordered(self):
pin = Pin.objects.latest('id')
response = self.api_client.get('/api/v1/pin/', format='json', data={'order_by': '-id'})
@@ -111,6 +141,7 @@ class PinResourceTest(ResourceTestCase):
image = Image.objects.get(pk=1)
standard = filter_generator_for('standard')(image)
thumbnail = filter_generator_for('thumbnail')(image)
square = filter_generator_for('square')(image)
response = self.api_client.get('/api/v1/pin/', format='json')
self.assertValidJSONResponse(response)
self.assertDictEqual(self.deserialize(response)['objects'][0], {
@@ -132,7 +163,12 @@ class PinResourceTest(ResourceTestCase):
u'image': unicode(thumbnail.image.url),
u'width': thumbnail.width,
u'height': thumbnail.height,
}
},
u'square': {
u'image': unicode(square.image.url),
u'width': square.width,
u'height': square.height,
},
},
u'url': self.pin_1.url,
u'description': self.pin_1.description,


+ 1
- 0
pinry/settings/__init__.py View File

@@ -91,4 +91,5 @@ INSTALLED_APPS = (
IMAGE_SIZES = {
'thumbnail': {'size': [240, 0]},
'standard': {'size': [600, 0]},
'square': {'crop': True, 'size': [125, 125]},
}

Loading…
Cancel
Save