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

How to disable a decorator on a method, if that method is called in django tests?

I have a function that is like: @dec_func def a(): do_something; In my django tests this function is ran in execution. Now i want that whenever the tests run my function a should not get decorated dec_func but if the function runs in…
coderelliot
  • 421
  • 5
  • 15
0
votes
0 answers

Do not wait for spawned threads in testing functions

I have a function, which I want to test, but spawns a thread, which can live long enough to wait its end. How to not wait the thread's end in this situation? I use django's unittests, but it is not the point, I guess. Example below: import…
0
votes
1 answer

Operational Error while running unit tests Django

I have dockerized my Django app together with my postgres Database. However after the dockerization, the unit tests that i have written (not the SimpleTestCase but the TestCase ones) stopped running. I thought it could be because of the new db so I…
0
votes
0 answers

Unit Testing in Python Djnago

I am using Django==3.0.3 djangorestframework==3.11.0 python ==3.6.8 I want to write unit testing for API and no need to use any database(no need of mock database) that mean I want to mock the database call and write unit test cases how can i write…
0
votes
1 answer

I can't figure out how to test these views using unittests

I need to test this code using unittest help me figure it out show how they are tested def post(self, request, pk): form = ReviewForm(request.POST) movie = Movie.objects.get(id=pk) if form.is_valid(): form =…
0
votes
0 answers

Unit tests for OrderingFilter DRF

I have a model: class Trade(models.Model): name = models.CharField(max_length=255, unique=True) is_active = models.BooleanField('Active', default=True) is_deleted = models.BooleanField('Deleted', default=False) and views.py class…
0
votes
1 answer

Django-channels, how to use mocks

I build this chat website, and I'd like to test this functionnality: if you send a message and the user is online, send message via websocket: Tested if you send a message and the user is offline, send a push notification (it's a REST…
Arnaud Fouchet
  • 933
  • 1
  • 7
  • 14
0
votes
1 answer

Feature-testing a REST API with unittest in Django

In our Django project, we have some API views that are defined in urls.py like this: path('api/calendar/calendar_data', calendar_api.serve_data), and our calendar_api is an instance of CalendarAPI, which is instantiated above: from…
Tobias Sytsma
  • 41
  • 1
  • 5
0
votes
1 answer

django unittest to use "real" database

I am currently writing test cases for views, Which eventually uses database also. By default a test database is being created and removed after test are run. As the database itself is development database, I don't want my test to create a separate…
user
  • 2,694
  • 6
  • 24
  • 25
0
votes
0 answers

Django testing Http404 exception causes further NoReverseMatch

I have the following block in my DetailView def get_object(self): post = get_object_or_404( Post.objects \ .select_related('author') \ .prefetch_related('comments'), \ slug=self.kwargs['post_slug']) if…
Ken
  • 859
  • 2
  • 14
  • 33
0
votes
1 answer

Execute Unittest in Django

I have written a small unit test for my django view .My project structure is like Project_name/ apps/ module1/ tests.py module2/ tests.py this is my dir structure i…
Shashi
  • 2,137
  • 3
  • 22
  • 37
0
votes
1 answer

How do I Mock a method that makes multiple POST and GET request all requiring different response data?

I have looked at How to mock REST API and I have read the answers but I still can't seem to get my head around how I would go about dealing with a method that executes multiple GET and POST requests. Here is some of my code below. I have a class,…
Red Cricket
  • 9,762
  • 21
  • 81
  • 166
0
votes
1 answer

How to make a request to local URL as part of automated tests?

I'm writing an automated test in Django to check that a webhook is working on the application. The test sends a bunch of JSON to the webhook and will check that the call has been logged in the database. The problem I'm hitting however is that the…
rcx935
  • 217
  • 5
  • 15
0
votes
1 answer

How to get a value from SubFactory Django Unit Test

I have three classes.In OrdFactory i wana pass only id to "sku" field and sku is integer field. class CoFactory(factory.django.DjangoModelFactory): class Meta: model = models.Co name = factory.Sequence(lambda n: 'Co…
0
votes
1 answer

Mocking django tests - why is this patched function still being called?

I'm trying to test a function in one of my models, and am trying to to mock out the filesytem using mock.patch. No matter what I try, it doesn't seem to intercept the method. Model to test: app/models.py from django.db import models from…
741852963
  • 479
  • 1
  • 3
  • 18