def testWithTwoBlogEntries(self):
     BlogEntry(title='entry1', text='entry1').save()
     BlogEntry(title='entry2', text='entry2').save()
     result = IndexHandler().render()
     self.assertIn('entry2', result)
     self.assertIn('entry1', result)
     self.assertLess(result.index('entry2'), result.index('entry1'))
 def testNoEditLinkForGuest(self):
     # Given there is a blog entry in the database
     BlogEntry(title='entry1', text='entry1').save()
     self.assertEqual(1, BlogEntry.all().count())
     # When I visit the home page
     result = IndexHandler().render()
     # Then I should not see the "Edit" link
     self.assertNotRegexpMatches(result, r"<a href=[^>]+>Edit</a>")
 def testRenderingBlogEntries(self):
     self.assertEqual(0, BlogEntry.all().count())
     BlogEntry(title='asdsad', text='my text').save()
     self.assertEqual(1, BlogEntry.all().count())
     result = IndexHandler().render()
     today = datetime.datetime.now().strftime('%Y-%m-%d')
     self.assertRegexpMatches(result, r'<[^>]+ class="title"[^>]*>asdsad</')
     self.assertRegexpMatches(result,
                              r'<[^>]+ class="text"[^>]*><p>my text</p></')
     self.assertRegexpMatches(result,
                              r'<[^>]+ class="date"[^>]*>%s</' % today)
 def testEditLinkForAdmin(self):
     # Given there are no blog entries in the database
     self.assertEqual(0, BlogEntry.all().count())
     # And I am signed in as admin
     self.signInAsAdmin()
     # And I add a new blog entry "entry1"
     BlogEntry(title='entry1', text='entry1').save()
     self.assertEqual(1, BlogEntry.all().count())
     # When I visit the home page
     result = IndexHandler().render()
     # Then I should see a "Edit" link
     self.assertRegexpMatches(result, r"<a href=[^>]+>Edit</a>")
 def testRenderingBlogEntriesWithMarkdown(self):
     self.assertEqual(0, BlogEntry.all().count())
     BlogEntry(
         title='asdsad',
         text='Hello Markdown\n' + '==\n' + '\n' +
         'This is an example post using [Markdown](http://a.b).').save()
     self.assertEqual(1, BlogEntry.all().count())
     result = IndexHandler().render()
     today = datetime.datetime.now().strftime('%Y-%m-%d')
     self.assertRegexpMatches(result, r'<[^>]+ class="title"[^>]*>asdsad</')
     self.assertRegexpMatches(
         result,
         r'<[^>]+ class="text"[^>]*><h1>Hello Markdown</h1>' + '[^<]*' +
         '<p>This is an example post using <a href="http://a.b">Markdown</a>.</p></'
     )
     self.assertRegexpMatches(result,
                              r'<[^>]+ class="date"[^>]*>%s</' % today)
 def testGuest(self):
     result = IndexHandler().render()
     self.assertNotRegexpMatches(result,
                                 r"<a href=[^>]+>New blog entry</a>")
 def testSignedIn(self):
     self.signInAsUser()
     result = IndexHandler().render()
     self.assertNotRegexpMatches(result,
                                 r"<a href=[^>]+>New blog entry</a>")
 def testSignedIn(self):
     self.signInAsUser()
     result = IndexHandler().render()
     self.assertRegexpMatches(result, r"<a href=[^>]+>Sign out</a>")
 def testGuest(self):
     result = IndexHandler().render()
     self.assertNotRegexpMatches(result, r"<a href=[^>]+>Sign out</a>")
 def testWithNoBlogEntries(self):
     self.assertEqual(0, BlogEntry.all().count())
     result = IndexHandler().render()
     self.assertRegexpMatches(result,
                              "No entries yet, please check back later!")