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 can I use django's default test framework to test a module included in sys.path that is not a subdirectory of the django project?

I have a django (1.8) site that is structured like this: .../django_project/ ./templates/ ./manage.py ./ .../django_app_project/ ./app_name/ ./ ./test_app.py To run the site, I…
lowtex
  • 707
  • 4
  • 22
0
votes
1 answer

Django unittest: TypeError: 'NoneType' object is not iterable

python3 manage.py test apps.favorites Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File…
DmitrySemenov
  • 9,204
  • 15
  • 76
  • 121
0
votes
1 answer

Calling super method in Django TestCase causes RecursionError

According to Django's document: Warning SimpleTestCase and its subclasses (e.g. TestCase, ...) rely on setUpClass() and tearDownClass() to perform some class-wide initialization (e.g. overriding settings). If you need to override those methods,…
nalzok
  • 14,965
  • 21
  • 72
  • 139
0
votes
1 answer

How can I bypass the Language request

On each of my view I have a function that return the request language code of the browser. But when I run my unittest my views I have an error: applications\emplois\views.py:74: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _…
Papouche Guinslyzinho
  • 5,277
  • 14
  • 58
  • 101
0
votes
1 answer

Django self.client.post does not send data to view with decorator

I have a simple test case which checks that POST request with valid data returns an HTML response with 200 status code: class PostRequestTestCase(TestCase): def test_valid_post_request(self): response = self.client.post('/foo/',…
Mikhail Geyer
  • 881
  • 2
  • 9
  • 27
0
votes
2 answers

How to handle view throwing manual exception in django in unit-testing?

I have made a django application and am writing tests for it. In one of my views I'm manually throwing an exception: raise Http404('Not authorised') While writing test for that using django's built-in test framework(based on unittest). TL;DR: Is…
T K Sourabh
  • 351
  • 2
  • 8
0
votes
1 answer

How to override Site.get_current()/request.get_host() in tests

In my app I have line if request.get_host() == Site.objects.get_current().domain. The problem is in my tests this condition is never True. request.get_host() returns testserver and Site.objects.get_current returns example.com. I know that I can add…
Iwko
  • 73
  • 1
  • 4
  • 10
0
votes
2 answers

Django unittest with legacy database connection

I have a Django project that pulls data from legacy database (read only connection) into its own database, and when I run integration tests, it tries to read from test_account on legacy connection. (1049, "Unknown database 'test_account'") Is…
James Lin
  • 25,028
  • 36
  • 133
  • 233
0
votes
2 answers

Django Unitest: Table doesn't exist

I created a simple test case like this: from unittest import TestCase import user_manager class UserTest(TestCase): def test_register(self): email = "dung7@gmail.com" password = "123456" result, user =…
Dũng Nguyễn
  • 485
  • 1
  • 4
  • 20
0
votes
1 answer

401 error for tastypie for api_client

Hi I am trying to write a test case for my app. URL = '/api/project/'. I have enabled get, post and put methods along with authentication. But still i get 401 error for post request class EntryResourceTest(ResourceTestCaseMixin, TestCase): class…
Naggappan Ramukannan
  • 2,564
  • 9
  • 36
  • 59
0
votes
1 answer

Django test can't find br tag

I use linebreaks in template. But the test can't find 'br' tag. {{ book.short_description | linebreaks }} This is the test self.assertContains(response, "New

Lines")
Masked Man
  • 522
  • 1
  • 6
  • 21
0
votes
1 answer

Django Integrated Test Passing When it Should Fail

I'm in the process of creating an assessment system using Django; however, I have an integrated test that passes and I'm not sure as to why (it should be failing). In the test, I set the grade field of the bobenrollment object to "Excellent". As…
jharrison12
  • 150
  • 8
0
votes
1 answer

Django AssertionError: 404 != 200 in simple unit test class

This is my Simple Test class,while running this test I am getting AssertionError: 404 != 200 class SimpleTest(unittest.TestCase): def setUp(self): # Every test needs a client. self.client = Client() def test_details(self): # Issue a…
Avinash KS
  • 1
  • 1
  • 5
0
votes
2 answers

call script from django unittest

I'm trying to run a script from a django unit test but failing to do so. The script I want to call can be run from the command line with python -m webapp.lib.cron.my_cron I've tried: from subprocess import call call("python -m…
user2954587
  • 4,661
  • 6
  • 43
  • 101
0
votes
1 answer
1 2 3
21
22