-2

I am trying to use selenium for testing of my django application

After running the following command:

python3 manage.py test function_test(folder)

The following error came up:

*Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 122, in connect
    connection_created.send(sender=self.__class__, connection=self)
  File "/usr/local/lib/python3.4/dist-packages/django/dispatch/dispatcher.py", line 189, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/usr/local/lib/python3.4/dist-packages/django_hstore/apps.py", line 48, in __call__
    return [x(connection) for x in handlers]
  File "/usr/local/lib/python3.4/dist-packages/django_hstore/apps.py", line 48, in <listcomp>
    return [x(connection) for x in handlers]
  File "/usr/local/lib/python3.4/dist-packages/django_hstore/apps.py", line 76, in register_hstore_handler
    register_hstore(connection.connection, globally=HSTORE_REGISTER_GLOBALLY)
  File "/usr/local/lib/python3.4/dist-packages/psycopg2/extras.py", line 775, in register_hstore
    "hstore type not found in the database. "
psycopg2.ProgrammingError: hstore type not found in the database. please install it from your 'contrib/hstore.sql' fil*e

I have already installed hstore in my main project and i m running the tests on a live_server_test_case , so it should not be creating a problem.

Is there a way i can skip migrations before running the selenium code as i have mentioned the creation of hstore type in the setup() function , but i am not able to reach the code.

Forge
  • 6,538
  • 6
  • 44
  • 64
Mona
  • 1

1 Answers1

0

When you run the tests, Django creates a test database. Using LiveServerTestCase means that there is a Django server that can be used by the tests (e.g. by Selenium), it doesn't mean that it uses the live database.

It sounds like you need to create a migration to install the HStoreExtension. The Django test runner will run the migration, preventing the error. See the docs or this question for more info.

Community
  • 1
  • 1
Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • i have already created the migration in my live db for the hstore and its working correctly , when i use my model, but when i run selenium using the way mentioned above , it shows the unable to create test db because of hstore extension issue , how to deal with that....???? – Mona Mar 19 '16 at 14:18
  • and also to add to it , i created a setup function in selenium code , where i add a cursore.execute("create hstore extension "), but since migrations are done before setup function runs, error is occuring, u have any suggestions for that?? – Mona Mar 19 '16 at 14:21
  • Make sure that the hstore migration runs before any migrations that create hstore fields. You might need to change the dependencies of your migrations to do this. – Alasdair Mar 19 '16 at 14:43
  • how do i change the migration dependencies ?? you have any idea how to do that?? – Mona Mar 30 '16 at 15:05
  • Change the `dependencies` list in migration file. [See the docs](https://docs.djangoproject.com/en/1.9/topics/migrations/#migration-files) for an example. I don't know what migrations you have, so I can't tell you which changes to make. The easiest thing might be to add the migration that installs the extension as a dependency to the first migration in the app that uses the `HStoreField`. – Alasdair Mar 30 '16 at 15:14