Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
sudo: false
language: python
python: 3.5
services:
- mysql
- postgresql

env:
global:
- TRAVIS=true
- DATABASE_URL="postgres://postgres:@localhost/default"
- SHARD_001_DATABASE_URL="mysql://travis:@localhost/shard_001"
- SHARD_002_DATABASE_URL="postgres://postgres:@localhost/shard_002"
- REPLICA_001_DATABASE_URL="postgres://postgres:@localhost/sharding_replica_001"
- REPLICA_002_DATABASE_URL="postgres://postgres:@localhost/sharding_replica_002"
matrix:
- TOX_ENV=py27-dj18
- TOX_ENV=py27-dj19
- TOX_ENV=py27-djdev
- TOX_ENV=py34-dj18
- TOX_ENV=py34-dj19
- TOX_ENV=py34-djdev
- TOX_ENV=py35-dj18
- TOX_ENV=py35-dj19
- TOX_ENV=py35-djdev
matrix:
fast_finish: true
allow_failures:
- env: TOX_ENV=py27-djdev
- env: TOX_ENV=py34-djdev
- env: TOX_ENV=py35-djdev

before_install:
- psql -c 'CREATE DATABASE "default";' -U postgres
- mysql -e 'CREATE DATABASE shard_001;'
- psql -c 'CREATE DATABASE "shard_002";' -U postgres
- psql -c 'CREATE DATABASE "sharding_replica_001";' -U postgres
- psql -c 'CREATE DATABASE "sharding_replica_002";' -U postgres
install:
- pip install --upgrade pip virtualenv tox coveralls --quiet
script:
- tox -e $TOX_ENV
after_success:
- coveralls
- cat .tox/$TOX_ENV/log/*.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Django Sharding is a library and part-framework for sharding Django applications

It helps you to scale your applications by sharding your data across multiple databases in a consistent way.

[![Circle CI](https://circleci.com/gh/JBKahn/django-sharding.svg?style=svg)](https://circleci.com/gh/JBKahn/django-sharding)
[![Build Status](https://travis-ci.org/JBKahn/django-sharding.svg?branch=master)](https://travis-ci.org/JBKahn/django-sharding)
[![PyPI version](https://badge.fury.io/py/django-sharding.svg)](https://badge.fury.io/py/django-sharding)
[![PyPi downloads](https://img.shields.io/pypi/dm/django-sharding.svg)](https://crate.io/packages/django-sharding/)
[![Coverage Status](https://coveralls.io/repos/JBKahn/django-sharding/badge.svg?branch=master&service=github)](https://coveralls.io/github/JBKahn/django-sharding?branch=master)
Expand Down
29 changes: 0 additions & 29 deletions circle.yml

This file was deleted.

4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
django>=1.8
dj-database-url==0.3.0
-r requirements/common.txt
-r requirements/development.txt
1 change: 1 addition & 0 deletions requirements/_without_django.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dj-database-url==0.3.0
2 changes: 2 additions & 0 deletions requirements/common.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
django>=1.8
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplication preventing in tox's django.

-r _without_django.txt
5 changes: 0 additions & 5 deletions requirements-test.txt → requirements/development.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
-r requirements.txt

psycopg2==2.6.1
mysqlclient==1.3.7
mock==1.0.1
django_nose==1.4.2
coverage==4.0
coveralls==1.0
tox==2.1.1
3 changes: 0 additions & 3 deletions run_coverage.sh

This file was deleted.

121 changes: 57 additions & 64 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,72 @@
import sys

try:
import django
from django.conf import settings
from django.test.utils import get_runner
from django_sharding_library.settings_helpers import database_configs

CIRCLECI = os.getenv("CIRCLECI", False)

DATABASES = database_configs(databases_dict={
'unsharded_databases': [
{
'name': 'default',
'environment_variable': 'DATABASE_URL',
'default_database_url': 'postgres://sharding:sharding@localhost/sharding' if CIRCLECI else 'sqlite://testing123'
}
],
'sharded_databases': [
{
'name': 'app_shard_001',
'environment_variable': 'SHARD_001_DATABASE_URL',
'default_database_url': 'postgres://sharding:sharding@localhost/sharding_001' if CIRCLECI else 'sqlite://testing124',
'replicas': [
{
'name': 'app_shard_001_replica_001',
'environment_variable': 'REPLICA_001_DATABASE_URL',
'default_database_url': 'postgres://sharding:sharding@localhost/sharding_replica_001' if CIRCLECI else 'sqlite://testing125'
},
{
'name': 'app_shard_001_replica_002',
'environment_variable': 'REPLICA_002_DATABASE_URL',
'default_database_url': 'postgres://sharding:sharding@localhost/sharding_replica_002' if CIRCLECI else 'sqlite://testing126'
},
]
},
{
'name': 'app_shard_002',
'environment_variable': 'SHARD_002_DATABASE_URL',
'default_database_url': 'mysql://sharding:sharding@localhost/sharding_002' if CIRCLECI else 'sqlite://testing127'
},
]
})

settings.configure(
DEBUG=True,
USE_TZ=True,
DATABASES=DATABASES,
DATABASE_ROUTERS=['django_sharding_library.router.ShardedRouter'],
AUTH_USER_MODEL='tests.User',
ROOT_URLCONF="django_sharding.urls",
INSTALLED_APPS=[
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sites",
"django_sharding",
"django_nose",
"tests",
],
SITE_ID=1,
MIDDLEWARE_CLASSES=(),
)

try:
import django
setup = django.setup
except AttributeError:
pass
else:
setup()

except ImportError:
import traceback
traceback.print_exc()
raise ImportError("To fix this error, run: pip install -r requirements-test.txt")


TRAVISCI = os.environ.get('TRAVIS')

DATABASES = database_configs(databases_dict={
'unsharded_databases': [
{
'name': 'default',
'environment_variable': 'DATABASE_URL',
'default_database_url': 'postgres://postgres:@localhost/default' if TRAVISCI else 'sqlite://testing123'
}
],
'sharded_databases': [
{
'name': 'app_shard_001',
'environment_variable': 'SHARD_001_DATABASE_URL',
'default_database_url': 'postgres://postgres:@localhost/sharding_001' if TRAVISCI else 'sqlite://testing124',
'replicas': [
{
'name': 'app_shard_001_replica_001',
'environment_variable': 'REPLICA_001_DATABASE_URL',
'default_database_url': 'postgres://postgres:@localhost/sharding_replica_001' if TRAVISCI else 'sqlite://testing125'
},
{
'name': 'app_shard_001_replica_002',
'environment_variable': 'REPLICA_002_DATABASE_URL',
'default_database_url': 'postgres://postgres:@localhost/sharding_replica_002' if TRAVISCI else 'sqlite://testing126'
},
]
},
{
'name': 'app_shard_002',
'environment_variable': 'SHARD_002_DATABASE_URL',
'default_database_url': 'mysql://travis:@localhost/sharding_002' if TRAVISCI else 'sqlite://testing127'
},
]
})
settings.configure(
DEBUG=True,
USE_TZ=True,
DATABASES=DATABASES,
DATABASE_ROUTERS=['django_sharding_library.router.ShardedRouter'],
AUTH_USER_MODEL='tests.User',
ROOT_URLCONF="django_sharding.urls",
INSTALLED_APPS=[
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sites",
"django_sharding",
"django_nose",
"tests",
],
SITE_ID=1,
MIDDLEWARE_CLASSES=(),
)
django.setup()


def run_tests(*test_args):
if not test_args:
test_args = ['tests']
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
packages=find_packages(),
include_package_data=True,
install_requires=['Django>=1.8', 'dj-database-url==0.3.0'],
tests_require=['psycopg2==2.6.1', 'mysqlclient==1.3.7', 'mock==1.0.1', 'django_nose==1.4.2', 'coverage==4.0', 'coveralls==1.0', 'tox==2.1.1'],
tests_require=['psycopg2==2.6.1', 'mysqlclient==1.3.7', 'mock==1.0.1', 'django_nose==1.4.2', 'tox==2.1.1'],
Copy link
Contributor Author

@Surgo Surgo Apr 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coverage and coveralls are needed only in the ci.

license="BSD",
zip_safe=False,
keywords='django shard sharding library',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class BigAutoFieldTestCase(TestCase):
def test_largest_id(self):
if settings.DATABASES['default']['ENGINE'] == Backends.POSTGRES:
if settings.DATABASES['default']['ENGINE'] in [Backends.POSTGRES, Backends.SQLITE]:
max_id = 9223372036854775807
else:
max_id = 18446744073709551615
Expand Down Expand Up @@ -41,7 +41,7 @@ def get_next_id(self):

class TableShardedIDFieldTestCase(TestCase):
def test_largest_id(self):
if settings.DATABASES['app_shard_001']['ENGINE'] == Backends.POSTGRES:
if settings.DATABASES['app_shard_001']['ENGINE'] in [Backends.POSTGRES, Backends.SQLITE]:
max_id = 9223372036854775807
else:
max_id = 18446744073709551615
Expand Down
4 changes: 3 additions & 1 deletion tests/test_migration_command.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from mock import patch
from unittest import skip

from django.core.management import call_command
from django.test import TestCase
from mock import patch

from django_sharding_library.exceptions import InvalidMigrationException

Expand Down Expand Up @@ -39,6 +40,7 @@ def test_migrate_replica_raises_exception(self, mock_migrate_command):

self.assertEqual(databases_migrated, expected_migrated_databases)

@skip("skipped until fix https://code.djangoproject.com/ticket/26597")
def test_passes_other_args(self, mock_migrate_command):
call_command('migrate', database='app_shard_001', fake=True, verbosity=0, app_label='tests', migration_name='0001', noinput=True, fake_initial=True, interactive=False, list=True)

Expand Down
38 changes: 17 additions & 21 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
# Tox (http://tox.testrun.org/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
envlist = py27, py34, py35
envlist =
py27-dj{18,19,dev}
py34-dj{18,19,dev}
py35-dj{18,19,dev}

[testenv]
passenv=
-passenv=
DATABASE_URL
SHARD_001_DATABASE_URL
SHARD_002_DATABASE_URL
REPLICA_001_DATABASE_URL
REPLICA_002_DATABASE_URL
CIRCLECI
TRAVIS
basepython =
py27: python2.7
py34: python3.4
py35: python3.5
deps =
coverage
-r{toxinidir}/requirements/_without_django.txt
-r{toxinidir}/requirements/development.txt
dj18: Django>=1.8,<1.9
dj19: Django>=1.9,<1.10
djdev: https://github.com/django/django/archive/master.tar.gz
commands=
- pip install mysqlclient==1.3.7
coverage run --source=django_sharding,django_sharding_library -a setup.py test
deps=
nose
coverage==4.0

[testenv:clean]
commands=
coverage erase

[testenv:stats]
commands=
coverage report -m
coverage html -d $CIRCLE_ARTIFACTS