From 31142b402a12eba53671def706ba08f95b69f45a Mon Sep 17 00:00:00 2001 From: darius BERNARD Date: Wed, 31 May 2017 10:21:38 +0200 Subject: [PATCH 1/6] added tests for django 1.10 --- rest_models/tests/test_introspection.py | 2 +- setup.py | 2 -- tox.ini | 7 +++++++ 3 files changed, 8 insertions(+), 3 deletions(-) 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 From 20b8e91b11f32f43e9be2073ccfde76a9658b3ec Mon Sep 17 00:00:00 2001 From: darius BERNARD Date: Thu, 1 Jun 2017 15:11:37 +0200 Subject: [PATCH 2/6] fixed tests for checking local port via regexp instead of hard code port --- rest_models/tests/test_clients.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_models/tests/test_clients.py b/rest_models/tests/test_clients.py index b0138fe..ea51435 100644 --- a/rest_models/tests/test_clients.py +++ b/rest_models/tests/test_clients.py @@ -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 From 99ab489c161a973d46ce2b05b9f8aac92e5998e9 Mon Sep 17 00:00:00 2001 From: darius BERNARD Date: Thu, 1 Jun 2017 15:12:19 +0200 Subject: [PATCH 3/6] fixed tests for checking local port via regexp instead of hard code port --- rest_models/tests/test_clients.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_models/tests/test_clients.py b/rest_models/tests/test_clients.py index ea51435..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 From b30957d7e949900da1c9a4d84b145ab2ce99814f Mon Sep 17 00:00:00 2001 From: darius BERNARD Date: Fri, 2 Jun 2017 09:35:55 +0200 Subject: [PATCH 4/6] fix side-effect on test database teardown/setup cycle. --- rest_models/backend/creation.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/rest_models/backend/creation.py b/rest_models/backend/creation.py index 62e8a82..a7ea259 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,22 @@ 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 From fd49fc9a8ab1c36279f4203e666b8a60f6b20361 Mon Sep 17 00:00:00 2001 From: darius BERNARD Date: Fri, 2 Jun 2017 10:56:12 +0200 Subject: [PATCH 5/6] fixed misconfiguration of the database test --- rest_models/backend/creation.py | 15 +++++++++++++++ testsettings.py | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/rest_models/backend/creation.py b/rest_models/backend/creation.py index a7ea259..6231418 100644 --- a/rest_models/backend/creation.py +++ b/rest_models/backend/creation.py @@ -73,3 +73,18 @@ def destroy_test_db(self, old_database_name=None, *args, **kwargs): 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/testsettings.py b/testsettings.py index 5ffcb96..8ebb94c 100644 --- a/testsettings.py +++ b/testsettings.py @@ -154,17 +154,17 @@ 'loggers': { 'django': { 'handlers': ['console'], - 'level': 'ERROR', + 'level': 'CRITICAL', 'propagate': True, }, 'django.request': { 'handlers': ['console'], - 'level': 'ERROR', + 'level': 'CRITICAL', 'propagate': False, }, 'rest_models': { 'handlers': ['console'], - 'level': 'ERROR', + 'level': 'CRITICAL', 'propagate': False, } } From 5d1e1fddeb141287a26d6e000bda708a52b71ecd Mon Sep 17 00:00:00 2001 From: darius BERNARD Date: Fri, 2 Jun 2017 11:10:10 +0200 Subject: [PATCH 6/6] reversed verbose for errors. --- testsettings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testsettings.py b/testsettings.py index 8ebb94c..5ffcb96 100644 --- a/testsettings.py +++ b/testsettings.py @@ -154,17 +154,17 @@ 'loggers': { 'django': { 'handlers': ['console'], - 'level': 'CRITICAL', + 'level': 'ERROR', 'propagate': True, }, 'django.request': { 'handlers': ['console'], - 'level': 'CRITICAL', + 'level': 'ERROR', 'propagate': False, }, 'rest_models': { 'handlers': ['console'], - 'level': 'CRITICAL', + 'level': 'ERROR', 'propagate': False, } }