Exemplo n.º 1
0
 def get_context_data(self, **kwargs):
     context = super(BlogView, self).get_context_data(**kwargs)        
     default_blog = Blog.query().get()
     context['blog'] = default_blog
     if default_blog:
         context['posts'] = Blog.get_all_posts(default_blog.key.id())
     return context
Exemplo n.º 2
0
def initialise_db():
    # Create an ancestor for all of our Posts to ensure consistency when manipulating Posts
    blog_instance = Blog.query().get()
    if not blog_instance:
        blog_instance = Blog()
        blog_instance.put()

    # Create Users
    if not User.query().fetch():
        User(
            username='******',
            password='******'  # TODO - obfuscate this
        ).put()
Exemplo n.º 3
0
def get_blog_key():
    # Return our Blog key. There should only be one instance of Blog. This is used as an ancestor to all Posts.
    return Blog.query().get().key
Exemplo n.º 4
0
 def test_blog_create(self):
     """ we can create """
     res = self.c.post('/blog', {'title': 'Sample Blog 1', 'description': 'Sample Description'})
     self.assertEqual(len(Blog.query().fetch()), 2)
Exemplo n.º 5
0
 def test_blog_delete(self):
     """ we can destroy"""
     res = self.c.delete('/blog/delete/{0}'.format(self.blog_id))
     self.assertEqual(res.status_code, 200)
     self.assertEqual(len(Blog.query().fetch()), 0)
Exemplo n.º 6
0
 def test_blog_get(self):
 	""" ensure blog exist """
 	res = self.c.get('/')
     self.assertEqual(res.context_data['blog'], Blog.query().get())