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
0
votes
1 answer

Running tests for third-party Django app results in "ImportError: No module named urls"

I've installed a not-yet-open sourced third-party Django app using pip and now I'm implementing unit tests for it. However, whenever I try running the unit tests, it results in the following traceback for each test case: ERROR: test_form_page_loads…
3cheesewheel
  • 9,133
  • 9
  • 39
  • 59
0
votes
2 answers

Is there anyway to use initial data without reinstalling custom sql?

I'm new to django and I wonder if there is anyway to use initial data without reinstalling custom sql each time. My initial data is almost 100MB and it's kind of painful to wait for database import for each test. I'm trying to find a way to do it…
eneepo
  • 1,407
  • 3
  • 21
  • 32
-1
votes
1 answer

Django tests - getting BadZipFile with openpyxl

I have an export function for excel files with filters. The file downloads normaly and some manual tests looked fine. I wanted to write unittests to test the filter. For this I read the returned file with openpyxl. There I get the…
-1
votes
1 answer

Django test uses wrong database in some cases

I try to setup my Django tests, and I noticed that when I run all tests TestRunner uses correct test database (for all aliases): docker-compose exec my_project python manage.py test --keepdb from django import db from django.test.runner import…
-1
votes
1 answer

django test client returns 404, but works in the shell

This code works fine in the shell, but if you run it through python manage.py test it throws a 404 error, what could be the problem? test_urls.py from django.test import Client, TestCase class StaticURLTests(TestCase): def setUp(self): …
finegorko
  • 57
  • 8
-1
votes
1 answer

Test password protected page django

I want to write test cases about password-protected pages. I have /management/edit page. it is loginrequired page. My test case currently likes below, but it is failed. I am expecting to get 200 but instead of I got redirection(302) Tests.py from…
Mamed
  • 95
  • 4
  • 16
-1
votes
3 answers

django: test case for @property function of a Model

I have a Django Library application which has the following BookInstance Model: class BookInstance(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4,help_text='Unique ID for this particular book across whole library') …
Simran
  • 593
  • 1
  • 14
  • 37
-1
votes
1 answer

Load Django Fixtures Once?

I know this question was asked before, but I was wanting to see if there is a more updated solution. Would there be a way to load all my fixtures in setUp and and flush them when all tests are finished? Right now, I'm loading in my fixtures like…
DForsyth
  • 498
  • 8
  • 19
-1
votes
1 answer

Django tests not validating null=False constraint

I have a model with various fields. One of them is a CharField field = models.CharField(max_length=100, blank=False, null=False) Now when I create an object without this field in django tests class function 'setUpTestData', it doesnt give any…
Arjunsingh
  • 703
  • 9
  • 22
-1
votes
1 answer

Fail in test of function, it doesn't update database

There is my function: views.py def save(request): data = {'mark':request.POST.get('mark'), 'task':request.POST.get('task')} Task.objects.filter(id=request.POST.get('s')).update(mark=data['mark'], task=data['task']) return…
JDxun
  • 1
  • 1
-1
votes
1 answer

differentiate between custom and 3rd party/inbred apps; django

I am writing tests for model_mommy, very useful fake objects for django. I want a fast way to make the script self-sustaining, and it needs to only write tests for your custom apps in your django project. Right now it may find and write tests for…
codyc4321
  • 9,014
  • 22
  • 92
  • 165
-1
votes
2 answers

How to initialize test database in django?

I am writing a test cases for my project written in django, it's giving an unexpected output that looks like {u'message': u'', u'result': {u'username': u'john', u'user_fname': u'', u'user_lname': u'', u'cur_time': 1442808291000.0, u'dofb': None,…
geeks
  • 2,025
  • 6
  • 31
  • 49
-2
votes
1 answer

Mocking time.sleep will cause the test to fail

I wrote this test, but in order not to delay the test, I mock the time.sleep and the test will encounter an fail. from unittest.mock import patch from django.core.management import call_command from django.db.utils import OperationalError from…
-2
votes
1 answer

Get to self.request.user in test python

I want to make tests for app, and I just can't make it right. I have such function: def get_queryset(self): return User.objects.filter(id=self.request.user.id) And I wrote such test: def test_Uzytkownik_get_query(self): self.c = Client() …
hohel
  • 121
  • 10
-2
votes
2 answers

Should Django models be tested?

Should I test Django Models? So far I've been writing tests for the views only. What else could and should be tested?
Ivo Valchev
  • 215
  • 3
  • 11
1 2 3
29
30