Questions tagged [django-tests]

Use for questions about testing applications based upon the Python web framework Django, or the features provided in the module itself (django.test)

docs: https://docs.djangoproject.com/en/2.1/topics/testing/overview/

450 questions
4
votes
1 answer

AttributeError: This QueryDict instance is immutable for test cases

I am trying to change my request.data dict to remove some additional field. It is working completely fine in views. But when I run test cases for the same, I get this error: AttributeError: This QueryDict instance is immutable Here is my viewset: …
Aarti Joshi
  • 325
  • 1
  • 8
  • 17
4
votes
1 answer

request.data not always a queryDict

Using a PATCH request on a RetrieveUpdateDestroyAPIView I receive the following in RetrieveUpdateDestroyAPIView.update when i run print(request.data): {'myVar': ''} when running automated tests using django rest framework's APIClient I get…
Preston
  • 7,399
  • 8
  • 54
  • 84
4
votes
1 answer

Django Factory Boy Create vs create_batch

I am learning django test and i found django factory boy library very helpfull for writing testcase but one thing i am not getting.. forexample my one of Factory name is BlogFactory so i notice, most of the people use this like this:…
user11149657
4
votes
1 answer

DJANGO development server using TestCase database

GOAL: Run the DJANGO development server, using the TestCase database. Case: DJANGO produces this database when running a TestCase. Now I'm filling the database using DJANGO-autofixture. It would be really nice to start the DJANGO testserver using…
DA--
  • 723
  • 1
  • 8
  • 20
4
votes
1 answer

Install hstore extension for django tests

I am trying to install the hstore extension before running django tests. For that, I have overridden the default DiscoverRunner's setup_databases method. However, the extension is not installed & the tests show this error…
4
votes
6 answers

Django tests not finding my tests

When I run tests, django runs 0 tests. This is my project structure: manage.py - app/ - main_app/ - test/ - tests_v1.py - tests_v2.py I use this command: python manage.py test --pattern="tests_v*.py" Django runs 0 tests in 0…
Alejandro Veintimilla
  • 10,743
  • 23
  • 91
  • 180
4
votes
2 answers

Issue with assertNumQueries

I am trying to test the number of DB queries executed by an API in my Django application. So, I have a test case similar to the following: class DatabaseQueriesTestCase(TestCase): scan_uri = "something" def test_API_1(self): payload…
User_Targaryen
  • 4,125
  • 4
  • 30
  • 51
4
votes
0 answers

Django: how do I specify on which apps and migrations test case depends?

I want to speed up my tests by running only necessary migrations to build database. Currently, Django runs all of them. I know how to specify dependencies among migrations and actively use it. I watch for dependencies, most of my tests don't depend…
George Sovetov
  • 4,942
  • 5
  • 36
  • 57
4
votes
2 answers

Django: Keeping setUpTestData DRY

I've been really enjoying the convenience of setUpTestData and --keepdb in Django 1.8! However, I am running into an issue keeping data consistent across multiple test files. I'd like to have my setUpTestData classmethod in one location, and have…
Adam Starrh
  • 6,428
  • 8
  • 50
  • 89
4
votes
2 answers

django test client gets 404, but browser works

I am able to reach a local address through my web browser (http://127.0.0.1:8983/solr) to see the Solr Admin (search webapp). However, through the Django (1.7) test client I get: >>> from django.test import Client >>> c = Client() >>> response…
gatlanticus
  • 1,158
  • 2
  • 14
  • 28
4
votes
1 answer

Django 1.7 ImageField form validation

I'm writing unit tests using Django 1.7 with Python 3.4. The form below validates fine when the file_data element is commented out. With the file_data included it doesn't validate and the test fails. from django.core.files.uploadedfile import…
cms_mgr
  • 1,977
  • 2
  • 17
  • 31
4
votes
2 answers

Django: Multiple Databases, Routers and Test Framework

I'm currently writing the tests for our django application. Sadly we had to use a multiple database layout and can't change this. (Distributed databases with multiple backends on different servers across multiple datacenters) We have two…
MAGYS
  • 181
  • 1
  • 14
3
votes
1 answer

Wrap python decorator with another decorator

I have a common decorator call throughout my Django codebase: @override_settings( CACHES={ **settings.CACHES, "default": generate_cache("default", dummy=False), "throttling": generate_cache("throttling", dummy=False), …
Johnny Metz
  • 5,977
  • 18
  • 82
  • 146
3
votes
0 answers

Database queries to 'new-database' are not allowed in this test

I have added a new database in my django project. Now I have run into issues with my test cases. I am keep getting this error message for every single of my test cases: Database queries to 'new-database' are not allowed in this test I have searched…
3
votes
2 answers

Testing: TypeError: expected str, bytes or os.PathLike object, not NoneType

I'm testing user's creation but the test haven't reach the failed test because of the error given TypeError: expected str, bytes or os.PathLike object, not NoneType. I have the migrations using pass on using the AbstractUser giving the following on…
Rodragon
  • 135
  • 3
  • 12