Skip to main content

All Questions

1 vote
1 answer
30 views

Django session in tests

everyone! I can't figure out how the sessions work in Django. I have a shop, an anonymous user's shopping cart is bound to session_key. The session key is taken from the request object. def ...
Андрей's user avatar
1 vote
1 answer
28 views

DRF test user sign-in, error inactive user

I have view for authentfication: class UserViewSet(viewsets.ViewSet): @method_decorator(sensitive_variables("password")) @action(url_path="sign-in", detail=False, methods=[&...
Андрей's user avatar
0 votes
1 answer
66 views

Django Ignoring TestCases

There are loads of questions with this issue, but whatever I try, it just doesn't want to work. This is the file structure of my project. As you can see, all directories have an init file. Here is ...
domjanzsoo's user avatar
0 votes
1 answer
42 views

Django Rest Framework (DRF) authenticate is not working with unit test database?

I have a BaseTestCase class for base set up. Let me show you the problem: class UserTestCase(BaseTestCase): def test_auth_login(self): self.client.logout() url = "/auth/login/" ...
Selman Faruk Yılmaz's user avatar
0 votes
0 answers
99 views

Django DB API testing: Destroying test database for alias 'default'... throw error

i'm using django rest framework and mongo DB for app backend. I'm implementing a testsuite ex: class RegisterViewSetTestCase(APITestCase): def setUp(self): def test1(self): I'm runnig my ...
Bobuse's user avatar
  • 3
3 votes
1 answer
390 views

Why is Django test cases checking actual DB and raising IntegrityError instead of just running in-memory?

When I run my tests with the DB empty (the actual application DB), everything goes fine. But when the DB has data, Django raises an IntegrityError for basically every test. The stact trace looks like ...
Ramon K.'s user avatar
  • 3,442
1 vote
1 answer
80 views

DRF APITestCase force_authenticate make request.user return tuple instead of User object

I have a custom authentication class following the docs class ExampleAuthentication(authentication.BaseAuthentication): def authenticate(self, request): username = request.META.get('...
Linh Nguyen's user avatar
  • 3,760
0 votes
1 answer
35 views

DRF - Testing, error while hitting sinlgle data from id

Urls.py router = routers.DefaultRouter() router.register('zone', views.ZoneViewSet, basename='zone') app_name = 'address' API. urlpatterns = [ path('', include(router.urls)), ] Test.py ...
Shiva Giri's user avatar
1 vote
1 answer
334 views

Test doesn't remove generated files using factory_boy in django

I'm using factory_boy to generate arbitrary data to run tests. but after each test it doesn't delete files automatically. Is there anything I should add? Any suggestion is highly appreciated Model for ...
henok's user avatar
  • 43
0 votes
1 answer
778 views

Adding a custom header 'FOO' to Django Rest Framework APIClient

For an application that uses SSO for login I have implemented a AuthBackend with Django Rest Framework. This custom AuthBackend class checks for the USERID present in the headers and based on that ...
abybaddi009's user avatar
  • 1,044
1 vote
1 answer
288 views

django rest framework APITestCase including file fields

How can I write a test for the following code snippet? I have trouble with handling files. Extra files are created in the media folder and also the test does not work properly. Searching was useless. #...
originull4's user avatar
0 votes
0 answers
508 views

Django Rest Framework - "You do not have permission to perform this action" in tests

I have Profile model which is custom user model. When I try to change it (sending patch request) via postman, all is ok. But when I try to do it in tests in returns "You do not have permission to ...
Aziz Nadirov's user avatar
0 votes
1 answer
246 views

ListAPIView with the querset User.objects.all() makes 7 queries with only two users in the test database?

I was creating an endpoint using drf to list users. While testing the code, I realized that it calls 7 queries. models.py:(I think using django's User model will achieve the same result) class ...
Zeddling's user avatar
0 votes
2 answers
1k views

Testing image uploads in Django REST Framework

I'm trying to add some tests to one of my apps in a Django project. This app includes the Image model: from django.db import models from django.utils.translation import gettext_lazy as _ from ...
Angel Bonilla's user avatar
0 votes
0 answers
116 views

Sign Up view test not passing [Django REST]

I'm trying to test the sign up view in Django using REST Framework but I'm getting an assertio error AssertionError: 201 != 400 when defining self.assertEqual(status.HTTP_201_CREATED, response....
Rodragon's user avatar

15 30 50 per page