<s> from __future__ import unicode_literals <EOL> import time <EOL> import datetime <EOL> import pytz <EOL> from django . core . cache import cache <EOL> from django . core . urlresolvers import reverse <EOL> from django . utils . translation import force_text , override <EOL> from aldryn_newsblog . models import NewsBlogConfig <EOL> from cms import api <EOL> from cms . models import StaticPlaceholder <EOL> from . import NewsBlogTestCase <EOL> class TestAppConfigPluginsBase ( NewsBlogTestCase ) : <EOL> plugin_to_test = '<STR_LIT>' <EOL> plugin_params = { } <EOL> def setUp ( self ) : <EOL> super ( TestAppConfigPluginsBase , self ) . setUp ( ) <EOL> self . placeholder = self . plugin_page . placeholders . all ( ) [ <NUM_LIT:0> ] <EOL> api . add_plugin ( <EOL> self . placeholder , self . plugin_to_test , self . language , <EOL> app_config = self . app_config , ** self . plugin_params ) <EOL> self . plugin = self . placeholder . get_plugins ( ) [ <NUM_LIT:0> ] . get_plugin_instance ( ) [ <NUM_LIT:0> ] <EOL> self . plugin . save ( ) <EOL> self . plugin_page . publish ( self . language ) <EOL> self . another_app_config = NewsBlogConfig . objects . create ( <EOL> namespace = self . rand_str ( ) ) <EOL> class TestPluginLanguageHelperMixin ( object ) : <EOL> def _test_plugin_languages_with_article ( self , article ) : <EOL> """<STR_LIT>""" <EOL> title_de = '<STR_LIT>' <EOL> title_en = article . title <EOL> article . set_current_language ( '<STR_LIT>' ) <EOL> article . title = title_de <EOL> article . save ( ) <EOL> self . page . unpublish ( '<STR_LIT>' ) <EOL> cache . clear ( ) <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> self . assertNotContains ( response , title_en ) <EOL> class TestArchivePlugin ( TestAppConfigPluginsBase ) : <EOL> plugin_to_test = '<STR_LIT>' <EOL> def test_archive_plugin ( self ) : <EOL> dates = [ <EOL> datetime . datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , pytz . UTC ) , <EOL> datetime . datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:16> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , pytz . UTC ) , <EOL> datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , pytz . UTC ) , <EOL> datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , pytz . UTC ) , <EOL> datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , pytz . UTC ) , <EOL> datetime . datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , pytz . UTC ) , <EOL> ] <EOL> articles = [ ] <EOL> for d in dates : <EOL> article = self . create_article ( publishing_date = d ) <EOL> articles . append ( article ) <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> response_content = force_text ( response . content ) <EOL> needle = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> month1 = needle . format ( year = <NUM_LIT> , month = <NUM_LIT:11> , num = <NUM_LIT:2> ) <EOL> month2 = needle . format ( year = <NUM_LIT> , month = <NUM_LIT:2> , num = <NUM_LIT:1> ) <EOL> month3 = needle . format ( year = <NUM_LIT> , month = <NUM_LIT:1> , num = <NUM_LIT:3> ) <EOL> self . assertRegexpMatches ( response_content , month1 ) <EOL> self . assertRegexpMatches ( response_content , month2 ) <EOL> self . assertRegexpMatches ( response_content , month3 ) <EOL> class TestArticleSearchPlugin ( TestAppConfigPluginsBase ) : <EOL> """<STR_LIT>""" <EOL> plugin_to_test = '<STR_LIT>' <EOL> plugin_params = { <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> } <EOL> def test_article_search_plugin ( self ) : <EOL> needle = '<STR_LIT>' <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> self . assertContains ( response , needle . format ( num = <NUM_LIT:5> ) ) <EOL> class TestAuthorsPlugin ( TestAppConfigPluginsBase ) : <EOL> plugin_to_test = '<STR_LIT>' <EOL> def test_authors_plugin ( self ) : <EOL> author1 , author2 = self . create_person ( ) , self . create_person ( ) <EOL> author1_articles = [ ] <EOL> for _ in range ( <NUM_LIT:3> ) : <EOL> article = self . create_article ( author = author1 ) <EOL> author1_articles . append ( article ) <EOL> other_articles = [ ] <EOL> for _ in range ( <NUM_LIT:5> ) : <EOL> article = self . create_article ( author = author2 ) <EOL> other_articles . append ( article ) <EOL> for _ in range ( <NUM_LIT:7> ) : <EOL> article = self . create_article ( <EOL> author = author1 , <EOL> is_published = False <EOL> ) <EOL> other_articles . append ( article ) <EOL> other_articles . append ( self . create_article ( <EOL> author = author1 , <EOL> app_config = self . another_app_config <EOL> ) ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> response_content = force_text ( response . content ) <EOL> pattern = '<STR_LIT>' <EOL> pattern += '<STR_LIT>' <EOL> author1_pattern = pattern . format ( <EOL> num = <NUM_LIT:3> , <EOL> url = reverse ( <EOL> '<STR_LIT>' . format ( self . app_config . namespace ) , <EOL> args = [ author1 . slug ] <EOL> ) <EOL> ) <EOL> author2_pattern = pattern . format ( <EOL> num = <NUM_LIT:5> , <EOL> url = reverse ( <EOL> '<STR_LIT>' . format ( self . app_config . namespace ) , <EOL> args = [ author2 . slug ] <EOL> ) <EOL> ) <EOL> self . assertRegexpMatches ( response_content , author1_pattern ) <EOL> self . assertRegexpMatches ( response_content , author2_pattern ) <EOL> class TestCategoriesPlugin ( TestAppConfigPluginsBase ) : <EOL> plugin_to_test = '<STR_LIT>' <EOL> def test_categories_plugin ( self ) : <EOL> cat1_articles = [ ] <EOL> for _ in range ( <NUM_LIT:3> ) : <EOL> article = self . create_article ( ) <EOL> article . categories . add ( self . category1 ) <EOL> cat1_articles . append ( article ) <EOL> other_articles = [ ] <EOL> for _ in range ( <NUM_LIT:5> ) : <EOL> article = self . create_article ( ) <EOL> article . categories . add ( self . category2 ) <EOL> other_articles . append ( article ) <EOL> for _ in range ( <NUM_LIT:7> ) : <EOL> article = self . create_article ( is_published = False ) <EOL> article . categories . add ( self . category1 ) <EOL> other_articles . append ( article ) <EOL> for _ in range ( <NUM_LIT:1> ) : <EOL> article = self . create_article ( app_config = self . another_app_config ) <EOL> article . categories . add ( self . category1 ) <EOL> other_articles . append ( article ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> response_content = force_text ( response . content ) <EOL> pattern = '<STR_LIT>' <EOL> needle1 = pattern . format ( num = <NUM_LIT:3> , name = self . category1 . name ) <EOL> needle2 = pattern . format ( num = <NUM_LIT:5> , name = self . category2 . name ) <EOL> self . assertRegexpMatches ( response_content , needle1 ) <EOL> self . assertRegexpMatches ( response_content , needle2 ) <EOL> class TestFeaturedArticlesPlugin ( TestPluginLanguageHelperMixin , <EOL> TestAppConfigPluginsBase ) : <EOL> plugin_to_test = '<STR_LIT>' <EOL> plugin_params = { <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> } <EOL> def test_featured_articles_plugin ( self ) : <EOL> featured_articles = [ self . create_article ( <EOL> is_featured = True , <EOL> is_published = True <EOL> ) for _ in range ( <NUM_LIT:3> ) ] <EOL> other_articles = [ self . create_article ( <EOL> is_featured = True , <EOL> is_published = False <EOL> ) for _ in range ( <NUM_LIT:3> ) ] <EOL> other_articles += [ self . create_article ( ) for _ in range ( <NUM_LIT:3> ) ] <EOL> other_articles += [ self . create_article ( <EOL> is_featured = True , <EOL> app_config = self . another_app_config <EOL> ) for _ in range ( <NUM_LIT:3> ) ] <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> for article in featured_articles : <EOL> self . assertContains ( response , article . title ) <EOL> for article in other_articles : <EOL> self . assertNotContains ( response , article . title ) <EOL> def test_featured_articles_plugin_unpublished_app_page ( self ) : <EOL> with override ( '<STR_LIT>' ) : <EOL> articles = [ self . create_article ( is_featured = True ) <EOL> for _ in range ( <NUM_LIT:3> ) ] <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> for article in articles : <EOL> self . assertContains ( response , article . title ) <EOL> self . page . unpublish ( '<STR_LIT>' ) <EOL> cache . clear ( ) <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> for article in articles : <EOL> self . assertNotContains ( response , article . title ) <EOL> def test_featured_articles_plugin_language ( self ) : <EOL> article = self . create_article ( is_featured = True ) <EOL> self . _test_plugin_languages_with_article ( article ) <EOL> class TestLatestArticlesPlugin ( TestPluginLanguageHelperMixin , <EOL> TestAppConfigPluginsBase ) : <EOL> plugin_to_test = '<STR_LIT>' <EOL> plugin_params = { <EOL> "<STR_LIT>" : <NUM_LIT:7> , <EOL> } <EOL> def test_latest_articles_plugin ( self ) : <EOL> articles = [ self . create_article ( ) for _ in range ( <NUM_LIT:7> ) ] <EOL> another_app_config = NewsBlogConfig . objects . create ( namespace = '<STR_LIT>' ) <EOL> another_articles = [ self . create_article ( app_config = another_app_config ) <EOL> for _ in range ( <NUM_LIT:3> ) ] <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> for article in articles : <EOL> self . assertContains ( response , article . title ) <EOL> for article in another_articles : <EOL> self . assertNotContains ( response , article . title ) <EOL> def _test_latest_articles_plugin_exclude_count ( self , exclude_count = <NUM_LIT:0> ) : <EOL> self . plugin . exclude_featured = exclude_count <EOL> self . plugin . save ( ) <EOL> self . plugin_page . publish ( self . plugin . language ) <EOL> articles = [ ] <EOL> featured_articles = [ ] <EOL> for idx in range ( <NUM_LIT:7> ) : <EOL> if idx % <NUM_LIT:2> : <EOL> featured_articles . append ( self . create_article ( is_featured = True ) ) <EOL> else : <EOL> articles . append ( self . create_article ( ) ) <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> for article in articles : <EOL> self . assertContains ( response , article . title ) <EOL> for featured_article in featured_articles [ : exclude_count ] : <EOL> self . assertNotContains ( response , featured_article . title ) <EOL> for featured_article in featured_articles [ exclude_count : ] : <EOL> self . assertContains ( response , featured_article . title ) <EOL> def test_latest_articles_plugin_exclude_featured ( self ) : <EOL> self . _test_latest_articles_plugin_exclude_count ( <NUM_LIT:3> ) <EOL> def test_latest_articles_plugin_no_excluded_featured ( self ) : <EOL> self . _test_latest_articles_plugin_exclude_count ( ) <EOL> def test_latest_articles_plugin_unpublished_app_page ( self ) : <EOL> with override ( '<STR_LIT>' ) : <EOL> articles = [ self . create_article ( ) for _ in range ( <NUM_LIT:3> ) ] <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> for article in articles : <EOL> self . assertContains ( response , article . title ) <EOL> self . page . unpublish ( '<STR_LIT>' ) <EOL> cache . clear ( ) <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> for article in articles : <EOL> self . assertNotContains ( response , article . title ) <EOL> def test_latest_articles_plugin_language ( self ) : <EOL> article = self . create_article ( ) <EOL> self . _test_plugin_languages_with_article ( article ) <EOL> class TestPrefixedLatestArticlesPlugin ( TestAppConfigPluginsBase ) : <EOL> plugin_to_test = '<STR_LIT>' <EOL> plugin_params = { <EOL> "<STR_LIT>" : <NUM_LIT:7> , <EOL> } <EOL> def setUp ( self ) : <EOL> super ( TestPrefixedLatestArticlesPlugin , self ) . setUp ( ) <EOL> self . app_config . template_prefix = '<STR_LIT>' <EOL> self . app_config . save ( ) <EOL> def test_latest_articles_plugin ( self ) : <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> class TestRelatedArticlesPlugin ( TestPluginLanguageHelperMixin , <EOL> NewsBlogTestCase ) : <EOL> def test_related_articles_plugin ( self ) : <EOL> main_article = self . create_article ( app_config = self . app_config ) <EOL> static_placeholder = StaticPlaceholder . objects . get_or_create ( <EOL> code = '<STR_LIT>' , <EOL> site__isnull = True , <EOL> ) [ <NUM_LIT:0> ] <EOL> placeholder = static_placeholder . draft <EOL> api . add_plugin ( placeholder , '<STR_LIT>' , self . language ) <EOL> static_placeholder . publish ( None , language = self . language , force = True ) <EOL> plugin = placeholder . get_plugins ( ) [ <NUM_LIT:0> ] . get_plugin_instance ( ) [ <NUM_LIT:0> ] <EOL> plugin . save ( ) <EOL> self . plugin_page . publish ( self . language ) <EOL> main_article . save ( ) <EOL> for _ in range ( <NUM_LIT:3> ) : <EOL> a = self . create_article ( ) <EOL> a . save ( ) <EOL> main_article . related . add ( a ) <EOL> another_language_articles = [ ] <EOL> with override ( '<STR_LIT>' ) : <EOL> for _ in range ( <NUM_LIT:4> ) : <EOL> a = self . create_article ( ) <EOL> main_article . related . add ( a ) <EOL> another_language_articles . append ( a ) <EOL> self . assertEquals ( main_article . related . count ( ) , <NUM_LIT:7> ) <EOL> unrelated = [ ] <EOL> for _ in range ( <NUM_LIT:5> ) : <EOL> unrelated . append ( self . create_article ( ) ) <EOL> response = self . client . get ( main_article . get_absolute_url ( ) ) <EOL> for article in main_article . related . all ( ) : <EOL> self . assertContains ( response , article . title ) <EOL> for article in unrelated : <EOL> self . assertNotContains ( response , article . title ) <EOL> self . page . unpublish ( '<STR_LIT>' ) <EOL> cache . clear ( ) <EOL> response = self . client . get ( main_article . get_absolute_url ( ) ) <EOL> for article in another_language_articles : <EOL> self . assertNotContains ( response , article . title ) <EOL> def test_latest_articles_plugin_language ( self ) : <EOL> main_article , related_article = [ <EOL> self . create_article ( ) for _ in range ( <NUM_LIT:2> ) ] <EOL> main_article . related . add ( related_article ) <EOL> self . _test_plugin_languages_with_article ( related_article ) <EOL> class TestTagsPlugin ( TestAppConfigPluginsBase ) : <EOL> plugin_to_test = '<STR_LIT>' <EOL> def test_tags_plugin ( self ) : <EOL> self . create_tagged_articles ( <NUM_LIT:3> , tags = [ '<STR_LIT>' ] ) [ '<STR_LIT>' ] <EOL> other_articles = self . create_tagged_articles ( <NUM_LIT:5> , tags = [ '<STR_LIT>' ] ) [ '<STR_LIT>' ] <EOL> other_articles += self . create_tagged_articles ( <EOL> <NUM_LIT:7> , tags = [ '<STR_LIT>' ] , is_published = False ) [ '<STR_LIT>' ] <EOL> other_articles += self . create_tagged_articles ( <EOL> <NUM_LIT:1> , tags = [ '<STR_LIT>' ] , app_config = self . another_app_config ) [ '<STR_LIT>' ] <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> response = self . client . get ( self . plugin_page . get_absolute_url ( ) ) <EOL> response_content = force_text ( response . content ) <EOL> self . assertRegexpMatches ( response_content , '<STR_LIT>' ) <EOL> self . assertRegexpMatches ( response_content , '<STR_LIT>' ) </s>
