Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Run multiple Django and Python version's tests on Travis-CI #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
dist: xenial
sudo: false

language: python
python:
- 2.7
- 3.4
- 3.5
- 3.6
- 3.7

cache: pip

env:
- DJANGO=1.11
- DJANGO=2.0
- DJANGO=2.1
- DJANGO=master

matrix:
fast_finish: true
include:
- python: 3.7
env: TOXENV=flake8
exclude:
- python: 2.7
env: DJANGO=2.0
- python: 2.7
env: DJANGO=2.1
- python: 3.4
env: DJANGO=2.1
allow_failures:
- env: DJANGO=master
install:
- travis_retry pip install -U tox-travis

script:
- tox
22 changes: 11 additions & 11 deletions flash/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import six
import time
import copy

from django.utils import six
from distutils.version import StrictVersion
from abc import ABCMeta, abstractmethod, abstractproperty
from collections import defaultdict
Expand Down Expand Up @@ -639,10 +639,10 @@ def get_key(self, *args, **kwargs):
value = field_dict[field.attname]
if isinstance(value, models.Model):
# get the pk value on instance
if field.rel:
rel_model = field.rel.to
if field.remote_field:
Copy link
Author

Choose a reason for hiding this comment

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

rel_model = field.remote_field.model
else:
# In very rare cases, field.rel is found to be None
# In very rare cases, field.remote_field is found to be None
# that I do not know why.
# fallback method to get rel_model
rel_model = value.__class__
Expand Down Expand Up @@ -869,7 +869,7 @@ def remove_fk_instances(self, instance):
delattr(instance, attr)

for field in instance._meta.fields:
if field.rel:
if field.remote_field:
attr = '_%s_cache' % field.name
if hasattr(instance, attr):
delattr(instance, attr)
Expand Down Expand Up @@ -959,7 +959,7 @@ def __new__(cls, *args, **kwargs):
relation_splits = ncls.relation.split('__')
relation_str = ''
for field_name in relation_splits:
rel_model = rel_model._meta.get_field(field_name).rel.to
rel_model = rel_model._meta.get_field(field_name).remote_field.model
if relation_str:
relation_str += '__%s' % field_name
else:
Expand All @@ -975,7 +975,7 @@ class RelatedModelInvalidationCache(object):
""" Mixin class used in RelatedInstanceCache, RelatedQuerysetCache
"""
def _get_invalidation_models(self):
return [self.model] + self.rel_models.keys()
return [self.model] + list(self.rel_models)
Copy link
Author

Choose a reason for hiding this comment

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


def _get_keys_to_be_invalidated(self, instance, signal, using):
keys = []
Expand Down Expand Up @@ -1173,7 +1173,7 @@ def __new__(cls, *args, **kwargs):
relation_splits = ncls.relation.split('__')
relation_str = ''
for field_name in relation_splits:
rel_model = rel_model._meta.get_field(field_name).rel.to
rel_model = rel_model._meta.get_field(field_name).remote_field.model
if relation_str:
relation_str += '__%s' % field_name
else:
Expand Down Expand Up @@ -1267,7 +1267,7 @@ def __get__(self, instance, instance_type=None):
# If NULL is an allowed value, return it.
if self.field.null:
return None
raise self.field.rel.to.DoesNotExist
raise self.field.remote_field.model.DoesNotExist
rel_obj = self.cache_class.get(val)
setattr(instance, self.cache_name, rel_obj)
return rel_obj
Expand Down Expand Up @@ -1385,7 +1385,7 @@ def patch_cached_foreignkeys(cls):
for model, cached_foreignkeys in cls.model_cached_foreignkeys.items():
for key in cached_foreignkeys:
try:
rel_model = model._meta.get_field(key).rel.to
rel_model = model._meta.get_field(key).remote_field.model
rel_model_pk_name = rel_model._meta.pk.name
cache_class = rel_model.cache.get_cache_class_for(
rel_model_pk_name)
Expand All @@ -1395,7 +1395,7 @@ def patch_cached_foreignkeys(cls):
assert False, ("Cached foreignkey can't be made on field "+
"`%s` of %s. Because %s is not cached on "+
"it's primary key") % (
key, model, model._meta.get_field(key).rel.to)
key, model, model._meta.get_field(key).remote_field.model)


@classmethod
Expand Down
3 changes: 1 addition & 2 deletions flash/collector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import six

from django.utils import six
from collections import defaultdict
from functools import wraps

Expand Down
1 change: 0 additions & 1 deletion flash/tests/__init__.py

This file was deleted.

33 changes: 0 additions & 33 deletions flash/tests/utils.py

This file was deleted.

25 changes: 25 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python

import os
import sys

os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'tests.settings')


def runtests():
import django
from django.conf import settings
from django.test.utils import get_runner

if hasattr(django, 'setup'):
django.setup()

TestRunner = get_runner(settings)
test_runner = TestRunner(verbosity=2, interactive=True)
failures = test_runner.run_tests(['tests'])
sys.exit(bool(failures))


if __name__ == "__main__":
runtests()

1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
'flash',
],
zip_safe=False,
test_suite='runtests.runtests',
)
Empty file added tests/__init__.py
Empty file.
File renamed without changes.
6 changes: 3 additions & 3 deletions flash/tests/models.py → tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class ModelA(models.Model):
class ModelB(models.Model):
Copy link
Author

Choose a reason for hiding this comment

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

flash.tests module does not required in flashpackage.
So its removed from package.

num = models.IntegerField()
text = models.CharField(max_length=50)
a = models.ForeignKey(ModelA)
a = models.ForeignKey(ModelA, on_delete=models.CASCADE)


class ModelC(models.Model):
a = models.ForeignKey(ModelA)
b = models.ForeignKey(ModelB)
a = models.ForeignKey(ModelA, on_delete=models.CASCADE)
b = models.ForeignKey(ModelB, on_delete=models.CASCADE)
num = models.IntegerField()


Expand Down
12 changes: 12 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SECRET_KEY = 's3cr3t'
INSTALLED_APPS = [
'django.contrib.contenttypes',
'flash',
'tests',
]
DATABASES = {
'default': {
'NAME': 'default',
'ENGINE': 'django.db.backends.sqlite3',
},
}
5 changes: 3 additions & 2 deletions flash/tests/test_flash.py → tests/test_flash.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import time

from django.test import TestCase

from flash.base import cache, BatchCacheQuery

from .utils import TestCase
from .models import ModelA, ModelB, ModelC, ModelD
from .caches import BCacheOnNum, AListCacheOnD

Expand Down Expand Up @@ -166,7 +167,7 @@ def test_basic1(self):
2: BCacheOnNum(num=2),
}).get(only_cache=True)

self.assertTrue(result.keys() == [1])
self.assertEqual(list(result), [1])

result = BatchCacheQuery({
1: ModelA.cache.get_query(num=1),
Expand Down
43 changes: 43 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[tox]
envlist =
py{27,34,35,36}-django111,
py{34,35,36,37}-django20,
py{35,36,37}-django21,
py{35,36,37}-djangomaster,
flake8

[travis]
python =
2.7: py27
3.4: py34
3.5: py35
3.6: py36
3.7: py37

[travis:env]
DJANGO =
1.11: django111
2.0: django20
2.1: django21
master: djangomaster

[testenv]
deps =
django111: django>=1.11,<2.0
django20: django>=2.0,<2.1
django21: django>=2.1,<2.2
djangomaster: https://github.com/django/django/archive/master.tar.gz
usedevelop = True
ignore_outcome =
djangomaster: True
commands =
python setup.py test
setenv =
PYTHONDONTWRITEBYTECODE=1

[testenv:flake8]
deps = flake8
commands = flake8

[flake8]
ignore = D203