Skip to content

Commit

Permalink
Merge branch 'release/0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Oct 7, 2013
2 parents de5cb24 + 81c5cbe commit b9b333e
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 111 deletions.
42 changes: 14 additions & 28 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,26 @@ services:
- PostgreSQL
python:
- 2.7
env:
- DJANGO="Django==1.4.5" DBENGINE=mysql
- DJANGO="Django==1.4.5" DBENGINE=postgres

- DJANGO="Django==1.5.2" DBENGINE=mysql
- DJANGO="Django==1.5.2" DBENGINE=postgres
env:
- DJANGO="1.4.x" DBENGINE=mysql
- DJANGO="1.4.x" DBENGINE=pg

- DJANGO="https://www.djangoproject.com/download/1.6b2/tarball/" DBENGINE=postgres
- DJANGO="1.5.x" DBENGINE=mysql
- DJANGO="1.5.x" DBENGINE=pg

install:
- pip install uuid python-coveralls coverage pytest pytest-cov pytest-django
- sh -c "if [ '$DBENGINE' = 'postgres' ]; then pip install -q psycopg2; fi"
- sh -c "if [ '$DBENGINE' = 'mysql' ]; then pip install -q MySQL-python; fi"
- pip install -q $DJANGO
- DJANGO="1.6.x" DBENGINE=mysql
- DJANGO="1.6.x" DBENGINE=pg

script:
- make coverage
- DJANGO="dev" DBENGINE=mysql
- DJANGO="dev" DBENGINE=pg

before_install:
- sh -c "if [ '$DBENGINE' = 'postgres' ]; then psql -c 'DROP DATABASE IF EXISTS django_uuid_pk;' -U postgres; fi"
- sh -c "if [ '$DBENGINE' = 'mysql' ]; then mysql -e 'DROP DATABASE IF EXISTS django_uuid_pk;'; fi"

before_script:
- sh -c "if [ '$DBENGINE' = 'postgres' ]; then psql -c 'CREATE DATABASE django_uuid_pk;' -U postgres; fi"
- sh -c "if [ '$DBENGINE' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS django_uuid_pk;'; fi"
install:
- make install-deps

matrix:
exclude:
- python: 3.2
env: DJANGO="Django==1.4.5" DBENGINE=mysql
- python: 3.2
env: DJANGO="Django==1.4.5" DBENGINE=postgres
- python: 3.2
env: DJANGO="Django==1.5.1" DBENGINE=mysql
script:
- make init-db ci

after_success:
- coveralls -c django_uuid_pk/tests/.coveragerc
- coveralls
7 changes: 6 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Release 0.2
-----------

* added full test matrix
* fixed #1

Release 0.1
---------------------------------
-----------

* initial release
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
VERSION=2.0.0
BUILDDIR=~build
DJANGO_14=django==1.4.8
DJANGO_15=django==1.5.4
DJANGO_16=https://www.djangoproject.com/m/releases/1.6/Django-1.6b4.tar.gz
DJANGO_DEV=git+git://github.com/django/django.git

mkbuilddir:
mkdir -p ${BUILDDIR}

install-deps:
pip install -r django_uuid_pk/requirements.pip python-coveralls coverage

test:
py.test -vv
Expand All @@ -19,3 +29,25 @@ coverage:
ifdef BROWSE
firefox ${BUILDDIR}/coverage/index.html
endif


init-db:
@sh -c "if [ '${DBENGINE}' = 'mysql' ]; then mysql -e 'DROP DATABASE IF EXISTS django_uuid_pk;'; fi"
@sh -c "if [ '${DBENGINE}' = 'mysql' ]; then pip install MySQL-python; fi"
@sh -c "if [ '${DBENGINE}' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS django_uuid_pk;'; fi"

@sh -c "if [ '${DBENGINE}' = 'pg' ]; then psql -c 'DROP DATABASE IF EXISTS django_uuid_pk;' -U postgres; fi"
@sh -c "if [ '${DBENGINE}' = 'pg' ]; then psql -c 'CREATE DATABASE django_uuid_pk;' -U postgres; fi"
@sh -c "if [ '${DBENGINE}' = 'pg' ]; then pip install -q psycopg2; fi"

ci: mkbuilddir
@sh -c "if [ '${DJANGO}' = '1.4.x' ]; then pip install ${DJANGO_14}; fi"
@sh -c "if [ '${DJANGO}' = '1.5.x' ]; then pip install ${DJANGO_15}; fi"
@sh -c "if [ '${DJANGO}' = '1.6.x' ]; then pip install ${DJANGO_16}; fi"
@sh -c "if [ '${DJANGO}' = 'dev' ]; then pip install ${DJANGO_DEV}; fi"
@pip install coverage
@python -c "from __future__ import print_function;import django;print('Django version:', django.get_version())"
@echo "Database:" ${DBENGINE}

py.test -vv --cov=django_uuid_pk --cov-report=html --cov-config=.coveragerc

34 changes: 0 additions & 34 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,6 @@ def pytest_configure(config):
if not settings.configured:
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_uuid_pk.tests.settings'

settings.configure(INSTALLED_APPS=('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.auth',
'django_uuid_pk.tests'),
SECRET_KEY = ';klkj;okj;lkn;lklj;lkj;kjmlliuewhy2ioqwjdkh',
DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'django_uuid_pk.sqlite',
'HOST': '',
'PORT': ''}})

settings.ALLOWED_HOSTS = ('127.0.0.1',)

test_db = os.environ.get('DBENGINE', 'sqlite')

if test_db == 'postgres':
settings.DATABASES['default'].update({
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'USER': 'postgres',
'NAME': 'django_uuid_pk',
'OPTIONS': {'autocommit': True}
})
elif test_db == 'mysql':
settings.DATABASES['default'].update({
'ENGINE': 'django.db.backends.mysql',
'USER': 'root',
'NAME': 'django_uuid_pk',
})
elif test_db == 'sqlite':
settings.DATABASES['default'].update({
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
})


def runtests(args=None):
Expand Down
2 changes: 1 addition & 1 deletion django_uuid_pk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import datetime
import os

VERSION = __version__ = (0, 1, 0, 'final', 1)
VERSION = __version__ = (0, 2, 0, 'final', 0)
NAME='django-uuid-pk'
__author__ = 'sax'

Expand Down
29 changes: 24 additions & 5 deletions django_uuid_pk/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.utils.encoding import smart_unicode

try:
# psycopg2 needs us to register the uuid type
#psycopg2 needs us to register the uuid type
import psycopg2

psycopg2.extras.register_uuid()
Expand All @@ -15,10 +15,19 @@


class StringUUID(uuid.UUID):
def __init__(self, *args, **kwargs):
# get around UUID's immutable setter
object.__setattr__(self, 'hyphenate', kwargs.pop('hyphenate', False))

super(StringUUID, self).__init__(*args, **kwargs)

def __unicode__(self):
return self.hex
return unicode(str(self))

def __str__(self):
if self.hyphenate:
return super(StringUUID, self).__str__()

return self.hex

def __len__(self):
Expand All @@ -40,7 +49,7 @@ def __init__(self, version=4, node=None, clock_seq=None,

self.version = version
# We store UUIDs in hex format, which is fixed at 32 characters.
kwargs['max_length'] = 32
kwargs['max_length'] = 36

if kwargs.get('primary_key', False):
auto = True
Expand All @@ -56,6 +65,9 @@ def __init__(self, version=4, node=None, clock_seq=None,
self.namespace, self.name = namespace, name
super(UUIDField, self).__init__(*args, **kwargs)

#def get_internal_type(self):
# return "CharField"

def _create_uuid(self):
if self.version == 1:
args = (self.node, self.clock_seq)
Expand Down Expand Up @@ -103,6 +115,8 @@ def get_db_prep_value(self, value, connection, prepared=False):
"""
if isinstance(value, uuid.UUID):
return str(value)
#elif isinstance(value, StringUUID):
# return str(value)
return value

def value_to_string(self, obj):
Expand All @@ -126,6 +140,10 @@ def to_python(self, value):
# instance already to be able to get our StringUUID in.
return StringUUID(smart_unicode(value))

def get_prep_value(self, value):
value = super(UUIDField, self).get_prep_value(value)
return self.to_python(value)

def formfield(self, **kwargs):
defaults = {
'form_class': forms.CharField,
Expand All @@ -139,7 +157,7 @@ def south_field_triple(self):
# We'll just introspect the _actual_ field.
from south.modelsinspector import introspector

field_class = "django.db.models.fields.CharField"
field_class = "django_uuid_pk.fields.UUIDField"
args, kwargs = introspector(self)
# That's our definition!
return (field_class, args, kwargs)
Expand All @@ -149,14 +167,15 @@ def contribute_to_class(self, cls, name):
if self.primary_key:
_wrap_model_save(cls)


def _wrap_model_save(model):
if not hasattr(model, '_uuid_patched'):
old_save = getattr(model, 'save')
setattr(model, 'save', _wrap_save(old_save))
model._uuid_patched = True

def _wrap_save(func):

def _wrap_save(func):
def inner(self, force_insert=False, force_update=False, using=None, **kwargs):
try:
return func(self, force_insert, force_update, using, **kwargs)
Expand Down
3 changes: 3 additions & 0 deletions django_uuid_pk/requirements.pip
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
uuid
pytest
pytest-django
pytest-cov
17 changes: 10 additions & 7 deletions django_uuid_pk/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@ class ModelUUIDField(models.Model):
uuid4 = UUIDField(version=4, auto=True)
uuid5 = UUIDField(namespace=uuid.NAMESPACE_URL, version=5, auto=True)

class AutoUUIDField(models.Model):
class AutoUUIDFieldModel(models.Model):
uuid = UUIDField(auto=True)


class ManualUUIDField(models.Model):
class ManualUUIDFieldModel(models.Model):
uuid = UUIDField(auto=False)


class NamespaceUUIDField(models.Model):
class NamespaceUUIDFieldModel(models.Model):
uuid = UUIDField(auto=True, namespace=uuid.NAMESPACE_URL, version=5)


class BrokenNamespaceUUIDField(models.Model):
class BrokenNamespaceUUIDFieldModel(models.Model):
uuid = UUIDField(auto=True, namespace='lala', version=5)


class PrimaryKeyUUIDField(models.Model):
class PrimaryKeyUUIDFieldModel(models.Model):
uuid = UUIDField(primary_key=True)
#char = models.CharField(max_length=10, null=True)


class BrokenPrimaryKeyUUIDField(models.Model):
class BrokenPrimaryKeyUUIDFieldModel(models.Model):
uuid = UUIDField(primary_key=True)
unique = models.IntegerField(unique=True)

def __repr__(self):
return {}
45 changes: 39 additions & 6 deletions django_uuid_pk/tests/settings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
import os

SITE_ID = 1
STATIC_URL = '/static/'
SECRET_KEY =';pkj;lkj;lkjh;lkj;oi'
db = os.environ.get('DBENGINE', None)
if db == 'pg':
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_uuid_pk',
'HOST': '127.0.0.1',
'PORT': '',
'USER': 'postgres',
'PASSWORD': '',
'OPTIONS': {
'autocommit': True, # same value for all versions of django (is the default in 1.6)
}}}
elif db == 'mysql':
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_uuid_pk',
'HOST': '127.0.0.1',
'PORT': '',
'USER': 'aa',
'PASSWORD': ''}}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'django_uuid_pk.sqlite',
'HOST': '',
'PORT': ''}}

INSTALLED_APPS = ('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django_uuid_pk.tests')

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'django_uuid_pk.sqlite',
'HOST': '',
'PORT': ''}}
ALLOWED_HOSTS = ('127.0.0.1',)

LOGGING = {
'version': 1,
Expand Down

0 comments on commit b9b333e

Please sign in to comment.