Running django tests with sqlite

Append the following lines in your settings: import sys if ‘test’ in sys.argv or ‘test_coverage’ in sys.argv: #Covers regular testing and django-coverage DATABASES[‘default’][‘ENGINE’] = ‘django.db.backends.sqlite3’ Make sure your actual database setting comes before them.

Django’s self.client.login(…) does not work in unit tests

The code that doesn’t work: from django.contrib.auth.models import User from django.test import Client user = User.objects.create(username=”testuser”, password=’12345′) c = Client() logged_in = c.login(username=”testuser”, password=’12345′) Why doesn’t it work? In the snippet above, when the `User` is created the actual password hash is set to be `12345`. When the client calls the `login` method, the value … Read more

How to launch tests for django reusable app?

The correct usage of Django (>= 1.4) test runner is as follows: import django, sys from django.conf import settings settings.configure(DEBUG=True, DATABASES={ ‘default’: { ‘ENGINE’: ‘django.db.backends.sqlite3′, } }, ROOT_URLCONF=’myapp.urls’, INSTALLED_APPS=(‘django.contrib.auth’, ‘django.contrib.contenttypes’, ‘django.contrib.sessions’, ‘django.contrib.admin’, ‘myapp’,)) try: # Django < 1.8 from django.test.simple import DjangoTestSuiteRunner test_runner = DjangoTestSuiteRunner(verbosity=1) except ImportError: # Django >= 1.8 django.setup() from django.test.runner import … Read more

Is APITest with Query params different then just normal url?

Try passing the query parameter as a data payload instead. Change the line in your test to: response = self.client.get(‘/api/titles-and-blurbs/’, {‘genre’: ‘horror’}) Django docs here on the different ways to pass query parameters in urls. Another person reported a similar issue with an empty QUERY_PARAMS while testing DRF (see here). It looks like they fixed … Read more

how to get request object in django unit testing?

See this solution: from django.utils import unittest from django.test.client import RequestFactory class SimpleTest(unittest.TestCase): def setUp(self): # Every test needs access to the request factory. self.factory = RequestFactory() def test_details(self): # Create an instance of a GET request. request = self.factory.get(‘/customer/details’) # Test my_view() as if it were deployed at /customer/details response = my_view(request) self.assertEqual(response.status_code, 200)

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)