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
1
vote
0 answers

"PermissionError: [Errno 13] Permission denied" error when using Django override_settings

I am trying to find the cleanest way of testing ImageField in Django, without polluting or affecting in anyway the MEDIA_ROOT folder (even for local development purposes). Currently, my code is this: models.py: class Image: def __init__(self,…
Edgar Navasardyan
  • 4,261
  • 8
  • 58
  • 121
1
vote
2 answers

How to avoid an authentication error during testing drf?

During the development process, all classes were written with a variable permission_classes = [permissions.AllowAny, ]. In the file setting.py set 'DEFAULT_AUTHENTICATION_CLASSES': [ …
Jekson
  • 2,892
  • 8
  • 44
  • 79
1
vote
1 answer

How to check redirect in Django while testing in Django

I want to write a unit test than checks where I was redirected. There are 2 behaviours depending on number of players in a room. I want to check this function: @login_required def game_join(request, id): game = Game.objects.get(pk=id) if…
DevVile
  • 59
  • 8
1
vote
0 answers

Secret Key not found when Django Unit Tests are executed

Whenever I'm running my Django-Tests via the unittests.py file in the main folder the SECRET KEY in .env is not found. What is the correct way to set up the regular Unittests-File for a series of Django-Tests? I wrote my settings.py in a way it's…
Qohelet
  • 1,459
  • 4
  • 24
  • 41
1
vote
1 answer

How can I test overriden function in Django admin?

I have overriden function in admin module @admin.register(Donation) class DonationAdmin(admin.ModelAdmin): def log_change(self, request, object, message): log_obj = super().log_change(request, object, message) name_map = {name:…
unknown
  • 252
  • 3
  • 12
  • 37
1
vote
0 answers

Can I configure Django for Unit tests with restricted view on unmanaged databases?

We are a small team, trying to work with Django with a restricted access to a futurely unmanaged PostgreSQL database (i.e: only views and stored procedures ; no access to any tables) for security reasons. We tried to give (within Postgre) the user…
Gmoaltos
  • 25
  • 5
1
vote
1 answer

Why does django Unittest throw an assertion error when comparing two instances of numpy.float64?

I'm writing some unit tests, one of which checks that the data provided in a dataframe is of the correct type (float). When I run the test assertIsInstance(type(foo), np.float64) the test fails with the following error message: AssertionError
741852963
  • 479
  • 1
  • 3
  • 18
1
vote
0 answers

django unitest multiple class instance

How can I create django unitest from multiple instances? I want to fetch all objects that was created in another unitest class. I doing this because class TestClassA and TestClassB also instanced from BaseTestAuth. class BaseTestAuth(TestCase): …
binpy
  • 3,994
  • 3
  • 17
  • 54
1
vote
4 answers

Django: how to mock a class inside the API view

Title might be a little confusing. Say I have an APIView with a post method. Inside the post method, I introduced a class that has its own method. In this case, it's a class that deals with uploading to S3, which is something I want to skip when…
JChao
  • 2,178
  • 5
  • 35
  • 65
1
vote
2 answers

Django - how to write test for DRF ImageField

I have the following serializer: from rest_framework.serializers import Serializer, ImageField class MySerializer(Serializer): avatar = ImageField() how can I write a unit test for it? I used the Django TestCase, but it raises an error. from…
msln
  • 1,318
  • 2
  • 19
  • 38
1
vote
0 answers

Running Django test tries to import module that was deleted

I have a Django project that I am trying to test. It had an app named 'people' that I have replaced with another app 'participant'. I have changed all of the settings needed, but why I runpython manage.py test, it won't run the tests because it…
Carl Brubaker
  • 1,602
  • 11
  • 26
1
vote
1 answer

Django Unittest that form field is required

I'm am trying to test the form fields have or don't have the required attribute, but I don't know where to find it. This is what I have tried: form.fields[field].widget.attrs['required'] But I get this…
Carl Brubaker
  • 1,602
  • 11
  • 26
1
vote
1 answer

Django assertTemplateUsed fails after redirect

I am working on a Django 2.1 practice project. Last line of my test keeps failing. Is it true that assertTemplateUsed check won't work if redirection happens? Traceback (most recent call last): File "test_views.py", line 24, in…
jiyi
  • 101
  • 9
1
vote
1 answer

"StopIteration" exception while using factory_boy in django setUp() unittest

I have the following factory: class ContactFactory(DjangoModelFactory): name = Faker('company') industry = Iterator(Industry.objects.all()) class Meta: model = 'sales.contact' @post_generation def…
1
vote
0 answers

How to ignore second DB in Django unit test?

I am trying to run a simple unit test in Django where I verify the template used. It is very similar to the test in TDD with Django: from django.test import TestCase class HomePageTest(TestCase): def test_uses_home_template(self): …
Scott Skiles
  • 3,647
  • 6
  • 40
  • 64