Skip to content

Commit

Permalink
测试travis
Browse files Browse the repository at this point in the history
  • Loading branch information
liangliangyy committed Feb 24, 2017
1 parent 3742457 commit d67206c
Show file tree
Hide file tree
Showing 11 changed files with 411 additions and 53 deletions.
36 changes: 36 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
language: python
python:
- "3.5"
- "3.6"
services:
- mysql
env:
global:
- DJANGO_SETTINGS_MODULE="test.travis_settings"
matrix:
- DJANGO="Django==1.8"
- DJANGO="Django==1.9"
- DJANGO="Django==1.10"
branches:
only:
- master
# command to install dependencies
install:
- pip install -r test/requirements.txt
- pip install "$DJANGO"
- pip install python-coveralls
- pip install coverage
before_script:
- mysql -e 'CREATE DATABASE `djangoblog` /*!40100 DEFAULT CHARACTER SET utf8 */;'
- python manage.py makemigrations accounts
- python manage.py makemigrations blog
- python manage.py makemigrations comments
- python manage.py makemigrations oauth
- python manage.py migrate
- python manage.py collectstatic --noinput
- python manage.py compress --force
# command to run tests
script:
- coverage run manage.py test
after_success:
- coveralls
4 changes: 2 additions & 2 deletions DjangoBlog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
url(r'', include('comments.urls', namespace='comment', app_name='comments')),
url(r'', include('accounts.urls', namespace='account', app_name='accounts')),
url(r'', include('oauth.urls', namespace='oauth', app_name='oauth')),
url(r'^sitemap\.xml$', cache_page(60 * 60 * 10)(sitemap), {'sitemaps': sitemaps},
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
url(r'^feed/$', cache_page(60 * 60 * 10)(DjangoBlogFeed())),
url(r'^feed/$', DjangoBlogFeed()),

url(r'^search', include('haystack.urls'), name='search'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
3 changes: 2 additions & 1 deletion accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def form_valid(self, form):

if form.is_valid():
from DjangoBlog.utils import cache
cache.clear()
if cache != None:
cache.clear()
auth.login(self.request, form.get_user())

return HttpResponseRedirect('/')
Expand Down
2 changes: 1 addition & 1 deletion blog/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import time
from ipware.ip import get_real_ip
from django.core.cache import cache
from DjangoBlog.utils import cache


class OnlineMiddleware(object):
Expand Down
2 changes: 1 addition & 1 deletion blog/templatetags/blog_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import urllib
from comments.models import Comment
from DjangoBlog.utils import cache_decorator, logger
from django.core.cache import cache
from DjangoBlog.utils import cache

register = template.Library()

Expand Down
43 changes: 42 additions & 1 deletion blog/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
from django.test import TestCase
from django.test import Client, RequestFactory, TestCase
from blog.models import Article, Category, Tag
from django.contrib.auth import get_user_model
from django.contrib.sites.models import Site
import datetime


# Create your tests here.

class ArticleTest(TestCase):
def setUp(self):
self.client = Client()
self.factory = RequestFactory()

def test_validate_article(self):
from accounts.models import BlogUser
site = Site.objects.get_current().domain
user = BlogUser()
user.email = "[email protected]"
user.username = "liangliangyy"
user.password = "liangliangyy"
user.save()
response = self.client.get(user.get_absolute_url())
self.assertEqual(response.status_code, 200)

category = Category()
category.name = "category"
category.created_time = datetime.datetime.now()
category.last_mod_time = datetime.datetime.now()
category.save()

response = self.client.get(category.get_absolute_url())
self.assertEqual(response.status_code, 200)

article = Article()
article.title = "nicetitle"
article.body = "nicecontent"
article.author = user
article.category = category
article.type = 'a'
article.status = 'p'
article.save()
response = self.client.get(article.get_absolute_url())
self.assertEqual(response.status_code, 200)
7 changes: 3 additions & 4 deletions blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,13 @@ def get_context_data(self, **kwargs):
articleid = int(self.kwargs[self.pk_url_kwarg])

comment_form = CommentForm()
u = self.request.user
user = self.request.user

if self.request.user.is_authenticated:
if user.is_authenticated and not user.is_anonymous and user.email and user.username:
comment_form.fields.update({
'email': forms.CharField(widget=forms.HiddenInput()),
'name': forms.CharField(widget=forms.HiddenInput()),
})
user = self.request.user
comment_form.fields["email"].initial = user.email
comment_form.fields["name"].initial = user.username

Expand Down Expand Up @@ -254,7 +253,7 @@ def refresh_memcache(request):

if request.user.is_superuser:
from DjangoBlog.utils import cache
cache.clear()
if cache != None: cache.clear()
return HttpResponse("ok")
else:
from django.http import HttpResponseForbidden
Expand Down
45 changes: 2 additions & 43 deletions comments/tests.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,3 @@
from django.test import Client, RequestFactory, TestCase
from blog.models import Article, Category, Tag
from django.contrib.auth import get_user_model
from django.contrib.sites.models import Site
import datetime
from django.test import TestCase


# Create your tests here.

class ArticleTest(TestCase):
def setUp(self):
self.client = Client()
self.factory = RequestFactory()

def test_validate_article(self):
from accounts.models import BlogUser
site = Site.objects.get_current().domain
user = BlogUser()
user.email = "[email protected]"
user.username = "liangliangyy"
user.password = "liangliangyy"
user.save()
response = self.client.get(user.get_absolute_url())
self.assertEqual(response.status_code, 200)

category = Category()
category.name = "category"
category.created_time = datetime.datetime.now()
category.last_mod_time = datetime.datetime.now()
category.save()

response = self.client.get(category.get_absolute_url())
self.assertEqual(response.status_code, 200)

article = Article()
article.title = "nicetitle"
article.body = "nicecontent"
article.author = user
article.category = category
article.type = 'a'
article.status = 'p'
article.save()
response = self.client.get(article.get_absolute_url())
self.assertEqual(response.status_code, 200)
# Create your tests here.
2 changes: 2 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import pymysql
pymysql.install_as_MySQLdb()
17 changes: 17 additions & 0 deletions test/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Django
django-autoslug
django-haystack
django-pagedown
django-uuslug
jieba
markdown2
Pillow
PyMySQL
python-slugify
requests
Unidecode
Whoosh
mistune
pygments
django-ipware
django_compressor
Loading

0 comments on commit d67206c

Please sign in to comment.