Test refactoring
This commit is contained in:
parent
a35fc201e8
commit
0f16e4e2db
4 changed files with 94 additions and 101 deletions
|
|
@ -71,8 +71,8 @@ class ModelsTest(BaseTest):
|
|||
})
|
||||
|
||||
def test_manager(self):
|
||||
post_1 = self._get_post(self.data['en'][0])
|
||||
post_2 = self._get_post(self.data['en'][1])
|
||||
post1 = self._get_post(self.data['en'][0])
|
||||
post2 = self._get_post(self.data['en'][1])
|
||||
|
||||
# default queryset, published and unpublished posts
|
||||
months = Post.objects.get_months()
|
||||
|
|
@ -81,8 +81,8 @@ class ModelsTest(BaseTest):
|
|||
self.assertEqual(data['count'], 2)
|
||||
|
||||
# custom queryset, only published
|
||||
post_1.publish = True
|
||||
post_1.save()
|
||||
post1.publish = True
|
||||
post1.save()
|
||||
months = Post.objects.get_months(Post.objects.published())
|
||||
for data in months:
|
||||
self.assertEqual(data['date'], date(year=date.today().year, month=date.today().month, day=1))
|
||||
|
|
@ -91,23 +91,23 @@ class ModelsTest(BaseTest):
|
|||
self.assertEqual(len(Post.objects.available()), 1)
|
||||
|
||||
# If post is published but publishing date is in the future
|
||||
post_2.date_published = date(year=date.today().year+1, month=date.today().month, day=1)
|
||||
post_2.publish = True
|
||||
post_2.save()
|
||||
post2.date_published = date(year=date.today().year+1, month=date.today().month, day=1)
|
||||
post2.publish = True
|
||||
post2.save()
|
||||
self.assertEqual(len(Post.objects.available()), 2)
|
||||
self.assertEqual(len(Post.objects.published()), 1)
|
||||
self.assertEqual(len(Post.objects.archived()), 0)
|
||||
|
||||
# If post is published but end publishing date is in the past
|
||||
post_2.date_published = date(year=date.today().year-2, month=date.today().month, day=1)
|
||||
post_2.date_published_end = date(year=date.today().year-1, month=date.today().month, day=1)
|
||||
post_2.save()
|
||||
post2.date_published = date(year=date.today().year-2, month=date.today().month, day=1)
|
||||
post2.date_published_end = date(year=date.today().year-1, month=date.today().month, day=1)
|
||||
post2.save()
|
||||
self.assertEqual(len(Post.objects.available()), 2)
|
||||
self.assertEqual(len(Post.objects.published()), 1)
|
||||
self.assertEqual(len(Post.objects.archived()), 1)
|
||||
|
||||
# counting with language fallback enabled
|
||||
post = self._get_post(self.data['it'][0], post_1, 'it')
|
||||
post = self._get_post(self.data['it'][0], post1, 'it')
|
||||
self.assertEqual(len(Post.objects.filter_by_language('it')), 2)
|
||||
|
||||
# No fallback
|
||||
|
|
@ -116,12 +116,12 @@ class ModelsTest(BaseTest):
|
|||
parler.appsettings.PARLER_LANGUAGES['default']['hide_untranslated'] = False
|
||||
|
||||
def test_tag_cloud(self):
|
||||
post_1 = self._get_post(self.data['en'][0])
|
||||
post_2 = self._get_post(self.data['en'][1])
|
||||
post_1.tags.add('tag 1', 'tag 2', 'tag 3', 'tag 4')
|
||||
post_1.save()
|
||||
post_2.tags.add('tag 6', 'tag 2', 'tag 5', 'tag 8')
|
||||
post_2.save()
|
||||
post1 = self._get_post(self.data['en'][0])
|
||||
post2 = self._get_post(self.data['en'][1])
|
||||
post1.tags.add('tag 1', 'tag 2', 'tag 3', 'tag 4')
|
||||
post1.save()
|
||||
post2.tags.add('tag 6', 'tag 2', 'tag 5', 'tag 8')
|
||||
post2.save()
|
||||
|
||||
self.assertEqual(len(Post.objects.tag_cloud()), 0)
|
||||
|
||||
|
|
@ -145,59 +145,59 @@ class ModelsTest(BaseTest):
|
|||
tag.count = 1
|
||||
tags_1.append(tag)
|
||||
|
||||
post_1.publish = True
|
||||
post_1.save()
|
||||
post1.publish = True
|
||||
post1.save()
|
||||
self.assertEqual(set(Post.objects.tag_cloud()), set(tags_1))
|
||||
self.assertEqual(set(Post.objects.tag_cloud(published=False)), set(tags))
|
||||
|
||||
def test_plugin_latest(self):
|
||||
post_1 = self._get_post(self.data['en'][0])
|
||||
post_2 = self._get_post(self.data['en'][1])
|
||||
post_1.tags.add('tag 1')
|
||||
post_1.save()
|
||||
plugin = add_plugin(post_1.content, 'BlogLatestEntriesPlugin', language='en')
|
||||
post1 = self._get_post(self.data['en'][0])
|
||||
post2 = self._get_post(self.data['en'][1])
|
||||
post1.tags.add('tag 1')
|
||||
post1.save()
|
||||
plugin = add_plugin(post1.content, 'BlogLatestEntriesPlugin', language='en')
|
||||
tag = Tag.objects.get(slug='tag-1')
|
||||
plugin.tags.add(tag)
|
||||
self.assertEqual(len(plugin.get_posts()), 0)
|
||||
post_1.publish = True
|
||||
post_1.save()
|
||||
post1.publish = True
|
||||
post1.save()
|
||||
self.assertEqual(len(plugin.get_posts()), 1)
|
||||
|
||||
def test_copy_plugin_latest(self):
|
||||
post_1 = self._get_post(self.data['en'][0])
|
||||
post_2 = self._get_post(self.data['en'][1])
|
||||
post1 = self._get_post(self.data['en'][0])
|
||||
post2 = self._get_post(self.data['en'][1])
|
||||
tag = Tag.objects.create(name='tag 1')
|
||||
plugin = add_plugin(post_1.content, 'BlogLatestEntriesPlugin', language='en')
|
||||
plugin = add_plugin(post1.content, 'BlogLatestEntriesPlugin', language='en')
|
||||
plugin.tags.add(tag)
|
||||
plugins = list(post_1.content.cmsplugin_set.filter(language='en').order_by('tree_id', 'level', 'position'))
|
||||
copy_plugins_to(plugins, post_2.content)
|
||||
new = downcast_plugins(post_2.content.cmsplugin_set.all())
|
||||
plugins = list(post1.content.cmsplugin_set.filter(language='en').order_by('tree_id', 'level', 'position'))
|
||||
copy_plugins_to(plugins, post2.content)
|
||||
new = downcast_plugins(post2.content.cmsplugin_set.all())
|
||||
self.assertEqual(set(new[0].tags.all()), set([tag]))
|
||||
|
||||
def test_plugin_author(self):
|
||||
post_1 = self._get_post(self.data['en'][0])
|
||||
post_2 = self._get_post(self.data['en'][1])
|
||||
plugin = add_plugin(post_1.content, 'BlogAuthorPostsPlugin', language='en')
|
||||
post1 = self._get_post(self.data['en'][0])
|
||||
post2 = self._get_post(self.data['en'][1])
|
||||
plugin = add_plugin(post1.content, 'BlogAuthorPostsPlugin', language='en')
|
||||
plugin.authors.add(self.user)
|
||||
self.assertEqual(len(plugin.get_posts()), 0)
|
||||
self.assertEqual(plugin.get_authors()[0].count, 0)
|
||||
|
||||
post_1.publish = True
|
||||
post_1.save()
|
||||
post1.publish = True
|
||||
post1.save()
|
||||
self.assertEqual(len(plugin.get_posts()), 1)
|
||||
self.assertEqual(plugin.get_authors()[0].count, 1)
|
||||
|
||||
post_2.publish = True
|
||||
post_2.save()
|
||||
post2.publish = True
|
||||
post2.save()
|
||||
self.assertEqual(len(plugin.get_posts()), 2)
|
||||
self.assertEqual(plugin.get_authors()[0].count, 2)
|
||||
|
||||
def test_copy_plugin_author(self):
|
||||
post_1 = self._get_post(self.data['en'][0])
|
||||
post_2 = self._get_post(self.data['en'][1])
|
||||
plugin = add_plugin(post_1.content, 'BlogAuthorPostsPlugin', language='en')
|
||||
post1 = self._get_post(self.data['en'][0])
|
||||
post2 = self._get_post(self.data['en'][1])
|
||||
plugin = add_plugin(post1.content, 'BlogAuthorPostsPlugin', language='en')
|
||||
plugin.authors.add(self.user)
|
||||
plugins = list(post_1.content.cmsplugin_set.filter(language='en').order_by('tree_id', 'level', 'position'))
|
||||
copy_plugins_to(plugins, post_2.content)
|
||||
new = downcast_plugins(post_2.content.cmsplugin_set.all())
|
||||
plugins = list(post1.content.cmsplugin_set.filter(language='en').order_by('tree_id', 'level', 'position'))
|
||||
copy_plugins_to(plugins, post2.content)
|
||||
new = downcast_plugins(post2.content.cmsplugin_set.all())
|
||||
self.assertEqual(set(new[0].authors.all()), set([self.user]))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue