diff --git a/pinry/core/tests/api.py b/pinry/core/tests/api.py index afed398..19dbecf 100644 --- a/pinry/core/tests/api.py +++ b/pinry/core/tests/api.py @@ -68,7 +68,7 @@ class PinResourceTest(ResourceTestCase): def test_post_create_url(self): url = 'http://testserver/mocked/logo.png' post_data = { - 'submitter': '/api/v1/user/1/', + 'submitter': '/api/v1/user/{}/'.format(self.user.pk), 'url': url, 'description': 'That\'s an Apple!' } @@ -90,7 +90,7 @@ class PinResourceTest(ResourceTestCase): def test_post_create_url_with_empty_tags(self): url = 'http://testserver/mocked/logo.png' post_data = { - 'submitter': '/api/v1/user/1/', + 'submitter': '/api/v1/user/{}/'.format(self.user.pk), 'url': url, 'description': 'That\'s an Apple!', 'tags': [] @@ -120,7 +120,7 @@ class PinResourceTest(ResourceTestCase): def test_post_create_url_with_empty_origin(self): url = 'http://testserver/mocked/logo.png' post_data = { - 'submitter': '/api/v1/user/1/', + 'submitter': '/api/v1/user/{}/'.format(self.user.pk), 'url': url, 'description': 'That\'s an Apple!', 'origin': None @@ -136,7 +136,7 @@ class PinResourceTest(ResourceTestCase): origin = 'http://testserver/mocked/' url = origin + 'logo.png' post_data = { - 'submitter': '/api/v1/user/1/', + 'submitter': '/api/v1/user/{}/'.format(self.user.pk), 'url': url, 'description': 'That\'s an Apple!', 'origin': origin @@ -156,7 +156,10 @@ class PinResourceTest(ResourceTestCase): 'tags': ['random', 'tags'], } response = self.api_client.post('/api/v1/pin/', data=post_data) - self.assertEqual(self.deserialize(response)['id'], 1) + self.assertEqual( + self.deserialize(response)['description'], + 'That\'s something else (probably a CC logo)!' + ) self.assertHttpCreated(response) # A number of Image objects should stay the same as we are using an existing image self.assertEqual(Image.objects.count(), 1) @@ -210,7 +213,7 @@ class PinResourceTest(ResourceTestCase): def test_get_list_json_filtered_by_tags(self): pin = PinFactory() - response = self.api_client.get('/api/v1/pin/', format='json', data={'tag': pin.tags.get(pk=1)}) + response = self.api_client.get('/api/v1/pin/', format='json', data={'tag': pin.tags.all()[0]}) self.assertValidJSONResponse(response) self.assertEqual(self.deserialize(response)['objects'][0]['id'], pin.pk) diff --git a/pinry/core/tests/helpers.py b/pinry/core/tests/helpers.py index 4abc37e..7dd1f35 100644 --- a/pinry/core/tests/helpers.py +++ b/pinry/core/tests/helpers.py @@ -68,7 +68,9 @@ class PinFactory(factory.Factory): class PinFactoryTest(TestCase): def test_default_tags(self): - self.assertTrue(PinFactory().tags.get(pk=1).name.startswith('tag_')) + tags = PinFactory.create().tags.all() + self.assertTrue(all([tag.name.startswith('tag_') for tag in tags])) + self.assertEqual(tags.count(), 1) def test_custom_tag(self): custom = 'custom_tag' diff --git a/pinry/users/tests.py b/pinry/users/tests.py index e21c0af..c9752e1 100644 --- a/pinry/users/tests.py +++ b/pinry/users/tests.py @@ -37,14 +37,14 @@ class CombinedAuthBackendTest(TestCase): @mock.patch('requests.get', mock_requests_get) def test_has_perm_on_pin(self): image = Image.objects.create_for_url('http://testserver/mocked/screenshot.png') - user = User.objects.get(pk=1) + user = User.objects.get(username=self.username) pin = Pin.objects.create(submitter=user, image=image) self.assertTrue(self.backend.has_perm(user, 'add_pin', pin)) @mock.patch('requests.get', mock_requests_get) def test_has_perm_on_pin_unauthorized(self): image = Image.objects.create_for_url('http://testserver/mocked/screenshot.png') - user = User.objects.get(pk=1) + user = User.objects.get(username=self.username) other_user = User.objects.create_user('test', 'test@example.com', 'test') pin = Pin.objects.create(submitter=user, image=image) self.assertFalse(self.backend.has_perm(other_user, 'add_pin', pin))