Skip to content

Commit 19e5fe9

Browse files
committed
fix test
1 parent 2d32eb0 commit 19e5fe9

File tree

8 files changed

+27
-30
lines changed

8 files changed

+27
-30
lines changed

.travis.yml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
11
language: python
22
python:
3-
- "2.7"
4-
- "3.8"
3+
- "3.7"
54
env:
6-
- DJANGO_VERSION=1.7
7-
- DJANGO_VERSION=1.8
8-
- DJANGO_VERSION=1.9
9-
- DJANGO_VERSION=1.10
105
- DJANGO_VERSION=2.0
116
- DJANGO_VERSION=3.0
127
install:
13-
- pip install -q Django==$DJANGO_VERSION flake8 coverage
8+
- pip install -q Django==$DJANGO_VERSION flake8 coverage djangorestframework
149
script:
1510
- flake8 --exclude vote/migrations/* vote
1611
- coverage run runtests.py
17-
matrix:
18-
exclude:
19-
- python: "3.8"
20-
env: DJANGO_VERSION=1.7
21-
- python: "2.7"
22-
env: DJANGO_VERSION=2.0
23-
- python: "2.7"
24-
env: DJANGO_VERSION=3.0
2512

2613
after_success:
2714
- bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,16 @@ Review.votes.all(user_id)
7171

7272
```
7373

74-
``django-vote`` now requires Django 1.7 or greater. (for Django < 1.7, please install previous release `django-vote==1.1.3`)
74+
#### Use `VoteMixin` for REST API
75+
76+
``` python
77+
class CommentViewSet(ModelViewSet, VoteMixin):
78+
queryset = Comment.objects.all()
79+
serializer_class = CommentSerializer
80+
```
81+
82+
```sh
83+
POST /api/comments/{id}/vote/
84+
POST /api/comments/{id}/vote/ {"action":"down"}
85+
DELETE /api/comments/{id}/vote/
86+
```

docs/changelog.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Changelog
55
------------------
66
* Add post_vote signal
77
* Add VoteMixin for easily write vote api
8-
* Support Django 3.0
8+
* Drop support for Django < 2.0
9+
* Add Django 3.0 test
910

1011
2.1.7(2018.05.08)
1112
-----------------

test/templates/test/comments.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{% load vote %}
22
{% for comment in comments %}
33
{{comment.content}} {% vote_exists comment user %}
4-
{% endfor %}
4+
{% endfor %}

test/tests.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def setUp(self):
1717
'111111')
1818
self.user3 = User.objects.create_user("test3", "[email protected]",
1919
'111111')
20+
print('\n%s.%s.%s' % (self.__class__.__module__,
21+
self.__class__.__name__,
22+
self._testMethodName))
2023

2124
def tearDown(self):
2225
self.model.objects.all().delete()
@@ -210,7 +213,9 @@ def test_vote_templatetag(self):
210213

211214
comment1 = comments[0]
212215
self.call_api('up', comment1, self.user1.pk)
213-
res = self.client.get('/comments/')
216+
# test with anonymous user
217+
self.client.get('/comments/')
218+
# test with authenticated user
214219
self.client.login(username=self.user1.username, password='111111')
215220
self.client.get('/comments/')
216221

@@ -220,8 +225,6 @@ def test_votemixin_api(self):
220225
content="I'm a comment")
221226
comment.save()
222227
self.assertEqual(comment.num_vote_up, 0)
223-
import pdb
224-
pdb.set_trace()
225228
self.client.login(
226229
username=self.user1.username, password='111111')
227230

test/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
router.register(r'comments', views.CommentViewSet)
77

88
urlpatterns = [
9-
path('comments', views.comments),
9+
path('comments/', views.comments),
1010
path('api/', include(router.urls)),
1111
]

vote/templatetags/vote.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from django import template
44
from django.contrib.auth.models import AnonymousUser
5-
from django import get_version
65

76
from vote.models import UP
87

@@ -11,9 +10,6 @@
1110

1211
@register.simple_tag
1312
def vote_exists(model, user=AnonymousUser(), action=UP):
14-
if get_version() >= '2.0':
15-
if user.is_anonymous:
16-
return False
17-
elif user.is_anonymous():
13+
if user.is_anonymous:
1814
return False
1915
return model.votes.exists(user.pk, action=action)

vote/views.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from django.db import IntegrityError
21
from rest_framework.decorators import action
3-
from rest_framework.views import APIView, Response
4-
from rest_framework.viewsets import ModelViewSet
2+
from rest_framework.views import Response
53

64
from vote.signals import post_voted
75

0 commit comments

Comments
 (0)