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

Sonarqube displaying 0% of coverage and no unittest in django project using coverage.py

I'm working on creating unitest for a django project I installed sonarqube: docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest through docker image and sonar-scanner using this command: docker run…
0
votes
0 answers

Procedure for setting up mysql/mariaadb triggers, stored procedures & views (only once) for all django TestCase unittests

A procedure for setting up mysql/mariaadb triggers, stored procedures & views for all (prior to running) unittests (see refs below). I've searched the django docs and other resource but can not find a solution. The 'python manage.py test' execution…
0
votes
1 answer

How to unit test for natural key in models.py in django

I want to unit test for the models.py in django. I do not know how to unit test for the function natural_key() class User(AbstractBaseUser, PermissionsMixin): email = models.EmailField(_('email address'), unique=True) username =…
0
votes
0 answers

Unit testing a unittest custom test runner in Django

I am trying to unit test a custom test runner using unittest framework but I get this error. File "/usr/local/lib/python3.7/dist-packages/django/test/runner.py", line 466, in setup_test_environment …
0
votes
1 answer

Test validate_unique raises ValidationError Django forms

I have a ModelForm called SignUpForm located in myproj.accounts.forms SignUpForm overrides Django's validate_unique so that the 'email' field is excluded from 'unique' validation as required by the model's unique=True (this is dealt with later in…
Radial
  • 342
  • 1
  • 4
  • 14
0
votes
0 answers

Is there a chance that emails are sent in parallel and thus `mail.outbox.clear()` doesn't really clear outbox in my django tests?

I have written django tests to check my outbox emails as shown below class TestX(TestCase): def setUp(self): # Clear outbox. mail.outbox.clear() super().setUp() def tearDown(self): # Clear outbox. …
E_K
  • 2,159
  • 23
  • 39
0
votes
1 answer

Is it possible to create an artificial model in FactoryBoy?

I wanted to know if in the tests it is possible to somehow create an "artificial" model using FactoryBoy without touching models.py I mean a simple model such as: class SomeMod(models.Model): title = models.CharField(max_length=255, blank=True,…
0
votes
0 answers

How to mock settings in Django Unit testing

I am new to Django Unit testing and am trying to write unit test for a simple function which is like below: utils.py #some import statements from django.conf import settings if platform.system() == 'Linux': …
0
votes
1 answer

VS Code Pytest/Unittest debugger doesn't stop on breakpoints

I wrote unittest-based tests with pytest. according to this document: https://docs.pytest.org/en/7.1.x/how-to/unittest.html then I tried to run the tests by Python testing in Visual Studio Code according to this…
0
votes
1 answer

How to test Django reusable templates?

In one of my templates for detailed view of a device assignment I had logic pertaining to if buttons should appear depending on the user's permission. I wrote tests for these buttons and they work as expected. Today I wanted to reuse these buttons…
Bil1
  • 440
  • 2
  • 18
0
votes
1 answer

Django unit tests - django.db.utils.IntegrityError: duplicate key value violates

What's the best way class BankLoanApplicationFile(TestCase): """Test cases for loan_application.py file.""" def setUp(self) -> None: """Set up configuration.""" self.loan_product = mock.Mock(spec=LoanProduct) …
Lutaaya Huzaifah Idris
  • 3,596
  • 8
  • 38
  • 77
0
votes
2 answers

Django unittest: required mock patch dotted path varies depending on how one calls/runs the tests

It took me hours to figure out how to patch the below code. The path to it was very much unexpected. Depending on how I run the tests, and which dir I am in, I find the dotted path to the module to patch changes. This is really bad for unittesting.…
run_the_race
  • 1,344
  • 2
  • 36
  • 62
0
votes
2 answers

How to test query_params?

How can I test query_params? I have provided a response and a request, but it still doesn't work. Initially, the error was like this: price = int(self.context.get('request').query_params.get('price', None)) AttributeError: 'NoneType' object has no…
0
votes
0 answers

How to use django unit tests with elasticsearch?

I use django unit tests to test my application. It worked very well until today. I integrated elasticsearch to the project with the 2 modules django_elasticsearch_dsl and django_elasticsearch_dsl_drf. Since then, almost none of my unit tests are…
darkvodka
  • 303
  • 1
  • 3
  • 11
0
votes
0 answers

Django Operational Error : No Such Column

I have a test case using Django MigratorTestCase. Previously the test case was working fine but then I had to add a column called updated and I made migrations to the project but ever since then the unit test case has been failing and I am not sure…