Skip to content

Commit 99537be

Browse files
committed
Merge pull request #88 from django-json-api/feature/test-all-versions
Automatically test combinations of Python 2.7+, Django 1.6+, and DRF 3.1+
2 parents b51d361 + 9ba86d0 commit 99537be

25 files changed

+3574
-179
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ pip-log.txt
2626
pip-delete-this-directory.txt
2727

2828
# Pycharm project files
29-
.idea/
29+
.idea/
30+
31+
# Tox
32+
.tox/

.travis.yml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
language: python
22
sudo: false
3-
python:
4-
- "2.7"
5-
- "3.3"
6-
- "3.4"
7-
install:
8-
- pip install -e .
9-
script: python runtests.py
3+
install: pip install tox
4+
script: tox
5+
env:
6+
- TOXENV=py27-django16-drf31
7+
- TOXENV=py27-django16-drf32
8+
- TOXENV=py32-django16-drf31
9+
- TOXENV=py32-django16-drf32
10+
- TOXENV=py33-django16-drf31
11+
- TOXENV=py33-django16-drf32
12+
- TOXENV=py27-django17-drf31
13+
- TOXENV=py27-django17-drf32
14+
- TOXENV=py32-django17-drf31
15+
- TOXENV=py32-django17-drf32
16+
- TOXENV=py33-django17-drf31
17+
- TOXENV=py33-django17-drf32
18+
- TOXENV=py34-django17-drf31
19+
- TOXENV=py34-django17-drf32
20+
- TOXENV=py27-django18-drf31
21+
- TOXENV=py27-django18-drf32
22+
- TOXENV=py32-django18-drf31
23+
- TOXENV=py32-django18-drf32
24+
- TOXENV=py33-django18-drf31
25+
- TOXENV=py33-django18-drf32
26+
- TOXENV=py34-django18-drf31
27+
- TOXENV=py34-django18-drf32

docs/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ like the following:
5353

5454
1. Python >= 2.7
5555
2. Django
56-
3. Django REST Framework >= 2.4
56+
3. Django REST Framework >= 3.1
5757

5858
## Installation
5959

example/api/resources/identity.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from django.contrib.auth import models as auth_models
2+
from django.utils import encoding
3+
24
from rest_framework import viewsets, generics, renderers, parsers, serializers
35
from rest_framework.decorators import list_route, detail_route
46
from rest_framework.response import Response
@@ -31,8 +33,8 @@ def posts(self, request):
3133
posts = [{'id': 1, 'title': 'Test Blog Post'}]
3234

3335
data = {
34-
u'identities': IdentitySerializer(identities, many=True).data,
35-
u'posts': PostSerializer(posts, many=True).data,
36+
encoding.force_text('identities'): IdentitySerializer(identities, many=True).data,
37+
encoding.force_text('posts'): PostSerializer(posts, many=True).data,
3638
}
3739
return Response(utils.format_keys(data, format_type='camelize'))
3840

example/api/urls.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +0,0 @@
1-
"""
2-
Example app URLs
3-
"""
4-
from django.conf.urls import patterns, include, url
5-
from rest_framework import routers
6-
from .resources.identity import Identity, GenericIdentity
7-
8-
router = routers.DefaultRouter(trailing_slash=False)
9-
10-
router.register(r'identities', Identity)
11-
12-
urlpatterns = router.urls
13-
14-
urlpatterns += patterns('',
15-
url(r'identities/default/(?P<pk>\d+)',
16-
GenericIdentity.as_view(), name='user-default'),
17-
)
18-

example/factories/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- encoding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
import factory
5+
6+
from example.models import Blog
7+
8+
9+
class BlogFactory(factory.django.DjangoModelFactory):
10+
class Meta:
11+
model = Blog
12+
13+
name = "Blog 1"

example/models.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- encoding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models
5+
from django.utils.encoding import python_2_unicode_compatible
6+
7+
8+
class BaseModel(models.Model):
9+
"""
10+
I hear RoR has this by default, who doesn't need these two fields!
11+
"""
12+
created_at = models.DateTimeField(auto_now_add=True)
13+
modified_at = models.DateTimeField(auto_now=True)
14+
15+
class Meta:
16+
abstract = True
17+
18+
19+
@python_2_unicode_compatible
20+
class Blog(BaseModel):
21+
name = models.CharField(max_length=100)
22+
tagline = models.TextField()
23+
24+
def __str__(self):
25+
return self.name
26+
27+
28+
@python_2_unicode_compatible
29+
class Author(BaseModel):
30+
name = models.CharField(max_length=50)
31+
email = models.EmailField()
32+
33+
def __str__(self):
34+
return self.name
35+
36+
37+
@python_2_unicode_compatible
38+
class Entry(BaseModel):
39+
blog = models.ForeignKey(Blog)
40+
headline = models.CharField(max_length=255)
41+
body_text = models.TextField()
42+
pub_date = models.DateField()
43+
mod_date = models.DateField()
44+
authors = models.ManyToManyField(Author)
45+
n_comments = models.IntegerField()
46+
n_pingbacks = models.IntegerField()
47+
rating = models.IntegerField()
48+
49+
def __str__(self):
50+
return self.headline

example/serializers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from rest_framework import serializers
2+
3+
4+
class BlogSerializer(serializers.Serializer):
5+
6+
class Meta:
7+
fields = ('name', )

example/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
'django.contrib.auth',
2323
'django.contrib.admin',
2424
'rest_framework',
25-
'example.api',
25+
'example',
2626
]
2727

28-
ROOT_URLCONF = 'example.api.urls'
28+
ROOT_URLCONF = 'example.urls'
2929

3030
SECRET_KEY = 'abc123'
3131

example/tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pytest_factoryboy import register
2+
3+
from example.factories import BlogFactory
4+
5+
register(BlogFactory)

0 commit comments

Comments
 (0)