diff --git a/rest_models/backend/creation.py b/rest_models/backend/creation.py index 62e8a82..6231418 100644 --- a/rest_models/backend/creation.py +++ b/rest_models/backend/creation.py @@ -34,7 +34,6 @@ class DatabaseCreation(BaseDatabaseCreation): sql_for_pending_references = do_nothing sql_indexes_for_model = do_nothing sql_create_model = do_nothing - destroy_test_db = do_nothing def create_test_db(self, verbosity=1, autoclobber=False, serialize=True, keepdb=False): """ @@ -42,10 +41,7 @@ def create_test_db(self, verbosity=1, autoclobber=False, serialize=True, keepdb= database already exists. Returns the name of the test database created. """ # Don't import django.core.management if it isn't needed. - test_override = self.connection.settings_dict.get('TEST', {}) - if any(test_override.values()): - self.connection.settings_dict.update(test_override) - elif not self.connection.alias.startswith('TEST_'): + if not self.connection.alias.startswith('TEST_'): test_database_name = self._get_test_db_name() settings.DATABASES[self.connection.alias]["NAME"] = test_database_name self.connection.settings_dict["NAME"] = test_database_name @@ -58,8 +54,37 @@ def _get_test_db_name(self): _create_test_db() and when no external munging is done with the 'NAME' settings. """ + test_alias = 'TEST_'+self.connection.alias + if self.connection.settings_dict['TEST']['NAME']: + return self.connection.settings_dict['TEST']['NAME'] if settings.DATABASES.get(test_alias): return settings.DATABASES[test_alias]['NAME'] name = self.connection.settings_dict['NAME'] return re.sub('https?://[^/]+/', LocalApiAdapter.SPECIAL_URL + "/", name, count=1) + + def destroy_test_db(self, old_database_name=None, *args, **kwargs): + """ + Destroy a test database, prompting the user for confirmation if the + database already exists. + """ + + # Restore the original database name + if old_database_name is not None: + settings.DATABASES[self.connection.alias]["NAME"] = old_database_name + self.connection.settings_dict["NAME"] = old_database_name + + def test_db_signature(self): + """ + Returns a tuple with elements of self.connection.settings_dict (a + DATABASES setting value) that uniquely identify a database + accordingly to the RDBMS particularities. + """ + settings_dict = self.connection.settings_dict + return ( + settings_dict['HOST'], + settings_dict['PORT'], + settings_dict['ENGINE'], + self._get_test_db_name(), + self.connection.alias + ) diff --git a/rest_models/tests/test_clients.py b/rest_models/tests/test_clients.py index b0138fe..5b683dd 100644 --- a/rest_models/tests/test_clients.py +++ b/rest_models/tests/test_clients.py @@ -20,7 +20,7 @@ def test_existing_db(self): called = [] def tmp_exec(self_dc, args, env): - self.assertEqual(env['_resty_host'], 'http://localhost:8097/api/v2*') + self.assertRegexpMatches(env['_resty_host'], 'http://localhost:[0-9]*/api/v2\*') called.append(args) DatabaseClient.execute_subprocess = tmp_exec @@ -33,7 +33,7 @@ def test_to_run_db(self): called = [] def tmp_exec(self_dc, args, env): - self.assertEqual(env['_resty_host'], 'http://localhost:8080/api/v2*') + self.assertRegexpMatches(env['_resty_host'], 'http://localhost:[0-9]*/api/v2\*') called.append(args) DatabaseClient.execute_subprocess = tmp_exec diff --git a/rest_models/tests/test_introspection.py b/rest_models/tests/test_introspection.py index a06638d..b87f963 100644 --- a/rest_models/tests/test_introspection.py +++ b/rest_models/tests/test_introspection.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, print_function, unicode_literals +import six from django.core.management import call_command from django.test.testcases import TestCase -import six class TestIntrospection(TestCase): diff --git a/setup.py b/setup.py index 82bfd4d..52a9b4b 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,6 @@ import os import sys -import unittest import rest_models @@ -51,7 +50,6 @@ packages=[ 'rest_models', 'rest_models.backend', - ], include_package_data=True, license="GNU GENERAL PUBLIC LICENSE", diff --git a/tox.ini b/tox.ini index 1203180..3b74025 100644 --- a/tox.ini +++ b/tox.ini @@ -13,6 +13,10 @@ envlist = py{27,34,35}-django19-drest15-drf34 py{27,34}-django18-drest16-drf35 py{27,34,35}-django19-drest16-drf35 + py{27,34,35}-django110-drest16-drf35 + py{27,34,35}-django110-drest16-drf36 + # py{27,34,35}-django111-drest16-drf35 + # py{27,34,35}-django111-drest16-drf36 isort flake8 @@ -26,10 +30,13 @@ deps = coverage django18: django >=1.8,<1.9 django19: django >=1.9a1,<1.10 + django110: django >=1.10a1,<1.11 + django111: django >=1.11a1,<1.12 drest15: dynamic-rest<1.6 drest16: dynamic-rest<1.7 drf34: djangorestframework<3.5 drf35: djangorestframework<3.6 + drf36: djangorestframework<3.7