2015-12-09 22:02:27 +00:00
|
|
|
from rest_framework.test import APITestCase
|
|
|
|
from django.core.urlresolvers import reverse
|
2015-12-10 15:07:19 +00:00
|
|
|
from uuid import uuid4
|
2015-12-09 22:02:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ReverserTestCase(APITestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super().setUp()
|
|
|
|
|
2015-12-10 14:25:08 +00:00
|
|
|
def test_reverser(self):
|
2015-12-10 14:02:38 +00:00
|
|
|
response = self.client.post(reverse('reverser'), data={'ident': 'tests:root'})
|
2015-12-10 14:25:08 +00:00
|
|
|
self.assertEqual(response.data, reverse('tests:root'))
|
|
|
|
|
|
|
|
def test_invalid(self):
|
|
|
|
response = self.client.post(reverse('reverser'), data={'ident': 'tests:not_a_thing'})
|
|
|
|
self.assertEqual(response.status_code, 404)
|
2015-12-10 15:07:19 +00:00
|
|
|
|
|
|
|
def test_kwrgs_pass(self):
|
|
|
|
kwargs = {'uuid': str(uuid4())}
|
|
|
|
response = self.client.post(reverse('reverser'), data={
|
|
|
|
'ident': 'tests:uuid',
|
|
|
|
'kwargs': kwargs
|
|
|
|
}, format="json")
|
|
|
|
self.assertEqual(response.data, reverse('tests:uuid', kwargs=kwargs))
|
|
|
|
|
|
|
|
def test_args_pass(self):
|
|
|
|
args = (str(uuid4()),)
|
|
|
|
response = self.client.post(reverse('reverser'), data={
|
|
|
|
'ident': 'tests:uuid',
|
|
|
|
'args': args
|
|
|
|
}, format="json")
|
|
|
|
self.assertEqual(response.data, reverse('tests:uuid', args=args))
|
2015-12-10 18:10:11 +00:00
|
|
|
|
|
|
|
def test_invalid_kwargs(self):
|
|
|
|
kwargs = {'not_uuid': str(uuid4())}
|
|
|
|
response = self.client.post(reverse('reverser'), data={
|
|
|
|
'ident': 'tests:uuid',
|
|
|
|
'kwargs': kwargs
|
|
|
|
}, format="json")
|
|
|
|
self.assertEqual(response.status_code, 404)
|
|
|
|
|
|
|
|
def test_multi_kwargs(self):
|
|
|
|
kwargs = {
|
|
|
|
'uuid': str(uuid4()),
|
|
|
|
'pk': str(uuid4())
|
|
|
|
}
|
|
|
|
response = self.client.post(reverse('reverser'), data={
|
|
|
|
'ident': 'tests:multi',
|
|
|
|
'kwargs': kwargs
|
|
|
|
}, format="json")
|
|
|
|
self.assertEqual(response.data, reverse('tests:multi', kwargs=kwargs))
|
|
|
|
|
|
|
|
def test_multi_args(self):
|
|
|
|
args = (str(uuid4()), str(uuid4()))
|
|
|
|
response = self.client.post(reverse('reverser'), data={
|
|
|
|
'ident': 'tests:multi',
|
|
|
|
'args': args
|
|
|
|
}, format="json")
|
|
|
|
self.assertEqual(response.data, reverse('tests:multi', args=args))
|