Browse Source

In PinResource.save_m2m do nothing when no tags

tags/v1.0.0
Krzysztof Klimonda 11 years ago
parent
commit
8c3599911e
2 changed files with 19 additions and 2 deletions
  1. +3
    -2
      pinry/core/api.py
  2. +16
    -0
      pinry/core/tests.py

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

@@ -108,8 +108,9 @@ class PinResource(ModelResource):
return orm_filters

def save_m2m(self, bundle):
tags = bundle.data.get('tags', [])
bundle.obj.tags.set(*tags)
tags = bundle.data.get('tags', None)
if tags:
bundle.obj.tags.set(*tags)
return super(PinResource, self).save_m2m(bundle)

class Meta:


+ 16
- 0
pinry/core/tests.py View File

@@ -88,6 +88,22 @@ class PinResourceTest(ResourceTestCase):
self.assertEqual(Pin.objects.count(), 3)
self.assertEqual(Image.objects.count(), 3)

@mock.patch('urllib2.urlopen', mock_urlopen)
def test_post_create_url_empty_tags(self):
url = 'http://testserver/mocked/screenshot.png'
post_data = {
'submitter': '/api/v1/user/1/',
'url': url,
'description': 'That\'s an Apple!',
'tags': []
}
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)
pin = Pin.objects.get(url=url)
self.assertEqual(pin.tags.count(), 0)

def test_post_create_obj(self):
user = User.objects.get(pk=1)
image = Image.objects.get(pk=1)


Loading…
Cancel
Save