Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

Commit

Permalink
Merge pull request #7 from swisscom/travis-integration
Browse files Browse the repository at this point in the history
Travis integration
  • Loading branch information
jean-christophe zulian committed Sep 16, 2014
2 parents a266c93 + adec396 commit 7ca1068
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: python
python:
- "2.7"
- "3.4"
env:
- DJANGO_VERSION=1.6.7
- DJANGO_VERSION=1.7

# Dependencies
install:
- pip install -q django==$DJANGO_VERSION
- pip install six

# Run tests
script: DJANGO_SETTINGS_MODULE=cleanerversion.settings.base python ./manage.py test versions
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""

setup(name='CleanerVersion',
version='1.1.2',
version='1.2.0',
description='A versioning solution for relational data models',
long_description='CleanerVersion is a solution that allows you to read and write multiple versions of an entry '
'to and from your relational database. It allows to keep track of modifications on an object '
Expand All @@ -40,6 +40,7 @@
'Framework :: Django',
'Intended Audience :: Developers',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Topic :: Database',
'Topic :: System :: Archiving',
])
8 changes: 4 additions & 4 deletions versions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def _create_at(self, timestamp=None, **kwargs):
:param kwargs: arguments needed for initializing the instance
:return: an instance of the class
"""
ident = unicode(uuid.uuid4())
ident = six.u(str(uuid.uuid4()))
if timestamp is None:
timestamp = get_utc_now()
kwargs['id'] = ident
Expand Down Expand Up @@ -564,7 +564,7 @@ def __init__(self, *args, **kwargs):
version_start_date_field = self.through._meta.get_field('version_start_date')
version_end_date_field = self.through._meta.get_field('version_end_date')
except (FieldDoesNotExist) as e:
print str(e) + "; available fields are " + ", ".join(self.through._meta.get_all_field_names())
print(str(e) + "; available fields are " + ", ".join(self.through._meta.get_all_field_names()))
raise e
# FIXME: this probably does not work when auto-referencing

Expand Down Expand Up @@ -814,7 +814,7 @@ def clone(self, forced_version_date=None):
# set earlier_version's ID to a new UUID so the clone (later_version) can
# get the old one -- this allows 'head' to always have the original
# id allowing us to get at all historic foreign key relationships
earlier_version.id = unicode(uuid.uuid4())
earlier_version.id = six.u(str(uuid.uuid4()))
earlier_version.version_end_date = forced_version_date
earlier_version.save()

Expand Down Expand Up @@ -888,7 +888,7 @@ def post_init_initialize(sender, instance, **kwargs):
:return: None
"""
if isinstance(instance, sender) and isinstance(instance, Versionable):
ident = unicode(uuid.uuid4())
ident = six.u(str(uuid.uuid4()))
now = get_utc_now()
if not hasattr(instance, 'version_start_date') or instance.version_start_date is None:
instance.version_start_date = now
Expand Down
21 changes: 17 additions & 4 deletions versions/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from django.test import TestCase
import datetime
from django.utils.timezone import utc
import six
from time import sleep
import itertools

Expand Down Expand Up @@ -682,6 +683,11 @@ class Player(Versionable):
name = CharField(max_length=200)
team = VersionedForeignKey(Team, null=True)

def __str__(self):
return "<" + str(self.__class__.__name__) + " object: " + str(
self.name) + " {valid: [" + self.version_start_date.isoformat() + " | " + (
self.version_end_date.isoformat() if self.version_end_date else "None") + "], created: " + self.version_birth_date.isoformat() + "}>"


class OneToManyTest(TestCase):
def setUp(self):
Expand Down Expand Up @@ -723,6 +729,7 @@ def test_creating_new_version_of_the_team(self):
self.assertEqual(2, team_at_t2.player_set.count())

def test_creating_new_version_of_the_player(self):
global filter
t1 = get_utc_now()
sleep(0.1)

Expand All @@ -739,13 +746,16 @@ def test_creating_new_version_of_the_player(self):
team = Team.objects.as_of(t1).first()
self.assertEqual(2, team.player_set.count())
for player in team.player_set.all():
self.assertNotEqual(u'p1.v2', unicode(player.name))
self.assertNotEqual(u'p1.v2', six.u(str(player.name)))

# at t2 there must be a 2 players and on of them is named 'p1.v2'
team = Team.objects.as_of(t2).first()
self.assertEqual(2, team.player_set.count())

matches = itertools.ifilter(lambda x: x.name == 'p1.v2', team.player_set.all())
if six.PY2:
matches = itertools.ifilter(lambda x: x.name == 'p1.v2', team.player_set.all())
if six.PY3:
matches = filter(lambda x: x.name == 'p1.v2', team.player_set.all())
self.assertEqual(1, len(list(matches)))

def test_adding_more_player_to_the_team(self):
Expand Down Expand Up @@ -917,7 +927,7 @@ def test_simple_filter_using_q_objects(self):
Player.objects.as_of(t1).filter(Q(name__startswith='p1') | Q(name__startswith='p2')).values_list('name',
flat=True))
self.assertEqual(2, len(t1_players))
self.assertItemsEqual(t1_players, ['p1.v1', 'p2.v1'])
self.assertListEqual(sorted(t1_players), sorted(['p1.v1', 'p2.v1']))


class Directory(Versionable):
Expand Down Expand Up @@ -992,7 +1002,10 @@ def test_creating_new_version_of_the_subdir(self):
self.assertEqual(2, parentdir_at_t2.directory_set.count())

# ... and one of then is named 'subdir1.v2'
matches = itertools.ifilter(lambda x: x.name == 'subdir1.v2', parentdir_at_t2.directory_set.all())
if six.PY2:
matches = itertools.ifilter(lambda x: x.name == 'subdir1.v2', parentdir_at_t2.directory_set.all())
if six.PY3:
matches = filter(lambda x: x.name == 'subdir1.v2', parentdir_at_t2.directory_set.all())
self.assertEqual(1, len(list(matches)))

def test_adding_more_subdir(self):
Expand Down

0 comments on commit 7ca1068

Please sign in to comment.