Skip to content

Commit

Permalink
7.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
codiebeulaine committed Dec 10, 2018
2 parents de2fdab + 94482b9 commit a6c364a
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 10 deletions.
10 changes: 9 additions & 1 deletion CHANGES.rst
@@ -1,10 +1,18 @@
CHANGES
=======

7.0.7
7.0.9
~~~~~~
- Bug: Add pre-delete for Tag to delete all article nav tags when tag deleted

7.0.8
~~~~~~
- Added testing documentation

7.0.7
~~~~~~
- Bug: Empty tags not saved in articles

7.0.6
~~~~~~
- Bug: Update copy_language to new Translations
Expand Down
11 changes: 4 additions & 7 deletions README.rst
Expand Up @@ -81,8 +81,7 @@ is read by the generated package's ``setup.py`` file.

Multiple requires can be specified on the command line::

$ molo scaffold myapp --require=django-contrib-comments \
> --require=molo.profiles
$ molo scaffold myapp --require=django-contrib-comments

Automatically adding installed apps
-----------------------------------
Expand All @@ -106,7 +105,6 @@ This results in the following ``urls.py`` entry::
For convenience, here's the full scaffold command for the current plugins::

$ molo scaffold myapp \
--require=molo.profiles --include=molo.profiles ^profiles/ \
--require=django-contrib-comments --include=django_comments ^comments/ \
--require=molo.commenting --include=molo.commenting ^commenting/ \
--require=molo.yourwords --include=molo.yourwords ^yourwords/
Expand All @@ -132,9 +130,7 @@ some amount of customization. Use the ``unpack-templates`` command in the
scaffolded application to unpack a package's templates in your application's
templates directory::

$ molo scaffold testapp \
> --require=molo.profiles \
> --include=molo.profiles ^profiles/
$ molo scaffold testapp
$ pip install -e testapp
...

Expand All @@ -155,14 +151,15 @@ The format is::

$ molo unpack-templates <source package> <target package>

Writing tests
Running tests
~~~~~~~~~~~~~

Now develop your application and write tests for the features you add.
Running your tests for Django works as you would expect::

$ ./manage.py test


What is bundled with Molo?
--------------------------

Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
7.0.7
7.0.9
1 change: 1 addition & 0 deletions docs/index.rst
Expand Up @@ -26,6 +26,7 @@ Contents
merged-cms
template-tags
template-patterns
testing
plugins
release-notes

Expand Down
76 changes: 76 additions & 0 deletions docs/testing.rst
@@ -0,0 +1,76 @@
Writing Test Cases
~~~~~~~~~~~~~~~~~~

Use Molo test mixin `molo.core.tests.base.MoloTestCaseMixin`

The Molo test mixin contains helper methods to generate test content necessary for the main sight.

::

class MyTest(MoloTestCaseMixin, TestCase):

def setUp(self):
self.mk_main()
main = Main.objects.all().first()
lang = Languages.for_site(main.get_site()
self.english = SiteLanguageRelation.objects.create(
language_setting=lang), locale='en', is_active=True)

self.user = User.objects.create_user(
'test', 'test@example.org', 'test')

self.client = Client()
...

def test_register_auto_login(self):
# Not logged in, redirects to login page
login_url = reverse('molo.profiles:edit_my_profile')
expected_url = '/login/?next=/profiles/edit/myprofile/'

response = self.client.get(login_url)
self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'], expected_url)


`MoloTestCaseMixin` methods

* login()

Creates a superuser and logs in
username='superuser', email='superuser@email.com', password='pass'

* mk_root()

Creates a root page accessible on the application application root url

* mk_main(title='Main', slug='main'), mk_main2(title='main2', slug='main2', path='4098')

Create the main page of your molo test site

* mk_tag(parent, slug=None, \**kwargs), mk_tags(parent, count=2, \**kwargs)

Attach/add tag to parent page

* mk_reaction_question(parent, article, \**kwargs)

Create test reaction question for an article

* mk_sections(parent, count=2, \**kwargs), mk_section(parent \**kwargs)

Create test section(s) page content in parent page

* mk_articles(parent, count=2, \**kwargs), mk_article(parent, \**kwargs)

Create test article(s) page content in parent page

* mk_banners(parent, count=2, \**kwargs), mk_banner(parent, \**kwargs)

Create test banner(s) page content in parent page

* mk_translation(source, language, translation)
mk_section_translation(source, language, \**kwargs)
mk_article_translation(source, language, \**kwargs)
mk_tag_translation(source, language, \**kwargs)
mk_reaction_translation(source, language, \**kwargs)

Create a translated version of the source (Page)
22 changes: 22 additions & 0 deletions molo/core/models.py
Expand Up @@ -54,6 +54,8 @@
get_image_hash
)

from django.db.models.signals import pre_delete


class BaseReadOnlyPanel(EditHandler):
def render(self):
Expand Down Expand Up @@ -890,6 +892,20 @@ class Tag(TranslatablePageMixin, MoloPage, ImportableMixin):
]


@receiver(pre_delete, sender=Tag)
def delete_tag(sender, instance, **kwargs):
nav_tags = ArticlePageTags.objects.filter(tag=instance)
if not nav_tags:
return
for nav_tag in nav_tags:
page = nav_tag.page
nav_tag.delete()
if page.live:
page.save_revision().publish()
else:
page.save()


class BannerIndexPage(MoloPage, PreventDeleteMixin, ImportableMixin):
parent_page_types = []
subpage_types = ['BannerPage']
Expand Down Expand Up @@ -1738,6 +1754,12 @@ class ArticlePageTags(Orderable):
panels = [PageChooserPanel('tag', 'core.Tag')]
api_fields = ['tag']

def save(self, *args, **kwargs):
if (self.tag is None):
return
else:
super(ArticlePageTags, self).save(*args, **kwargs)


class ArticlePageReactionQuestions(Orderable):
page = ParentalKey(ArticlePage, related_name='reaction_questions')
Expand Down
35 changes: 34 additions & 1 deletion molo/core/tests/test_models.py
Expand Up @@ -15,7 +15,7 @@
ArticlePage, CmsSettings, Main,
SiteLanguageRelation, Languages, SectionIndexPage, FooterIndexPage,
BannerIndexPage, TagIndexPage, BannerPage, ReactionQuestionIndexPage,
Timezone,
Timezone, Tag, ArticlePageTags
)
from molo.core import constants
from molo.core.templatetags.core_tags import (
Expand Down Expand Up @@ -456,6 +456,39 @@ def test_meta_data_tags(self):
ArticlePage.objects.filter(
metadata_tags__name='peace').count(), 1)

def test_nav_tag_delete_updates_article(self):
"""
ArticlePageTags with no tags should not be saved
"""
tag_index = TagIndexPage.objects.child_of(self.main).first()
article = self.mk_article(
parent=self.yourmind, title='first_main_article')

article2 = self.mk_article(
parent=self.yourmind, title='second_main_article')
tag = Tag(title='New tag')
tag2 = Tag(title='Another New tag')
tag_index.add_child(instance=tag)
tag.save_revision().publish()
tag_index.add_child(instance=tag2)
tag2.save_revision().publish()

article.nav_tags.create(tag=tag)
article.save()

article2.nav_tags.create(tag=tag)
article2.nav_tags.create(tag=tag2)
article2.save()
self.assertEqual(article.nav_tags.get(tag=tag).tag,
article2.nav_tags.get(tag=tag).tag,
)
# delete the tag
tag.delete()
# test the nav_tags are deleted and removed from the articles
self.assertEqual(ArticlePageTags.objects.count(), 1)
self.assertFalse(article.nav_tags.filter(pk=1).exists())
self.assertTrue(article2.nav_tags.get(), tag2)

def test_social_media(self):

User.objects.create_superuser(
Expand Down
21 changes: 21 additions & 0 deletions molo/core/tests/test_search.py
Expand Up @@ -106,6 +106,27 @@ def test_search(self):
response = self.client.get(reverse('search'))
self.assertContains(response, 'No search results for None')

def test_search_empty_values(self):
self.backend = get_search_backend('default')
self.backend.reset_index()

self.mk_article(
self.english_section, title="Site 1 article")
self.mk_article(
self.yourmind2, title="Site 2 article")
self.backend.refresh_index()

response = self.client.get(reverse('search'), {
'q': ' '
})
self.assertEqual(response.status_code, 200)

response = self.client.get(reverse('search'), {
'q': ' article '
})
self.assertContains(response, 'Site 1 article')
self.assertNotContains(response, 'Site 2 article')

def test_search_works_with_multisite(self):
self.backend = get_search_backend('default')
self.backend.reset_index()
Expand Down
1 change: 1 addition & 0 deletions molo/core/views.py
Expand Up @@ -50,6 +50,7 @@ def csrf_failure(request, reason=""):

def search(request, results_per_page=10, load_more=False):
search_query = request.GET.get('q', None)
search_query = search_query.strip() if search_query else search_query
page = request.GET.get('p', 1)
locale = get_locale_code(get_language_from_request(request))

Expand Down

0 comments on commit a6c364a

Please sign in to comment.