Ver código fonte

Fixed tests not passing on postgresql.

pull/68/head
Krzysztof Klimonda 10 anos atrás
pai
commit
b79e6249ea
3 arquivos alterados com 14 adições e 9 exclusões
  1. +9
    -6
      pinry/core/tests/api.py
  2. +3
    -1
      pinry/core/tests/helpers.py
  3. +2
    -2
      pinry/users/tests.py

+ 9
- 6
pinry/core/tests/api.py Ver arquivo

@@ -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)



+ 3
- 1
pinry/core/tests/helpers.py Ver arquivo

@@ -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'


+ 2
- 2
pinry/users/tests.py Ver arquivo

@@ -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))


Carregando…
Cancelar
Salvar