Questions tagged [django-unittest]

django-unittest tag refers to writing unit tests in Django, tests that are expressed as methods on a Python class that subclasses unittest.TestCase or Django's customized TestCase.

django-unittest tag refers to writing unit tests in Django, tests that are expressed as methods on a Python class that subclasses unittest.TestCase or Django’s customized TestCase.

329 questions
3
votes
0 answers

Capture IntegrityError in Django Dynamic Fixture

I'm trying out Django Dynamic Fixture (DDF). It has a few of its own Exceptions, one being BadDataError, generated when "the data passed to a field has some problem (not unique or invalid) or a required attribute is in ignore list". For example,…
Mathieu Dhondt
  • 8,405
  • 5
  • 37
  • 58
3
votes
2 answers

Django can't destroy and create test databases properly

When I try to run my unittest, this is what I get: python manage.py test dbank --settings=databank_web.settings.dqs.dev_hooman Creating test database for alias 'default'... Creating test database for alias 'global'... Creating test database for…
Houman
  • 64,245
  • 87
  • 278
  • 460
3
votes
1 answer

django-crispy-form: Unit test fails because of TypeError of helper object

Somewhat based on a chapter of this book, I'd like to unit test a form created with django-crispy-form but I get the following error: TypeError: helper object provided to {% crispy %} tag must be a crispy.helper.FormHelper object. The form…
lukas
  • 183
  • 1
  • 1
  • 10
3
votes
0 answers

How to write tests that account for custom User model in Django?

TL;DR: I don't wanna use @skipIfCustomUser What can I do? Django allows a custom user model to be defined in settings.py, and says we should use get_user_model() to reference the current (swapped) User model, in the docs. Forthermore, the docs…
frnhr
  • 12,354
  • 9
  • 63
  • 90
3
votes
2 answers

Django: issue with unit-test ListView and assertContains

I am adapting the unit tests from the official Django 1.5 tutorial. I am trying to test an empty context on a ListView. I get the following error: AssertionError: Couldn't find 'No persons are available' in response. And this is my ListView…
Paul
  • 2,409
  • 2
  • 26
  • 29
3
votes
1 answer

Using unit tests to measure Django performance

Unit tests are a great way to measure application functionality, but I'm wondering has anyone used them for some preliminary performance profiling? What I'm talking about is running some profiling tool as part of an automated test run, saving…
Berislav Lopac
  • 16,656
  • 6
  • 71
  • 80
3
votes
4 answers

django unittest output

I would like to run django unittest via python subprocess and I would like to store all the data (especially the words Failure or OK) in a variable. However when I use subprocess to run this the output only contains the parts: "Creating test…
Christopher H
  • 2,044
  • 6
  • 24
  • 30
3
votes
1 answer

Mocking django's database save

I'm trying mock out a save method call on a django models.Model. I'm using Mock as my mocking library. I'm testing a function in the file house_factory.py , which is located at apps.deps.house_factory. house_factory.py: from apps.market.models…
Jonas Geiregat
  • 5,214
  • 4
  • 41
  • 60
2
votes
1 answer

How do I run my Django testcase multiple times?

I want to perform some exhaustive testing against one of my test-cases (say, create a document, to debug some weird things I am encountering..) My brutal force was to fire python manage.py test myapp in a loop either using Popen or os.system, but…
User007
  • 1,519
  • 6
  • 22
  • 35
2
votes
1 answer

Django TestCase DB missing columns that are in the DB when I runserver

When I start my app it works perfectly, but when I try to run a testcase it creates the test DB from my local copy and errors for a missing column that I can see in my local DB and was part of an older migrations. Any suggestions (venv) PS…
Michael McDermott
  • 344
  • 3
  • 6
  • 14
2
votes
1 answer

How to read env vars from settings in django unittest?

I am new to unittesting. I want to read some env vars in django unittests, but I am having some troubles when trying to read the env var from django.conf.settings, but I can read the env var using os.environ.get(). How can I access the current env…
2
votes
1 answer

Django unittest run specific test syntax

I want to run one specific unit test from my app bank/tests.py in the pipeline but I keep getting errors, I believe I am missing something on the syntax here This is my test: class SettingsTestCase(TestCase):     def test_timezone_default(self):    …
patbet
  • 93
  • 1
  • 9
2
votes
1 answer

Importing the django.test does not work

As it is failing to import django.test module, unit test does not work. >>> import django.test Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\django\test\__init__.py", line 5, in…
2
votes
1 answer

How to write unittest for function in Django admin?

class SystemUserAdmin(UserAdmin): list_display = ('get_phone',) ​ def get_phone(self, obj): address = obj.cause.address return address.phone if address else '-' get_phone.short_description =…
user10898133
2
votes
1 answer

In Python, is it possible to mock requests inside another request?

In Django, I have a view which makes a request to an external API. The view is in my_app. class ExternalAPIView(View): def get(self, request, *args, **kwargs): ... external_api_response = requests.get(settings.EXTERNAL_API_URL) …
iuysal
  • 655
  • 1
  • 5
  • 15