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

Passing extra argument to TestCase Setup

I am writing tests for my django app using TestCase, and would like to be able to pass arguments to a parent class's setUp method like so: from django.test import TestCase class ParentTestCase(TestCase): def setUp(self, my_param): …
i_trope
  • 1,554
  • 2
  • 22
  • 42
1
vote
1 answer

Django 1.6.1 : Transaction error. You can't execute queries until the end of the atomic block in unitest

Django 1.6.1 on Windows with Postgres I m using unittest to test a view that upload a .cfg file to server. I am facing 2 error called (1) TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the…
Pawan
  • 4,249
  • 6
  • 27
  • 32
1
vote
1 answer

Speeding up Django unittests with a template Sqlite database

How do you make Django load a sqlite3 db file into memory when running unittests, instead of generating a new database and initializing schema from scratch? I have some large JSON fixtures that take a while for Django to load for each test. A…
Cerin
  • 60,957
  • 96
  • 316
  • 522
1
vote
1 answer

Unable to login inside a Django unittest

How do you simulate logging in to admin inside a Django unittest? The docs make it seems simple, but when I do that, I get 200 response and a page saying "Please log in again, because your session has expired." My unittest looks like: def…
Cerin
  • 60,957
  • 96
  • 316
  • 522
1
vote
2 answers

In Django REST API unittest, how do I send JSON parameters as body in client.get() function?

I'm building a REST API with Django and in some places I need to send HTTP GET with many parameters. Because of that I've decided to send them as JSON in the request.body. Now, the app works fine but not the unit testing. I cannot seem to find a way…
1
vote
0 answers

Django 1.6, Transaction.commit_on_success with Multiprocessing is not working

I am new in Django and trying to write some test cases. In my code I am doing some transaction. For that purpose I locked my that code using select_for_update in django. Now I want to test it whether lock is working correctly or not. I am running 2…
1
vote
2 answers

Getting extended information on Django unittest framework

I am using Django unit test framework for testing my application. When ever I am executing all the test cases I am getting very brief information about the test cases that ran…
Bhupesh Pant
  • 4,053
  • 5
  • 45
  • 70
1
vote
1 answer

How to test commit_manually inside Django unittests

How do you test Django code that uses commit_manually() from a unittest? I have a long-running method that deletes large numbers of records, enough so that it can't keep all those changes in a single transaction without consuming all system memory.…
Cerin
  • 60,957
  • 96
  • 316
  • 522
1
vote
3 answers

Django Test - I can't save my object when I use queryset to get it

I have an model, let's say something like: class Invoice(models.Model): client_name = models.CharField(max_length=100) And I have a file that looks like: def foo_1(): for inv in Invoice.objects.all(): inv.client_name = "Joe" …
Thom
  • 1,473
  • 2
  • 20
  • 30
1
vote
1 answer

Retrieving Django Unittest result in view

I can't find this anywhere, but is it possible to run a unittest from within a django view, to be output to a template? Currently if I run python manage.py test, I get a message like "Ran 10 tests in 0.401s OK". I would like to access this…
TheoretiCAL
  • 19,461
  • 8
  • 43
  • 65
1
vote
1 answer

Django: relation "auth_user" already exists when executing manage.py test myApp

The stack trace: Creating test database for alias 'default'... Destroying old test database 'default'... Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File…
1
vote
0 answers

Unittesting Django on Google App Engine

I have difficulty running django unit tests on GAE. I might be setting it up wrongly. from django.test import TestCase from django.test.utils import setup_test_environment from django.test.client import Client class Test_base(TestCase): def…
Houman
  • 64,245
  • 87
  • 278
  • 460
1
vote
0 answers

LiveServerTestCase does not map Django Application to url

Background: I am trying to setup my first Selenium driven integration test for a Django app. I have developed the following simple code: from django.test import LiveServerTestCase from selenium.webdriver.firefox.webdriver import WebDriver from…
Buck
  • 731
  • 1
  • 11
  • 23
1
vote
1 answer

Django Unittest for form with password

I want to create a unit test in django testing a form while passing some initial data to it and see if it's valid or invalid. The problem is the framework doesn't allow you to set initial value to a password field, is there any other way around this…
KVISH
  • 12,923
  • 17
  • 86
  • 162
1
vote
1 answer

Django Unit testing, unknown column error

I'm a Django beginner and am getting acquainted to using it, and I'm also a big believer in unit testing. Given a sample database table contracts with the fields parent_id int contract_num varchar start_date date end_date date org_name…
Jason
  • 11,263
  • 21
  • 87
  • 181