I have following easy test:
class DeviceListTests(APITestCase):
def test_devices_list(self):
self.user = UserFactory()
self.device = DeviceFactory(name="SoundTalks_device")
self.client.force_login(self.user)
response = self.client.get(
reverse("device-list")
)
Python/Django is returning an error on:
response = self.client.get(
reverse("device-list")
)
However this is an easy request, I get following error:
Traceback (most recent call last):
File "/opt/project/integrator_api/devices/tests/test_get_devices.py", line 15, in test_devices_list
reverse("device-list")
File "/usr/local/lib/python3.6/site-packages/rest_framework/test.py", line 286, in get
response = super().get(path, data=data, **extra)
File "/usr/local/lib/python3.6/site-packages/rest_framework/test.py", line 203, in get
return self.generic('GET', path, **r)
File "/usr/local/lib/python3.6/site-packages/rest_framework/test.py", line 232, in generic
method, path, data, content_type, secure, **extra)
File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 422, in generic
return self.request(**r)
File "/usr/local/lib/python3.6/site-packages/rest_framework/test.py", line 283, in request
return super().request(**kwargs)
File "/usr/local/lib/python3.6/site-packages/rest_framework/test.py", line 235, in request
request = super().request(**kwargs)
File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 503, in request
raise exc_value
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
TypeError: __init__() takes 1 positional argument but 2 were given
app_1 |
app_1 | Aborting on container exit...
Stopping integrator-api_app_1 ...
Stopping integrator-api_app_1 ... done
Process finished with exit code 1
devices/urls.py
from django.conf.urls import url
from rest_framework.urlpatterns import format_suffix_patterns
from integrator_api.devices.views.device_list_view import DeviceListView
urlpatterns = format_suffix_patterns(
[
url(r"^$", DeviceListView, name="device-list"),
]
)
integrator_api/urls.py (project urls)
from django.urls import path, include
from integrator_api.devices import urls as device_urls
urlpatterns = [
path("devices/", include(device_urls)),
]
question from:
https://stackoverflow.com/questions/65873437/django-client-get-typeerror-init-takes-1-positional-argument-but-2-were