From 8c3599911e0a21b8028e4714ba05b7eb585b657d Mon Sep 17 00:00:00 2001 From: Krzysztof Klimonda Date: Sun, 3 Mar 2013 06:20:50 -0800 Subject: [PATCH] In PinResource.save_m2m do nothing when no tags --- pinry/core/api.py | 5 +++-- pinry/core/tests.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pinry/core/api.py b/pinry/core/api.py index e9fe5da..3a30557 100644 --- a/pinry/core/api.py +++ b/pinry/core/api.py @@ -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: diff --git a/pinry/core/tests.py b/pinry/core/tests.py index 8732451..06069ad 100644 --- a/pinry/core/tests.py +++ b/pinry/core/tests.py @@ -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)