Skip to content

Commit

Permalink
fixed tests and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Lorenz committed Feb 19, 2013
1 parent 58b7d2a commit 1044ab1
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 22 deletions.
Expand Up @@ -9,8 +9,13 @@


@register.assignment_tag
def get_category(entry):
return EntryCategory.objects.get(entry=entry).category
def get_category(entry=None):
if entry:
try:
return EntryCategory.objects.get(entry=entry).category
except EntryCategory.DoesNotExist:
pass
return None


@register.inclusion_tag(
Expand Down
21 changes: 21 additions & 0 deletions cmsplugin_blog_categories/tests/cmsplugin_tests.py
@@ -0,0 +1,21 @@
"""Tests for models of the ``cmsplugin_blog_categories``` application."""
from django.test import TestCase

from cmsplugin_blog_categories.cms_plugins import CMSCategoryPlugin
from cmsplugin_blog_categories.tests.factories import CategoryPluginFactory


class CMSCategoryPluginTestCase(TestCase):
"""Tests for the ``CMSCategoryPlugin`` cmsplugin."""
longMessage = True

def setUp(self):
self.plugin = CategoryPluginFactory()
self.cmsplugin = CMSCategoryPlugin()

def test_render(self):
self.assertEqual(
self.cmsplugin.render(context={}, instance=self.plugin,
placeholder=None),
{'category': self.plugin.category, 'category_entries': [],
'placeholder': None})
18 changes: 16 additions & 2 deletions cmsplugin_blog_categories/tests/factories.py
Expand Up @@ -25,7 +25,21 @@ class CategoryTitleFactoryBase(factory.Factory):

class CategoryTitleENFactory(CategoryTitleFactoryBase):
"""Factory for english ``CategoryTitle`` objects."""
title = factory.LazyAttribute(lambda a: 'title-{0}'.format(a))
title = 'Category Title'
language = 'en-us'


class CategoryTitleCNFactory(CategoryTitleFactoryBase):
"""Factory for chinese ``CategoryTitle`` objects."""
title = unichr(34900)
language = 'zh-cn'


class CategoryPluginFactory(factory.Factory):
"""Base factory for factories for ``CategoryPlugin`` models."""
FACTORY_FOR = models.CategoryPlugin

category = factory.SubFactory(CategoryFactory)


class EntryFactory(factory.Factory):
Expand All @@ -46,5 +60,5 @@ class EntryCategoryFactory(factory.Factory):
"""Base factory for factories for ``EntryCategory`` models."""
FACTORY_FOR = models.EntryCategory

category = factory.SubFactory(CategoryTitleENFactory)
category = factory.SubFactory(CategoryFactory)
entry = factory.SubFactory(EntryFactory)
Expand Up @@ -3,14 +3,18 @@

from django_libs.tests.mixins import ViewTestMixin

from cmsplugin_blog_categories.tests.factories import CategoryTitleENFactory
from cmsplugin_blog_categories.tests.factories import (
CategoryTitleENFactory,
EntryFactory,
)


class CategoryListViewTestCase(ViewTestMixin, TestCase):
"""Tests for the ``CategoryListView`` generic view class."""
def setUp(self):
self.category_title = CategoryTitleENFactory()
self.category = self.category_title.category
self.entry = EntryFactory()

def get_view_name(self):
return 'blog_archive_category'
Expand All @@ -19,4 +23,4 @@ def get_view_kwargs(self):
return {'category': self.category.slug}

def test_view(self):
pass
self.should_be_callable_when_anonymous()
22 changes: 18 additions & 4 deletions cmsplugin_blog_categories/tests/models_tests.py
Expand Up @@ -3,6 +3,7 @@

from cmsplugin_blog_categories.tests.factories import (
CategoryFactory,
CategoryTitleCNFactory,
CategoryTitleENFactory,
EntryCategoryFactory,
EntryFactory,
Expand All @@ -19,10 +20,23 @@ def setUp(self):
def test_model(self):
self.assertTrue(self.obj.pk)

def test_translation(self):
self.assertFalse(self.obj.get_translation())
CategoryTitleENFactory(enquiry=self.obj)
self.assertEqual(self.obj.get_translation().title, 'A question?')
def test_get_title(self):
self.assertEqual(self.obj.get_title(), 'None')
CategoryTitleENFactory(category=self.obj)
self.assertEqual(self.obj.get_title(), 'Category Title')


class CategoryTitleTestCase(TestCase):
"""Tests for the ``CategoryTitle`` model class."""
longMessage = True

def setUp(self):
self.obj_en = CategoryTitleENFactory()
self.obj_cn = CategoryTitleCNFactory()

def test_model(self):
self.assertTrue(self.obj_en.pk)
self.assertTrue(self.obj_cn.pk)


class EntryTestCase(TestCase):
Expand Down
41 changes: 41 additions & 0 deletions cmsplugin_blog_categories/tests/tags_tests.py
@@ -0,0 +1,41 @@
"""Tests for tags of the ``cmsplugin_blog_categories``` application."""
from django.test import TestCase

from cmsplugin_blog_categories.templatetags import (
cmsplugin_blog_categories_tags as tags,
)
from cmsplugin_blog_categories.tests.factories import (
CategoryFactory,
EntryFactory,
EntryCategoryFactory,
)


class GetCategoryTestCase(TestCase):
"""Tests for the ``get_category`` tag."""
longMessage = True

def setUp(self):
self.entry = EntryFactory()
self.category = EntryCategoryFactory()

def test_tag(self):
self.assertFalse(tags.get_category())
self.assertFalse(tags.get_category(self.entry))
self.assertEqual(tags.get_category(self.category.entry),
self.category.category)


class RenderCategoryLinksTestCase(TestCase):
"""Tests for the ``render_category_links`` tag."""
longMessage = True

def setUp(self):
self.entry_category = EntryCategoryFactory()
self.category = CategoryFactory()

def test_tag(self):
self.assertEqual(tags.render_category_links({}).get('categories')[0],
self.entry_category.category)
self.assertEqual(
tags.render_category_links({}, True).get('categories').count(), 1)
26 changes: 14 additions & 12 deletions cmsplugin_blog_categories/tests/test_settings.py
Expand Up @@ -28,14 +28,6 @@
os.path.join(os.path.dirname(__file__), '../templates'),
)

COVERAGE_REPORT_HTML_OUTPUT_DIR = os.path.join(
os.path.dirname(__file__), 'coverage')

COVERAGE_MODULE_EXCLUDES = [
'tests$', 'settings$', 'urls$', 'locale$',
'migrations', 'fixtures', 'admin$', 'django_extensions',
]

# Settings needed to test a multilingual blog
LANGUAGE_CODE = 'en-us'
LANGUAGES = [
Expand Down Expand Up @@ -65,29 +57,39 @@
'django.contrib.sites',

# cms related apps
'cms',
'sekizai',
'mptt',
'menus',
'cms.plugins.text',

# blog related apps
'cmsplugin_blog',
'djangocms_utils',
'simple_translation',
'tagging',
'missing',
]

COVERAGE_APPS = [
# Needed to include cmsplugin_blog_categories, due to their relations
'cms',
'cmsplugin_blog',
]

INTERNAL_APPS = [
'django_nose',
'cmsplugin_blog_categories.tests.test_app',
'cmsplugin_blog_categories',
]

INSTALLED_APPS = EXTERNAL_APPS + INTERNAL_APPS
INSTALLED_APPS = EXTERNAL_APPS + INTERNAL_APPS + COVERAGE_APPS

COVERAGE_MODULE_EXCLUDES += EXTERNAL_APPS
COVERAGE_REPORT_HTML_OUTPUT_DIR = os.path.join(
os.path.dirname(__file__), 'coverage')

COVERAGE_MODULE_EXCLUDES = EXTERNAL_APPS + [
'tests$', 'settings$', 'urls$', 'locale$',
'migrations', 'fixtures', 'admin$', 'django_extensions',
]

MIDDLEWARE_CLASSES = [
'django.middleware.common.CommonMiddleware',
Expand Down

0 comments on commit 1044ab1

Please sign in to comment.