Bläddra i källkod

Add "origin" field to the Pin model

"origin" is an optional field that stores the URI for the site
that the image has been saved from, it's going to be used only from
bookmarklet. Fixes #63
tags/v1.0.0
Krzysztof Klimonda 11 år sedan
förälder
incheckning
d0d68545ca
3 ändrade filer med 35 tillägg och 2 borttagningar
  1. +1
    -1
      pinry/core/api.py
  2. +2
    -1
      pinry/core/models.py
  3. +32
    -0
      pinry/core/tests.py

+ 1
- 1
pinry/core/api.py Visa fil

@@ -114,7 +114,7 @@ class PinResource(ModelResource):
return super(PinResource, self).save_m2m(bundle)

class Meta:
fields = ['id', 'url', 'description']
fields = ['id', 'url', 'origin', 'description']
ordering = ['id']
queryset = Pin.objects.all()
resource_name = 'pin'


+ 2
- 1
pinry/core/models.py Visa fil

@@ -29,7 +29,8 @@ class Image(BaseImage):

class Pin(models.Model):
submitter = models.ForeignKey(User)
url = models.TextField(blank=True, null=True)
url = models.URLField(null=True)
origin = models.URLField(null=True)
description = models.TextField(blank=True, null=True)
image = models.ForeignKey(Image, related_name='pin')
published = models.DateTimeField(auto_now_add=True)


+ 32
- 0
pinry/core/tests.py Visa fil

@@ -104,6 +104,37 @@ class PinResourceTest(ResourceTestCase):
pin = Pin.objects.get(url=url)
self.assertEqual(pin.tags.count(), 0)

@mock.patch('urllib2.urlopen', mock_urlopen)
def test_post_create_url_with_empty_origin(self):
url = 'http://testserver/mocked/screenshot.png'
post_data = {
'submitter': '/api/v1/user/1/',
'url': url,
'description': 'That\'s an Apple!',
'origin': None
}
response = self.api_client.post('/api/v1/pin/', data=post_data)
self.assertHttpCreated(response)
self.assertEqual(Pin.objects.count(), 3)
self.assertEqual(Image.objects.count(), 3)
self.assertEqual(Pin.objects.get(url=url).origin, None)

@mock.patch('urllib2.urlopen', mock_urlopen)
def test_post_create_url_with_origin(self):
origin = 'http://testserver/mocked/'
url = origin + 'screenshot.png'
post_data = {
'submitter': '/api/v1/user/1/',
'url': url,
'description': 'That\'s an Apple!',
'origin': origin
}
response = self.api_client.post('/api/v1/pin/', data=post_data)
self.assertHttpCreated(response)
self.assertEqual(Pin.objects.count(), 3)
self.assertEqual(Image.objects.count(), 3)
self.assertEqual(Pin.objects.get(url=url).origin, origin)

def test_post_create_obj(self):
user = User.objects.get(pk=1)
image = Image.objects.get(pk=1)
@@ -201,6 +232,7 @@ class PinResourceTest(ResourceTestCase):
},
},
u'url': self.pin_1.url,
u'origin': self.pin_1.origin,
u'description': self.pin_1.description,
u'tags': [u'creative-commons'],
})

Laddar…
Avbryt
Spara