Skip to content

Commit

Permalink
Work on PEP8 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyontour committed Jun 15, 2015
1 parent 3ff603b commit c4ade2d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 39 deletions.
2 changes: 1 addition & 1 deletion articles/templatetags/article_tags.py
@@ -1,8 +1,8 @@
from django import template
from django.template import loader, Context, Library

register = template.Library()


@register.inclusion_tag('articles/inclusion/tag_list.html')
def tag_list(tags):
return {
Expand Down
48 changes: 19 additions & 29 deletions articles/tests/test_articles.py
@@ -1,9 +1,9 @@
"""
Tests for Articles
"""
import datetime, os
import os
from django.test import TestCase
from articles.models import Article, ArticleTag
from articles.models import ArticleTag
from django.contrib.auth.models import User
from articles.views import _get_images_in_text
from django.core.urlresolvers import reverse
Expand All @@ -20,11 +20,11 @@ def setUp(self):
def create_articles(self, number_of_articles=1, published=True):
self.client.login(username="testuser", password="testuser")
for i in range(1, number_of_articles + 1):
response = self.client.post('/articles/new',
self.client.post('/articles/new',
{
'title': 'New article %d title' % i,
'body': 'New article %d body' % i,
'published' : published
'published': published
})
self.client.logout()

Expand All @@ -47,7 +47,7 @@ def test_create_article(self):
self.assertContains(response, 'New article')
self.assertContains(response, 'New article body')
self.assertTrue('article' in response.context)
self.assertTrue(response.context['article'].published == False)
self.assertTrue(response.context['article'].published is False)
self.assertTrue(str(response.context['article']) == 'New article')

response = self.client.get('/articles/new-article')
Expand All @@ -61,7 +61,7 @@ def test_create_article_with_images(self):
{
'title': 'New article title',
'body': 'With {image:1} and {image:2} so there.',
'published' : True,
'published': True,
})

# Create an image
Expand Down Expand Up @@ -197,7 +197,6 @@ def test_update_article(self):
self.assertContains(response, 'Updated title')
self.assertContains(response, 'New article body updated')


def test_update_article_not_logged_in(self):
self.client.login(username="testuser", password="testuser")

Expand Down Expand Up @@ -242,12 +241,11 @@ def test_delete_article(self):

# Delete article
response = self.client.post('/articles/new-article-2-title/delete',
{
},
{},
follow=True)

response = self.client.get('/articles/new-article-2-title')

self.assertTrue(response.status_code == 404, msg="Expectec 404, got %d" % response.status_code)
response = self.client.get('/articles/new-article-1-title')
self.assertTrue(response.status_code == 200)
Expand Down Expand Up @@ -296,7 +294,7 @@ def test_retrieve_published_article_not_logged_in(self):
{
'title': 'New article title',
'body': 'New article body',
'published' : True
'published': True
},
follow=True)
self.client.logout()
Expand Down Expand Up @@ -387,7 +385,7 @@ def test_create_page(self):
self.assertContains(response, 'New page')
self.assertContains(response, 'New page body')
self.assertTrue('page' in response.context)
self.assertTrue(response.context['page'].published == True)
self.assertTrue(response.context['page'].published is True)
self.assertTrue(str(response.context['page']) == 'New page')

response = self.client.get('/articles/new-page')
Expand Down Expand Up @@ -420,11 +418,10 @@ def test_page_list(self):
self.assertTrue(len(response.context['articles']) == 2)
self.assertTemplateUsed('articles/article_list.html')


def test_home_page(self):
self.create_articles(number_of_articles=10)
response = self.client.get('/')
self.client.get('/')

def test_home_page_article(self):
self.create_articles(number_of_articles=10)
self.client.login(username="testuser", password="testuser")
Expand Down Expand Up @@ -502,7 +499,7 @@ def test_text_parsing_for_images_4(self):
self.assertEquals(_get_images_in_text('''
Blah blah
{image:12}
{image:23}{image:45}'''), [12,23,45])
{image:23}{image:45}'''), [12, 23, 45])


class ArticleTagsTest(TestCase):
Expand Down Expand Up @@ -700,10 +697,10 @@ def test_popular_tags(self):
self.client.login(username="testuser", password="testuser")

tags = {
'taga': 0,
'tagb': 0,
'tagc': 0,
'tagd': 0,
'taga': 0,
'tagb': 0,
'tagc': 0,
'tagd': 0,
}
for i in range(1, 10):
text = 'taga'
Expand All @@ -726,16 +723,9 @@ def test_popular_tags(self):
},
follow=True)

#print ArticleTag.objects.all()
#print tags

# for tag in ArticleTag.objects.all():
# print tag.title, tag.article_set.count()

response = self.client.get('/articles/')
for t in response.context['popular_tags']:
if t['tag'].title in tags and t['count'] == tags[t['tag'].title]:
del tags[t['tag'].title]
del tags[t['tag'].title]

self.assertTrue(tags == {}, msg=str(tags))

4 changes: 0 additions & 4 deletions config/settings/base.py
Expand Up @@ -163,10 +163,6 @@
)

CACHES = {
#'default': {
# 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
# 'LOCATION': '127.0.0.1:11211',
# },
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': os.path.join(BASE_DIR, 'cache'),
Expand Down
5 changes: 2 additions & 3 deletions config/settings/live.py
Expand Up @@ -4,11 +4,10 @@

DATABASES = {
'default': {
#'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'ENGINE': 'mysql.connector.django', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': os.environ.get('DB_NAME'), # Or path to database file if using sqlite3.
'NAME': os.environ.get('DB_NAME'), # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': os.environ.get('DB_USER'),
'USER': os.environ.get('DB_USER'),
'PASSWORD': os.environ.get('DB_PASS'),
'HOST': os.environ.get('DB_HOST', ''), # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
Expand Down
4 changes: 2 additions & 2 deletions config/settings/test.py
Expand Up @@ -5,9 +5,9 @@
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': os.environ.get('DB_NAME'), # Or path to database file if using sqlite3.
'NAME': os.environ.get('DB_NAME'), # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': os.environ.get('DB_USER'),
'USER': os.environ.get('DB_USER'),
'PASSWORD': os.environ.get('DB_PASS'),
'HOST': os.environ.get('DB_HOST', ''), # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
Expand Down
1 change: 1 addition & 0 deletions tox.ini
@@ -1,5 +1,6 @@
[flake8]
;ignore = E226,E302,E41
ignore = E128,E241
max-line-length = 160
exclude = */tests.py
;max-complexity = 10

0 comments on commit c4ade2d

Please sign in to comment.