Skip to content

Commit

Permalink
added the tests for commenting settings and removed the getter
Browse files Browse the repository at this point in the history
  • Loading branch information
sewagodimo committed Feb 28, 2018
1 parent c419179 commit 5b8c313
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-02-27 08:33
# Generated by Django 1.11.10 on 2018-02-28 15:15
from __future__ import unicode_literals

from django.db import migrations, models
Expand Down
7 changes: 0 additions & 7 deletions molo/commenting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,3 @@ class CommentingSettings(BaseSetting):
],
heading="Site Commenting Settings", )
]

def get_anonymous_commenting_alias(self):
"""Return the alias assigned to anonymous comments."""
if(self.commenting_anonymous == "" or
self.commenting_anonymous == "Anonymous"):
return "Anonymous"
return self.commenting_anonymous
2 changes: 1 addition & 1 deletion molo/commenting/templates/comments/comment.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h4 class="comment__author">
{{node.user_name}}
{% else %}
{% if not node.user.profile.alias %}
{{self.get_anonymous_commenting_alias}}
{% trans settings.commenting.CommentingSettings.commenting_anonymous%}
{% else %}
{{node.user.profile.alias}}
{% endif %}
Expand Down
60 changes: 43 additions & 17 deletions molo/commenting/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.contrib.sites.models import Site
from django.test import TestCase
from django.utils import timezone
from django.core.urlresolvers import reverse

from molo.commenting.models import MoloComment, CommentingSettings
from django_comments.models import CommentFlag
Expand Down Expand Up @@ -130,20 +131,45 @@ def test_auto_remove_for_non_remove_flag(self):
class CommentingSettingsTest(TestCase, MoloTestCaseMixin):
"""Test if the commengting settings valued are set properly."""

named_comment = CommentingSettings(commenting_anonymous="Little Sister")
empty_comment = CommentingSettings(commenting_anonymous="")
default_comment = CommentingSettings()

def test_get_anonymous_commenting_alias(self):
print(self.named_comment.get_anonymous_commenting_alias())
print(self.empty_comment.get_anonymous_commenting_alias())
print(self.default_comment.get_anonymous_commenting_alias())
self.assertTrue(
self.named_comment.get_anonymous_commenting_alias() ==
"Little Sister")
self.assertTrue(
self.empty_comment.get_anonymous_commenting_alias() ==
"Anonymous")
self.assertTrue(
self.default_comment.get_anonymous_commenting_alias() ==
"Anonymous")
def setUp(self):
self.mk_main()
self.main = Main.objects.all().first()
self.language_setting = Languages.objects.create(
site_id=self.main.get_site().pk)
self.english = SiteLanguageRelation.objects.create(
language_setting=self.language_setting,
locale='en',
is_active=True)
self.user = User.objects.create_user(
'test', 'test@example.org', 'test')
self.content_type = ContentType.objects.get_for_model(self.user)

self.yourmind = self.mk_section(
self.section_index, title='Your mind')
self.article1 = self.mk_article(
title='article 1', slug='article-2', parent=self.yourmind)
self.setting = CommentingSettings.for_site(self.site)

def test_get_comments_anonymous(self):
article = self.article1
MoloComment.objects.create(
content_object=article, object_pk=article.id,
content_type=ContentType.objects.get_for_model(article),
site=Site.objects.get_current(), user=self.user,
comment='This is a comment, you dig?', submit_date=timezone.now())
response = self.client.get(
reverse('molo.commenting:more-comments', args=(article.pk,)))
self.assertContains(response, "Anonymous")

def test_get_comments_anonymous_alias(self):
self.setting.commenting_anonymous = "Little Sister"
self.setting.save()
article = self.article1
MoloComment.objects.create(
content_object=article, object_pk=article.id,
content_type=ContentType.objects.get_for_model(article),
site=Site.objects.get_current(), user=self.user,
comment='This is another comment', submit_date=timezone.now())
response = self.client.get(
reverse('molo.commenting:more-comments', args=(article.pk,)))
self.assertContains(response, "Little Sister")

0 comments on commit 5b8c313

Please sign in to comment.