Skip to content

Commit

Permalink
Merge 5d1e1fd into a630b3c
Browse files Browse the repository at this point in the history
  • Loading branch information
darius committed Jun 2, 2017
2 parents a630b3c + 5d1e1fd commit 6711b44
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
35 changes: 30 additions & 5 deletions rest_models/backend/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@ 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):
"""
Creates a test database, prompting the user for confirmation if the
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
Expand All @@ -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
)
4 changes: 2 additions & 2 deletions rest_models/tests/test_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rest_models/tests/test_introspection.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import os
import sys
import unittest

import rest_models

Expand Down Expand Up @@ -51,7 +50,6 @@
packages=[
'rest_models',
'rest_models.backend',

],
include_package_data=True,
license="GNU GENERAL PUBLIC LICENSE",
Expand Down
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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



Expand Down

0 comments on commit 6711b44

Please sign in to comment.