def testEditBlogEntry(self):
        # Given there is a blog entry in the database
        entry = BlogEntry(title='entry1', text='entry1')
        entry.save()
        self.assertEqual(1, BlogEntry.all().count())
        # And I am signed in as admin
        self.signInAsAdmin()
        # When I edit the blog entry
        handler = self.createEditBlogEntryHandler()
        handler.request.GET['id'] = entry.key().id()
        handler.get()
        result = str(handler.response.out)
        # And I should see an input for "title"
        self.assertRegexpMatches(result, r'<[^>]+ name="title"[^>]*>')
        self.assertRegexpMatches(result, r'<[^>]+ value="entry1"[^>]*>')
        # And I should see an input for "text"
        self.assertRegexpMatches(result, r'<[^>]+ name="text"[^>]*>')
        self.assertRegexpMatches(result, r'<textarea[^>]*>entry1<')
        # And I should see a "Save" button
        self.assertRegexpMatches(result, r'<button[^>]*>Save</')

        # And I fill out the "title" field with "new title"
        handler = self.createEditBlogEntryHandler()
        handler.request.POST['id'] = entry.key().id()
        handler.request.POST['title'] = 'new title'
        # And I fill out the "text" field with "new text"
        handler.request.POST['text'] = 'new text'
        # And I click on the "Save" button
        handler.post()
        # And I should see the blog entry with "title": "new title"
        self.assertEqual(1, BlogEntry.all().count())
        entry = BlogEntry.all().get()
        self.assertEqual('new title', entry.title)
        # And I should see the blog entry with "text": "new text"
        self.assertEqual('new text', entry.text)
    def testPostNewBlogEntry(self, textLength=200):
        self.signInAsAdmin()

        self.assertEqual(0, BlogEntry.all().count())
        handler = self.createNewBlogEntryHandler(textLength=textLength)
        handler.post()
        self.assertEqual(1, BlogEntry.all().count())
        e = BlogEntry.all().get()
        self.assertEqual('asdsad', e.title)
        self.assertEqual(handler.request.text, e.text)
 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 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 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)
Пример #7
0
    def get(self):
        # GET ALL BLOG POSTS TO LIST THEM
        posts = BlogEntry.all().order('-created')

        # get any error messages from get request
        error = self.request.get("error")

        self.render("login.html", error=error, posts=posts)
Пример #8
0
    def get(self):
        user_id = None
        u = None
        error = ""
        post = ""
        # GET ALL BLOG POSTS TO LIST THEM
        try:
            posts = BlogEntry.all().order('-created')
        except:
            pass

        # AUTHENTICATE: check for valid cookie
        user_id = auth(self.request.cookies.get('user_id'))

        if user_id:
            try:
                # check db to verify that the username exists even though \
                # browser has a cookie. Maybe this user was deleted from the\
                # db by the admin.
                u = Users.get_by_id(int(user_id))
            except:
                pass
            if u:
                user_name = u.userName

                try:
                    error = self.request.get("error")
                except:
                    pass
                self.render("blogMain.html", user_name=user_name, posts=posts, error=error)
            else:
                # if user is NOT in the db
                error = "Could not verify username."
                self.redirect("/login?error=%s" % error)
        else:
            error = "Please log in."
            self.redirect("/login?error=%s" % error)
Пример #9
0
 def get(self):
     entries = BlogEntry.all().order('-updated_at')
     template_vars = { 'object_list': entries }
     self.render_response('blog/blog_list.html', template_vars)
 def testWithNoBlogEntries(self):
     self.assertEqual(0, BlogEntry.all().count())
     result = IndexHandler().render()
     self.assertRegexpMatches(result,
                              "No entries yet, please check back later!")