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

Django Unit Testing stucks with an E

I'm experiencing a strange error in Djangos Unit Testing Framework. It worked before, but out of the blue, the tests do not work any longer. The framework puts out: python manage.py test Creating test database for alias…
shredding
  • 5,374
  • 3
  • 46
  • 77
1
vote
0 answers

I want test the post method by django

I created a "Like" function that works properly. good. good. good. # a test file from django.test import TestCase from django.urls import reverse from register.models import User from vietnam_research.models import Articles, Likes class…
yoshitaka okada
  • 113
  • 1
  • 12
1
vote
0 answers

Django 4 - TransactionTestCase - Postgresql sqlflush error

My code: Django 4.1 I am using multiple postgresql schemas for my models, postgresql12 with out-of-box ubuntu 20.04 setup. I am performing unit tests of some code which uses transactions. migrations are created When running other non-transaction…
wtdmn
  • 73
  • 1
  • 7
1
vote
0 answers

do some things same time in the Django unit test

How can I test if two users can reserve the same car simultaneously? def test_if_two_users_can_reserve_the_same_car_simultaneously(self): with patch.object( timezone, "now", return_value=make_aware( …
sahaaari
  • 11
  • 3
1
vote
0 answers

Django - How to copy schema of existing database into test database?

In my django project, I am using an existing database (Postgres) and with python manage.py inspectdb I created models. now I want to write unit tests and my problem is django just creates an empty test database for it, but it doesn't create schemas.…
1
vote
1 answer

Add additional field to response in pytest-django

I'm new to testing and I spent a day finding a solution for my problem but I couldn't find any. this is my serializer serilaizer.py class LeadSerializer(serializers.ModelSerializer): def create(self, validated_data): user =…
1
vote
0 answers

Writting Unnittest Test for Django Model

I've written a test for the get_rendered_text() method in my django app as seen in the Model below. But when i run a coverage report, it still says i haven't tested this particular method meanwhile to the best of my understanding,the test i've…
Cthegod
  • 19
  • 2
1
vote
1 answer

How to mock instance attribute of django form

I'm doing a unit test where I'm mocking a Django form, but I'm having some trouble because I need to mock two things from the form: An instance attribute (token) A method (is_valid) I'm using the form in a view, importing it like this: from…
1
vote
0 answers

Is there a way to mock the firebase_admin credentials.Certificate class in Django?

In my project, FirebaseAuthentication is used and while running the test cases(pipenv run python manage.py test) I am getting the following error - ValueError: Invalid certificate argument: "None". Certificate argument must be a file path, or a dict…
1
vote
1 answer

Django Unit Test Case

Hello I'm a newbie to Django Unit test as I'm working on Django Rest Framework using modelviewset. I need to test few models, serializers, views & urls. I'm not sure how to perform it. As I have followed few documentations. But still not clear.…
1
vote
1 answer

Testing a custom auth backend with Django RestFramework

I created a custom authentication backend for my DRF application. I can't figure out how to test it. Calling the client.post calls my authenticate function (cause that's in my view) But I need to mock an internal method in my ModelBackend. Kinda…
1
vote
1 answer

Django unittest self.assertTemplateUsed, how to check the occurrence of multiple templates

self.assertTemplateUsed(response,('goods/item_list.html', 'base.html', 'inc/_nav.html') ,) error AssertionError: False is not true : Template '('goods/item_list.html', 'base.html', 'inc/_nav.html')' was not a template used to render the response.…
Charls Ken
  • 101
  • 2
  • 7
1
vote
1 answer

DRF: Set language while testing

I have a serializer with a DateField that is localized according to the user's language settings. I would like to write a test and verify that the formatting is working correctly but I couldn't figure out how to set the reuqest language when using…
hendrikschneider
  • 1,696
  • 1
  • 14
  • 26
1
vote
0 answers

Authenticating with DRF API key in unit tests return error: "Authentication credentials were not provided"

After recently discovering (and loving!) test driven development, I've started working on an API for a project of mine using Django with Django REST Framework and Django REST Framework API Key. However, I'm getting stuck trying to unit test some…
1
vote
2 answers

Unable to authenticate using factory-boy Django

I'm quite new to factory-boy and I'm trying to send a request to an API endpoint in my unit test, which requires a user to be authenticated. The endpoint expects a token in the header in the form of 'Bearer ' + token. I've looked at a few examples…