AttributeError: 'Request' object has no attribute 'log' on TestCase
See original GitHub issueHello, I have stumbled upon the same thing on my test suite. I’m testing accessing the given resource without authentication.
class DriverReadFailureTests(APITestCase):
def setUp(self):
self.client = APIClient()
self.user = User.objects.create_superuser('admin', 'admin@admin.com', 'admin123')
self.client.force_login(user=self.user)
self.token = Token.objects.create(user=self.user)
self.client.post('/api/drivers/', data=driver_data, format='json')
self.client.post('/api/drivers/', data=driver_data_second, format='json')
self.client.logout()
def test_read_no_auth_driver(self):
"""Try to retrieve json representation of previously added driver.
"""
response = self.client.get('/api/drivers/')
self.assertEqual(response.status_code, 401)
Traceback: Error
Traceback (most recent call last):
File "/home/bkovacev/sally-projects/ops4/drivers/tests.py", line 316, in test_read_no_auth_driver
response = self.client.get('/api/drivers/')
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/rest_framework/test.py", line 282, in get
response = super(APIClient, self).get(path, data=data, **extra)
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/rest_framework/test.py", line 208, in get
return self.generic('GET', path, **r)
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/django/test/client.py", line 409, in generic
return self.request(**r)
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/rest_framework/test.py", line 279, in request
return super(APIClient, self).request(**kwargs)
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/rest_framework/test.py", line 231, in request
request = super(APIRequestFactory, self).request(**kwargs)
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/django/test/client.py", line 494, in request
six.reraise(*exc_info)
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 42, in inner
response = get_response(request)
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/rest_framework/views.py", line 483, in dispatch
response = self.handle_exception(exc)
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/rest_framework_tracking/mixins.py", line 80, in handle_exception
self.request.log.errors = traceback.format_exc()
File "/home/bkovacev/envs/ops4-env/local/lib/python2.7/site-packages/rest_framework/request.py", line 384, in __getattribute__
six.reraise(info[0], info[1], info[2].tb_next)
File "<string>", line 2, in reraise
AttributeError: 'Request' object has no attribute 'log'
How do I approach this?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Testing Login View - AttributeError: 'HttpRequest' object has ...
Django - Testing Login View - AttributeError: 'HttpRequest' object has no attribute 'user' ; in test_login_form logged_in = self.client.
Read more >Testing - Django REST framework
The login method is appropriate for testing APIs that use session authentication, for example web sites which include AJAX interaction with the API....
Read more >Getting AttributeError: 'TestCase' object has no attribute ...
Coding example for the question Getting AttributeError: 'TestCase' object has no attribute 'assertTemplateUsed' when trying to unit test views.py using ...
Read more >Understanding the Python Mock Object Library - Real Python
In this tutorial, you'll learn how to use the Python mock object library, unittest.mock, to create and use mock objects to improve your...
Read more >AttributeError: 'str' object has no attribute 'copy'
So check the python requests module version on both machines as well. Hopefully this helps,. Dave. Centaure13 (John) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@vince-stark Thanks again for taking an interest in helping out the project. I am always accepting of contributions to make this library better.
@avelis I think this one is fixed (if I check the PR which contains the commit #54 )