<s> import os . path <EOL> from django . core . urlresolvers import reverse <EOL> from django . template import Context , Template <EOL> from django . template . defaultfilters import slugify <EOL> from django . test import TestCase <EOL> from django . test . client import Client <EOL> from radpress . compat import get_user_model <EOL> User = get_user_model ( ) <EOL> from radpress . models import Article , Page , Tag <EOL> from radpress . readers import get_reader <EOL> from radpress . settings import CONTEXT_DATA , MORE_TAG <EOL> from radpress . templatetags . radpress_tags import radpress_get_url <EOL> class RadpressTestCase ( TestCase ) : <EOL> fixtures = [ os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) ] <EOL> def setUp ( self ) : <EOL> self . client = Client ( ) <EOL> self . article1 = Article . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . user1 = User . objects . get ( username = '<STR_LIT>' ) <EOL> self . user1 . set_password ( '<STR_LIT>' ) <EOL> self . user1 . save ( ) <EOL> self . user2 = User . objects . get ( username = '<STR_LIT>' ) <EOL> self . user2 . set_password ( '<STR_LIT>' ) <EOL> self . user2 . save ( ) <EOL> def render_template ( self , template , context ) : <EOL> context = Context ( context ) <EOL> return Template ( template ) . render ( context ) <EOL> class RadpressReaderTestCase ( RadpressTestCase ) : <EOL> markup = None <EOL> file_path = None <EOL> def setUp ( self ) : <EOL> self . reader = get_reader ( markup = self . markup ) <EOL> if self . file_path is not None : <EOL> file_path = os . path . join ( os . path . dirname ( __file__ ) , self . file_path ) <EOL> content = open ( file_path ) . read ( ) <EOL> self . content_body , self . metadata = self . reader ( content ) . read ( ) <EOL> def test_check_metadata ( self ) : <EOL> self . assertEqual ( self . metadata [ '<STR_LIT:image>' ] , '<STR_LIT:1>' ) <EOL> self . assertTrue ( self . metadata [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( self . metadata [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . metadata [ '<STR_LIT:title>' ] , '<STR_LIT>' ) <EOL> for tag in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . assertIn ( tag , self . metadata [ '<STR_LIT>' ] ) <EOL> def test_contents ( self ) : <EOL> for article in Article . objects . filter ( markup = self . markup ) : <EOL> content_body , metadata = self . reader ( article . content ) . read ( ) <EOL> self . assertEqual ( article . content_body , content_body ) <EOL> def test_more_tag ( self ) : <EOL> self . assertIn ( MORE_TAG , self . content_body ) <EOL> class BaseTest ( RadpressTestCase ) : <EOL> def test_all_published_articles ( self ) : <EOL> self . assertEqual ( Article . objects . all_published ( ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Page . objects . all_published ( ) . count ( ) , <NUM_LIT:2> ) <EOL> def test_open_private_and_public_article_details ( self ) : <EOL> for article in Article . objects . all ( ) : <EOL> status_code = <NUM_LIT:200> if article . is_published else <NUM_LIT> <EOL> response = self . client . get ( article . get_absolute_url ( ) ) <EOL> self . assertEqual ( response . status_code , status_code ) <EOL> def test_preview_page ( self ) : <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> expected_status_code = <NUM_LIT> <EOL> self . assertEqual ( response . status_code , expected_status_code ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> expected_status_code = <NUM_LIT> <EOL> self . assertEqual ( response . status_code , expected_status_code ) <EOL> def test_slugs ( self ) : <EOL> for article in Article . objects . all ( ) : <EOL> slug = slugify ( article . slug ) <EOL> self . assertEqual ( article . slug , slug ) <EOL> def test_tags ( self ) : <EOL> self . assertEqual ( Tag . objects . count ( ) , <NUM_LIT:2> ) <EOL> tag_name = '<STR_LIT>' <EOL> tag = Tag . objects . create ( name = tag_name ) <EOL> self . assertEqual ( tag . slug , slugify ( tag_name ) ) <EOL> self . article1 . articletag_set . create ( tag = tag ) <EOL> self . assertEqual ( self . article1 . tags . count ( ) , <NUM_LIT:1> ) <EOL> articles = Article . objects . filter ( tags__name = tag_name ) <EOL> self . assertEqual ( articles . count ( ) , <NUM_LIT:1> ) <EOL> def test_access_not_published_article ( self ) : <EOL> """<STR_LIT>""" <EOL> article = Article . objects . get ( slug = '<STR_LIT>' ) <EOL> page = Page . objects . get ( slug = '<STR_LIT>' ) <EOL> def get_responses ( ) : <EOL> response_article = self . client . get ( <EOL> reverse ( '<STR_LIT>' , args = [ article . slug ] ) ) <EOL> response_page = self . client . get ( <EOL> reverse ( '<STR_LIT>' , args = [ page . slug ] ) ) <EOL> return response_article , response_page <EOL> response_article , response_page = get_responses ( ) <EOL> self . assertEqual ( response_article . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( response_page . status_code , <NUM_LIT> ) <EOL> self . client . login ( username = self . user2 . username , password = '<STR_LIT>' ) <EOL> self . assertFalse ( self . user2 . is_superuser ) <EOL> response_article , response_page = get_responses ( ) <EOL> self . assertEqual ( response_article . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( response_page . status_code , <NUM_LIT> ) <EOL> self . user2 . is_superuser = True <EOL> self . user2 . save ( ) <EOL> self . assertTrue ( self . user2 . is_superuser ) <EOL> response_article , response_page = get_responses ( ) <EOL> self . assertEqual ( response_article . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response_page . status_code , <NUM_LIT:200> ) <EOL> article . author = self . user2 <EOL> article . save ( ) <EOL> self . user2 . is_superuser = False <EOL> self . user2 . save ( ) <EOL> self . assertFalse ( self . user2 . is_superuser ) <EOL> response_article , response_page = get_responses ( ) <EOL> self . assertEqual ( response_article . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response_page . status_code , <NUM_LIT> ) <EOL> def test_context_data ( self ) : <EOL> """<STR_LIT>""" <EOL> for context in CONTEXT_DATA . keys ( ) : <EOL> self . assertTrue ( context . startswith ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( context , context . upper ( ) ) <EOL> def test_radpress_get_url_tag ( self ) : <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertIn ( '<STR_LIT>' , response . context_data ) <EOL> context = response . context_data <EOL> for article in Article . objects . all ( ) : <EOL> article_url = context [ '<STR_LIT>' ] + article . get_absolute_url ( ) <EOL> expected_url = radpress_get_url ( context , article ) <EOL> self . assertEqual ( article_url , expected_url ) <EOL> class RestructuredtextTest ( RadpressReaderTestCase ) : <EOL> markup = '<STR_LIT>' <EOL> file_path = '<STR_LIT>' <EOL> def test_pygmentize ( self ) : <EOL> self . assertIn ( '<STR_LIT>' , self . content_body ) <EOL> self . assertIn ( '<STR_LIT>' , self . content_body ) </s>
