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

Many Testcase classes inside a test.py in django don't run correctly

I want to have different Testcase classes inside my test.py in my django project. One for Model testing (crud) one for view testing etc. I have the following classes class EntryModelTest(TestCase): LOG = logging.getLogger(__name__) …
Apostolos
  • 7,763
  • 17
  • 80
  • 150
0
votes
0 answers

django.db.utils.DatabaseError: (1146, "Table 'test_xxx.django_content_type' doesn't exist")

I get the following error when I run the django unittest. python manage.py test ... ... django.db.utils.DatabaseError: (1146, "Table 'test_xxx.django_content_type' doesn't exist") Please guide me on what I might be doing wrong. Is this has to do…
attaboyabhipro
  • 1,450
  • 1
  • 17
  • 33
0
votes
0 answers

Is it possible for python mock to make django unittest client.session to shadow request.session?

I have a unittest which access an internal api and which sets value in session. eg. def api_work(request): request.session['stuff'] = True Now for me to test it: def test_api(self): self.client.get(/api_work/) # self.client.session is…
James Lin
  • 25,028
  • 36
  • 133
  • 233
0
votes
1 answer

Django 1.6.1 Fixtures not getting loaded for Unittest

Django is not loading fixtures for the following test. from django.test import TestCase class DevViewsTests(TestCase): fixtures = ['device/fixtures/test_device.json'] def setUp(self): self.client = Client() self.username =…
Pawan
  • 4,249
  • 6
  • 27
  • 32
0
votes
1 answer

Django Test: Test view without creating client

I would like to write a test case like: # Create fake request with missing header that we are testing for request = HttpRequest() request.META = {} response = MyApp.views.start(request) self.assertEqual(400,…
Raj
  • 2,852
  • 4
  • 29
  • 48
0
votes
1 answer

Why is my POST request not redirecting as expected in my unit test even though there are no form errors?

I've got a Django view with a form, which I'm POSTing to in a unit test. Here's the general structure of the test: class ViewTests(TestCase): form_url = reverse_lazy('myapp:form') success_url = reverse_lazy('myapp:success') def…
3cheesewheel
  • 9,133
  • 9
  • 39
  • 59
0
votes
1 answer

Django Testing MySQLdb in UnitTest / WebTest

I have a WebTest that I'm running using django-webtest against a database in memory. # settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', } } There's a piece of code that I just cannot run through the…
scoopseven
  • 1,767
  • 3
  • 18
  • 27
0
votes
1 answer

Django - Unit Testing an AdminForm

I am very new to unit testing and am probably doing something wrong, but when I simulate a post to update a model via the admin backend it seems like my save_model method in my AdminForm isn't being called. I am trying to test this method - what am…
Kvass
  • 8,294
  • 12
  • 65
  • 108
0
votes
1 answer

How to test methods that compute relative time in python using unitttest?

I have a method in a django model that does a computation relative to the current time. Here is a snippet: def next_date(): now = datetime.now() trial_expires = max(self.date_status_changed + timedelta(self.trial_days), now) return…
Tony Abou-Assaleh
  • 3,000
  • 2
  • 25
  • 37
-1
votes
1 answer

Python (django) call two management commands at the same time

I'm writing unit tests for my management commands. I would like to run my two management commands meanwhile by using call_command() function. How can I do that? I need to run them at the same time because they do work together, one creates data and…
-1
votes
1 answer

How can I run Django unit test in Microsoft TFS automatically?

How can I run django unit test in Microsoft TFS automatically?
majidmc2
  • 1
  • 2
-1
votes
1 answer

Django Unit test

i have two servers,one working as api and another used to retrieve the data from api(webui).If i perform any unit tests for views in webui,it is creating objects in api.How to delete the objects in api after the testing is complete?Can you suggest…
Debajyoti
  • 1
  • 2
-2
votes
1 answer

My Django test is failing due to csrf_token value?

I Think the two csrf value is not same that is why my test case is failing. How do i test the template is working good? FAIL: test_home_page_can_save_a_POST_request (lists.tests.HomePageTest) Traceback (most recent call last): File…
-3
votes
1 answer

@unittest.skip doesn't print anything in Python <= 3.7

We are using Django with unittest. Some tests are skipped with the @unittest.skip decorator. But if I run the tests with Python 3.6 or 3.7, I get a number of tests passed (Ran 993 tests / OK), and if I run the same tests with Python 3.8, I get the…
Uri
  • 2,992
  • 8
  • 43
  • 86
1 2 3
21
22