0

I have the below test case

from rest_framework.test import APIClient
from django.test import TestCase
from factories import UserFactory

class TestUserApi(TestCase):
    def setUp(self):
        # Create or get model factory objects
        self.users = UserFactory()
        self.client = APIClient()

    def test_user_list(self):
        response = self.client.get('/api/1/users/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def tearDown(self):
        pass

When I run the above test case I am getting the below error which I don't understand why?

ERROR: test_user_list (test_cases.TestUserApi)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/test/testcases.py", line 178, in __call__
    self._pre_setup()
  File "/usr/local/lib/python2.7/dist-packages/django/test/testcases.py", line 749, in _pre_setup
    self._fixture_setup()
  File "/usr/local/lib/python2.7/dist-packages/django/test/testcases.py", line 861, in _fixture_setup
    if not connections_support_transactions():
  File "/usr/local/lib/python2.7/dist-packages/django/test/testcases.py", line 848, in connections_support_transactions
    for conn in connections.all())
  File "/usr/local/lib/python2.7/dist-packages/django/test/testcases.py", line 848, in <genexpr>
    for conn in connections.all())
  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 49, in __get__
    res = instance.__dict__[self.func.__name__] = self.func(instance)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 676, in supports_transactions
    self.connection.leave_transaction_management()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 324, in leave_transaction_management
    if managed == self.get_autocommit():
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 331, in get_autocommit
    self.ensure_connection()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 127, in ensure_connection
    self.connect()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 114, in connect
    conn_params = self.get_connection_params()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 86, in get_connection_params
    raise NotImplementedError
NotImplementedError:

EDIT

DATABASES = {
    'default': {
        'ENGINE':   'django.db.backends.mysql',
        'NAME':     'integration_tests',
        'USER':     'root',
        'PASSWORD': 'root',
        'HOST':     '192.16x.xx.x',
        'PORT':     '3306',
    },
}
Shiva Krishna Bavandla
  • 25,548
  • 75
  • 193
  • 313
  • What is your `DATABASES` settings? Which version of Django are you using? – Alasdair Nov 06 '17 at 10:32
  • @Alasdair Django version - 1.6.5, Edited my question with djago database settings – Shiva Krishna Bavandla Nov 06 '17 at 10:38
  • 2
    I can't see why that `DATABASES` setting would cause that error. The `get_connection_params()` method is implemented for the mysql backend. Note that Django 1.6.5 is years old, out of date and missing security fixes. – Alasdair Nov 06 '17 at 10:52
  • @Alasdair Yes the application is very large and old... upgrading to latest django is in the process actually.. And regarding error, that's what I didn't understand and couldn't able to debug and hence thought to post a question on SO – Shiva Krishna Bavandla Nov 06 '17 at 11:32
  • It doesn't look that you are actually using `django.db.backends.mysql` here. The error indicates that django tries to use `BaseDatabaseWrapper`, which is meant to be subclassed, or possibly as subclass that doesn't implement all the required methods. – Håken Lid Nov 06 '17 at 13:29

0 Answers0