class ProcessDocRequestTestCase(BxApiTestCase): username = 'hr'
def test_email_sent_on_creation(self):
r = r0 = self.r('post', 201, '/api/processes', %post_data%)
requestor_superior_id = r0.data['extra']['next_employees'][0]
superior_emp = Employee.objects.get(pk=requestor_superior_id)
employee_serializer = EmployeeSerializer(superior_emp, context={'request': r})
employee_serializer.data
the last line crashes with this error:
Traceback (most recent call last): File "/my_proj/bx/process/tests.py", line 81, in test_email_sent_on_creation employee_serializer.data File "/my_proj/venv/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 503, in data ret = super(Serializer, self).data File "/my_proj/venv/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 239, in data self._data = self.to_representation(self.instance) File "/my_proj/venv/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 472, in to_representation ret[field.field_name] = field.to_representation(attribute) File "/my_proj/venv/local/lib/python2.7/site-packages/rest_framework/relations.py", line 340, in to_representation url = self.get_url(value, self.view_name, request, format) File "/my_proj/venv/local/lib/python2.7/site-packages/rest_framework/relations.py", line 277, in get_url return self.reverse(view_name, kwargs=kwargs, request=request, format=format) File "/my_proj/venv/local/lib/python2.7/site-packages/rest_framework/reverse.py", line 50, in reverse url = _reverse(viewname, args, kwargs, request, format, **extra) File "/my_proj/venv/local/lib/python2.7/site-packages/rest_framework/reverse.py", line 65, in _reverse return request.build_absolute_uri(url) AttributeError: 'Response' object has no attribute 'build_absolute_uri'
how do I do this?
for reference, my r method is defined like so:
from rest_framework.test import APIClient
..
def setUp(self):
self.refreshTestData()
self.c = APIClient()
if getattr(self, 'username', None):
self.login(self.username, self.password)
def r(self, method, status_code, url, data=None, *args, **kwargs):
kwargs['data'] = data
kwargs['format'] = kwargs.get('format', 'json')
r = getattr(self.c, method)(url, *args, **kwargs)
self.assertEqual(r.status_code, status_code,
'Expected status %d, got %d.\n%s\n%s' % (
status_code, r.status_code, url, pformat(getattr(r, 'data', None))) )
return r