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

Specify two arguments in URL parameters for path Django

I've currently got an endpoint that accepts GET requests, to retrieve users within a date range (there's no real need to explain the 'why'). The specific endpoint looks like this: GET /users/?fromdate={yyyy-mm-dd}&todate={yyyy-mm-dd} For example, I…
Adam
  • 2,384
  • 7
  • 29
  • 66
1
vote
0 answers

django test method mock persists with call_command

SSCCE example here: first_app/tests/test_file.py from unittest.mock import patch from django.core.management import call_command from django.test import TestCase class TestWierdo(TestCase): @patch('first_app.class_a.method_to_import') …
zcahfg2
  • 861
  • 1
  • 12
  • 27
1
vote
0 answers

Endpoint working in postman but failing test

I'm trying to test a delete endpoint, which is working when testing manually in Postman but it's failing my test with 500 error. def test_delete_notification(self): deleted_notification = URL + 'delete/' + str(self.notification.id) …
1
vote
1 answer

Django unit test constraints

So I have a problem in writing my unit tests for a Check and Unique constraint. Here are the their definition: # assert that a partner can have only one headquarter constraints = [ models.UniqueConstraint( fields=['partner', 'active'], …
davidm
  • 1,570
  • 11
  • 24
1
vote
1 answer

How to check and see if an output contains the desired elements from any list or not?

I am trying to write tests for a particular app in django using the python's unittest library. def test_permissions_for_admin(self): admin = Group.objects.get(name='Administrator') permisisons = admin.permissions.all() admin_permissions…
1
vote
2 answers

Django Models Unit Tests: Help for a newbie

Right, this is kind of the last place i would like to have asked due to the question being very vague, but I'm at a loss. Basically, I'm trying to learn how to code and I'm currently working with Django to help me get to grips with the back end of…
DrGoob
  • 37
  • 9
1
vote
0 answers

Unused import gives me access to the stdout of a signal

I just ran into a strange interaction and I'm curious if one of you could explain what's happening: I'm writing a test, and to start I just created a simple print statement to check if the signal was going off. Here's the test located in…
1
vote
0 answers

Permission.objects.get() method is not working while creating the test database for Unit tests in Django

I Written the Django signals for creating the groups and assign permissions to theses groups for the different user roles but when I am running my test cases then I am getting permission error for creating test database. signal.py from…
1
vote
2 answers

Waiting function that waits for a loading circle to disappear selenium, unittest, python takes 12+ seconds even if the circle has done loading

Given this code that waits until a loading circle disappears from a webpage : def wait_loadingCircle(self): try: while self.browser.find_element_by_xpath('//div[@class="sk-circle-container"]').is_displayed() is True: …
Henry-G
  • 131
  • 1
  • 8
1
vote
2 answers

Test Image Upload Always Fails

I cannot get any of my image upload unit tests to work. The following test fails with AssertionError: != 'test_image.jpg' (Ignoring the fact that my test would fail regardless because it's comparing an…
horse
  • 479
  • 7
  • 25
1
vote
0 answers

Why does a ManyToMany relationship created in setUpTestData cause a duplicate key error?

I am using postgreSQL 12. I have the following models: class Publication(models.Model): title = models.CharField(max_length=30) class Article(models.Model): headline = models.CharField(max_length=100) publications =…
alias51
  • 8,178
  • 22
  • 94
  • 166
1
vote
1 answer

How can I get setUpTestData to tear down / rollback primary keys (postgreSQL)?

I am using postgreSQL 12. I have two TestCase classes: class TestA(TestCase): @classmethod def setUpTestData(cls): for _ in range(5): MyModel.objects.create() def test_1(self): print('Start test 1') …
alias51
  • 8,178
  • 22
  • 94
  • 166
1
vote
1 answer

Writing Unit Test for my Class based views which also require LoginRequiredMixin

I have one ListView and one DetailView and both requires LoginRequiredMixin. Now i want to write unit test for these class based views. Can somebody help me with this. I want to test the template, context as well as right view is called. My Tests.py…
1
vote
1 answer

Unit Test Case of redirection after successful Login of auth login view in Django

I have used Django auth login view and mentioned LOGIN_REDIRECT_URL = '/team/' in my settings.py. Now i want to write the unit test case if user successfully login then it should redirect to /team/. My Login Url is: path('login/',…
1
vote
0 answers

Why are integration tests failing on updates to model objects when the function is run on Django q-cluster?

I am running some django integration tests of code that passes some functions to Django-Q for processing. This code essentially updates some fields on a model object. The app uses signals.py to listen for a post_save change of the status field of…
741852963
  • 479
  • 1
  • 3
  • 18