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
8
votes
2 answers

Testing django application with several legacy databases

I have django application with 5 legacy databases. Almost all models are set with the meta attribute managed=False. Since managed=False is set, migrations for each model have been created with the option managed=False. And since, django test runner…
AmirM
  • 1,089
  • 1
  • 12
  • 26
8
votes
1 answer

KeyError: 'HTTP_HOST' when running django tests

I am new to unit testing so I have no idea what I am doing wrong. I use python2.7 with Django1.8 When I run python manage.py test myapp --keepdb I get ====================================================================== ERROR: test_view_content…
Zoli
  • 831
  • 1
  • 11
  • 27
7
votes
1 answer

Unit tests project with multiple application and databases - Circular dependency in TEST[DEPENDENCIES]

So I've got a django project with several applications. Each application use its own database, and they share a common database containing django tables (such as auth, sessions). For this I've got several database routers, so my settings looks like…
May.D
  • 1,832
  • 1
  • 18
  • 34
7
votes
3 answers

Setting liveserver port when running tests in django

I am using django for a webapp and I'm using docker to deploy it. I need to test it in the container with selenium. I'm using selenium grid for testing. In order to connect with the liveserver on the docker, i need to port forward a specific port,…
7
votes
1 answer

Django Test client.get() returns 302 code instead of 200

Running a test on a url returns 302 instead of 200. Yet testing the same urls in production with a redirect tester returns 200. Not really sure what's going on. tests.py def test_detail(self): response =…
KingFu
  • 1,358
  • 5
  • 22
  • 42
7
votes
2 answers

Django UnitTest - Setting session variable

I have a Django unit test class that is based on django_webtest.WebTest, and I can't find a proper way to set a session variable during the test. I have tried the following, but I don't work from django_webtest import WebTest class…
user1187968
  • 7,154
  • 16
  • 81
  • 152
7
votes
2 answers

HttpResponseRedirect' object has no attribute 'client'

Django 1.9.6 I'd like to write some unit test for checking redirection. Could you help me understand what am I doing wrongly here. Thank you in advance. The test: from django.test import TestCase from django.core.urlresolvers import reverse from…
Michael
  • 4,273
  • 3
  • 40
  • 69
7
votes
3 answers

How to run all tests with python manage.py test command in django

I am working on a django project in which I have multiple apps. Every app has a tests directory which has test for whole project. My directory structure is as follow. Project App_1 tests __init__.py …
Muhammad Hassan
  • 14,086
  • 7
  • 32
  • 54
7
votes
3 answers

Django Test Case Error 'WSGIRequest' object has no attribute 'session'

I'm trying to write some tests for my django app and it's throwing up an error: File "/Users/croberts/.virtualenvs/litem/lib/python3.4/site-packages/django/contrib/auth/__init__.py", line 101, in login if SESSION_KEY in…
Chase Roberts
  • 9,082
  • 13
  • 73
  • 131
7
votes
1 answer

How to test a custom python-social-auth pipeline?

So, I have created a custom pipeline for saving user's social profile data fetched from extra_data attribute of the user.social_auth model. I have thoroughly tested it, but manually. How do I automate testing for my custom pipeline, by using…
shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
7
votes
1 answer

Django test database not auto-flushing

I have a bunch of unit test files, all of which consist of django.test.TestCase classes. Wrote myself a little shell script to uncomment/comment test file imports in my __init__.py file, so I can run tests from certain test files, based off the…
pleasedesktop
  • 1,395
  • 3
  • 14
  • 25
6
votes
1 answer

Django 3.0 — database connections are not closed after async tests

I use Django ORM inside async code. Everything works fine and all tests pass. However, DB connections do not close properly after tests. Here is an example: from asgiref.sync import sync_to_async, async_to_sync @sync_to_async def count_books(): …
Max Malysh
  • 29,384
  • 19
  • 111
  • 115
6
votes
3 answers

Assertion error while testing Django views

This is my testing function for views.py which I have mention below: def test_operation_page(self): url = reverse('operation') response = self.client.get(url) self.assertEqual(response.status_code, 200) …
Sachin
  • 185
  • 1
  • 3
  • 10
6
votes
2 answers

Django channels pytest testing. django.core.exceptions.ImproperlyConfigured. .

I am getting this error when running pytest. I am following this tutorial: https://channels.readthedocs.io/en/latest/topics/testing.html django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured.…
6
votes
1 answer

How to perform a Django test with a request.post?

I'm using Django 1.8 and Python 3.5. I have a view method I would love to test. I am supplying the self.client.get method with the data but it fails to validate the form. what am I doing wrong? This is the view method: def…
Blue
  • 195
  • 1
  • 4
  • 9
1
2
3
29 30