1,225 questions
0
votes
0
answers
31
views
Flaky Circle CI tests (django): ImportError: cannot import name "task" from "app.tasks" (unknown location)
Sometimes, I have many flaky test failures due to one error:
ImportError: cannot import name 'task_import_events_to_db' from
'app.tasks' (unknown location)
It seems the tests fail because of this ...
1
vote
1
answer
62
views
CheckConstraint in Django model not triggering in unittest.TestCase (AssertionError: IntegrityError not raised)
I have a Model class with a series of constraints that I am attempting to test, and I am unable to get these constraints to return an IntegrityError in testing. The class is as follows:
from django.db ...
0
votes
1
answer
80
views
Django Testing: Use main database as only one database available?
I am a university student, and I decided to use Django for my final year project. This means I am limited to using the University's MySQL database server. On the server, I am only allowed to have one ...
0
votes
3
answers
63
views
Django test client redirects logged users to login page
I know this questions has already been asked, but none of the answers works for me.
Whenever I try to use the client login in Django tests, it basically gets ignored and I get a redirect to the login ...
0
votes
0
answers
43
views
Importing login of users/tests module to another application/tests not working in Django
I'm trying to avoid code duplication so I want to import login from users/test to the ordering/test where I need to test different views that have @login_required.
users/test.py
User = get_user_model()...
1
vote
1
answer
41
views
How do I pass request to a form in test
I am trying to pass request to a Django form in unittest. This is my test:
def test_AddPairedStudyForm(self):
self.client.force_login(self.user)
request = RequestFactory().get(reverse("...
0
votes
1
answer
37
views
Defining test methods in base class which should not be instanciated directly
I am trying to create test cases which only differ by which user is logged in.
Therefore I figured defining the tests in a base class and creating sub classes which log in the user during setUp() ...
2
votes
0
answers
424
views
Django- How to use django-silk to work in running tests
I use the django-silk to profile the APIs of my Django project (Django + DRF). Currently, I call APIs in the browser (using DRF browsable API) and then I can see the API profiling data in the silk. ...
0
votes
0
answers
34
views
AssertionError in Django Unit Test: Unable to Retrieve Correct Count from Database
I'm encountering an AssertionError in my Django unit test when attempting to save a POST request to an existing list. Despite creating the list and sending the POST request successfully, the test ...
1
vote
1
answer
290
views
Django SimpleUploadedFile is not being sent
I'm developing Django application and wrote a test that checks if view method acts correctly. I need to send some data in request, including the image file.
In my case:
def setUp(self):
...
self....
3
votes
1
answer
221
views
Django Tests - TemplateSyntaxError: 'socialaccount' is not a registered tag library while running tests
I'm trying to run Django tests but I'm encountering with this error - django.template.exceptions.TemplateSyntaxError: 'socialaccount' is not a registered tag library., but normally it have to work ...
0
votes
1
answer
110
views
How do I test ExportActionMixin in Django?
I'd like to test files produced on the admin website by import_export.admin.ExportActionMixin in Django.
In particular I'd like to test the admin command by looking into the file (which I download on ...
1
vote
1
answer
122
views
Test post django function
I have django function, that takes JSON-data from request, validates it and save to db.
I want to test this func, but POST request doesn’t work, error
‘json.decoder.JSONDecodeError: Expecting value: ...
0
votes
1
answer
101
views
I want to add a DRF API route only for testing (override_settings), getting 404
I want the following test to pass, but I am always getting a 404 Error. But I would expect the "get all" request to return all users.
import json
from django.test.utils import ...
0
votes
1
answer
50
views
Data missing (files) in my django serializer
I have an issue, some data are missing in my serializer (in validate and create functions).
My Model:
class PostsImage(models.Model):
image = models.ImageField(upload_to="posts/images")
...
2
votes
2
answers
1k
views
How can I see the body of the request that Django's test client makes
I am writing automated tests in Django and started writing tests for an API endpoint that supports the put method.
I am making my put request like so:
response = self.client.put(path, data=json.dumps({...
1
vote
1
answer
32
views
Tests - both classes share the same login code but it only works in one
I'm writing tests for locallibrary app following the tutorial on MDN. Both classes that test views share similar login code, but it only works in one class
I tried finding spelling errors and comping ...
1
vote
1
answer
483
views
Adding custom header to DRF test APIClient
I need to add a custom header to the APIClient for a test.
I have tried to follow this section of the official docs
from rest_framework.test import APIClient
client = APIClient()
client.credentials(...
0
votes
1
answer
235
views
How to send POST request with query params for image field in django tests
I have test.py
from rest_framework.test import APITestCase
from django.core.files.uploadedfile import SimpleUploadedFile
from django.urls import reverse
class PostImageTest(APITestCase):
def ...
0
votes
1
answer
55
views
"Select a valid choice. That choice is not one of the available choices" error on OneToOneField
models.py
class Major(models.Model):
major = models.CharField(max_length=50, unique=True)
description = models.TextField()
image = models.ImageField(default='default_pics/default_major.jpg'...
1
vote
0
answers
149
views
Unable to route to test pages using Wagtail Factories and Factory Boy
I'm trying to implement factory boy and wagtail factories to generate tests for the blog section of my site, at /blog/, which uses Wagtail CMS. However, I'm getting a 404 error when doing self....
1
vote
3
answers
819
views
Why is the page I am testing returning a 301 response instead of a 200 response?
I am writing tests for class-based views in the django project I am writing as part of a course. Currently, I am stuck trying trying to test a view that directs to an edit page that requires a user to ...
0
votes
1
answer
441
views
Override test settings from a file
For context, when one wants to change settings in a test (yes, it's ok to change it there), we can use override_settings() or modify_settings() (as observed here). That works when running the tests in ...
0
votes
1
answer
218
views
How to create test bucket before running tests by django-minio-backend
I use django-minio-backend in order to integrate Django and Minio.
I want to create a test bucket for created media files during tests running.
I tried to do that in a custom test runner as follows:
...
3
votes
2
answers
746
views
Disable logging bad requests while unittest django app
I have a tests in my Django app. They're working well, but i want to disable showing console logging like .Bad Request: /api/v1/users/register/
One of my tests code
def ...