Exemplo n.º 1
0
    def test_ask_create_blog(self):
        title = 'Test Blog'
        author = 'Test Author'
        blog = Blog(title, author)

        with patch('builtins.input') as mocked_input:
            mocked_input.side_effect = (title, author)
            app.ask_create_blog()

            self.assertIsNotNone(app.blogs.get(title))
Exemplo n.º 2
0
    def test_ask_read_blog(self):
        blog = Blog('Test', 'Test Author')
        app.blogs = {'Test': blog}
        with patch('builtins.input', return_value='Test') as mocked_input:
            with patch('app.print_posts') as mocked_print:

                app.ask_read_blog()
                mocked_input.assert_called_with(
                    "Enter the title of the blog you wish to read: ")
                mocked_print.assert_called_with(blog)
Exemplo n.º 3
0
    def test_ask_create_post(self):
        blog = Blog('Test', 'Test Author')
        app.blogs = {'Test': blog}
        with patch('builtins.input') as mock_input:
            mock_input.side_effect = ('Test', 'Test Title', 'Test Content')

            app.ask_create_post()

            self.assertEqual(blog.posts[0].title, 'Test Title')
            self.assertEqual(blog.posts[0].content, 'Test Content')
Exemplo n.º 4
0
    def test_read_blog(self):
        blog = Blog("Love", "Kingsman")
        app.blogs = dict({"Love": blog})
        with patch("builtins.input", return_value="Love") as mocked_input:
            #application.read_blog()
            #self.assertIsNotNone(application.blogs.get("Love"))

            with patch("application.print_posts") as mocked_print_posts:
                app.read_blog()
                mocked_print_posts.assert_called_with(blog)
Exemplo n.º 5
0
def create_app():
    app = Flask(__name__)
    app.secret_key = "secretkey"
    app.register_blueprint(site)
    app.userlist = UserList()
    app.blog = Blog()
    app.store = Store()
    app.library = Library()
    app.activitylist = ActivityList()
    return app
    def test_create_post(self):
        b = Blog('Test', 'Test Author')
        b.create_post('Test Post', 'Post Content')
        b.create_post('Test Post2', 'Post Content2')

        self.assertEqual(len(b.posts), 2)
        self.assertEqual(b.posts[0].title, 'Test Post')
        self.assertEqual(b.posts[0].content, 'Post Content')
        self.assertEqual(b.posts[1].title, 'Test Post2')
        self.assertEqual(b.posts[1].content, 'Post Content2')
Exemplo n.º 7
0
    def test_create_post(self):
        blog = Blog('Title', 'Author')
        blog.create_post('PostTitle', 'PostContent')
        expected = [{'Title': 'PostTitle',
                     'Content': 'PostContent',
                     }]

        self.assertEqual(len(blog.posts), 1)
        self.assertEqual(blog.posts[0].title, 'PostTitle')
        self.assertEqual(blog.posts[0].content, 'PostContent')
Exemplo n.º 8
0
    def test_json_no_posts(self):
        new_blog = Blog("Test Title", "Test Author")

        expected = {
            'title': 'Test Title',
            'author': 'Test Author',
            'posts': []
        }

        self.assertDictEqual(expected, new_blog.json())
Exemplo n.º 9
0
    def test_json(self):
        b = Blog("Testbloggen", "Alexandra Wåhlander")
        b.create_post("Test post", "Test Content")

        expected = {"Title": "Testbloggen",
                    "Author": "Alexandra Wåhlander",
                    "Posts": [
                        {"title": "Test post",
                               "content": "Test Content"}]
                    }
        self.assertDictEqual(expected, b.json())
Exemplo n.º 10
0
    def test_add_post(self):
        blog = Blog("Orange", "Mauli")
        self.assertEqual([], blog.posts)

        p1 = Post("First Post", "Best Content")
        p2 = Post("Second Post", "Another Best Content")

        blog.add_post(p1, "")
        blog.add_post(p2, "")

        self.assertEqual(2, len(blog.posts))
Exemplo n.º 11
0
    def test_ask_create_post(self):
        blog = Blog("Love", "Kingsman")
        app.blogs = dict({"Love": blog})

        with patch("builtins.input") as mocked_input:

            mocked_input.side_effect = ("Love", "Love Forever2", "Friendship")
            app.ask_create_post()

            #self.assertEqual(blog.posts[0].name, "Love Forever2")
            mocked_input.assert_called()
Exemplo n.º 12
0
def handler(req):
    req.content_type = 'text/html'
    fields = util.FieldStorage(req)
    uri = req.parsed_uri[apache.URI_PATH][1:] #remove the leading '/'
    if uri == 'blog.py' or uri == '': b = Blog(req, fields)
    elif uri == 'pp.py':
        compile_html(req)
        #print >>req, "here I would process htpy files"
    else: req.write("page not found: %s" % uri)
    #for x in dir(req): req.write(x + '<br>')
    return apache.OK
Exemplo n.º 13
0
    def test_json(self):
        b = Blog('My Blog', 'John Smith')
        b.create_post('Post Title', 'Post Content')

        expected = {'title': 'My Blog',
                    'author': 'John Smith',
                    'posts': [{'title': 'Post Title',
                               'content': 'Post Content'}
                              ],
                    }
        self.assertDictEqual(expected, b.json())
Exemplo n.º 14
0
def create_new_blog():
    if request.method == 'GET':
        return render_template('new_blog.html')
    else:
        title = request.form['title']
        description = request.form['description']
        user = User.get_by_email(session['email'])

        new_blog = Blog(user.email, title, description, user._id)
        new_blog.save_to_mongo()
        return make_response(user_blogs(user._id))
Exemplo n.º 15
0
def sitemap():
    # Import Os and Regex
    import os
    from gluon.myregex import regex_expose

    # Finding You Controllers 
    ctldir = os.path.join(request.folder,"controllers")
    ctls=os.listdir(ctldir)
    
    # Excluding The appadmin.py and the Manage.py
    if 'appadmin.py' in ctls: ctls.remove('appadmin.py')
    if 'manage.py' in ctls: ctls.remove('manage.py')

    # Adding  Schemas for the site map

    sitemap=TAG.urlset(_xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")

    # Add The Pages That You Dont want in the XML Sitemap
    ExcludedPages = ['edit', 'saved','delete','new','setpublic','user', 'publishing', 'preview','deletedraft','verified', 'requestreset', 'newform', 'download','handle_error','sitemap','register','google0ac0168ea35fcffb','BingSiteAuth','successful','mailcheck' ]
    ExcludedCtrl = ['administrator', 'plugin_ckeditor', 'verifyprocess', 'payment', 'myaccount', 'account', 'plans','payment','products']

    # Define Your Domain
    # urldomain = '%(scheme)s://www.gextiendas.es' % {'scheme':request.env.wsgi_url_scheme}
    urldomain = '%(scheme)s://%(host)s' % {'scheme':request.env.wsgi_url_scheme,'host':request.env.http_host}

    for ctl in ctls:
            if ctl.endswith(".bak") == False:

                if ctl.replace(".py","") not in ExcludedCtrl:
                    filename = os.path.join(ctldir,ctl)
                    data = open(filename, 'r').read()
                    functions = regex_expose.findall(data)
                    ctl = ctl[:-3].replace("_"," ")

                    # Adding Statics URLs From Your Controllers 
                    for f in functions:
                        # Ignore the Pages from the list above (  ExcludedPages )
                        if f not in ExcludedPages:
                             sitemap.append(TAG.url(TAG.loc('%s/%s/%s' % (urldomain, ctl,f.replace("_"," ")))))


    #  Dynamic URLs From Tables  For ex ... >> www.domain.com/post/1
    from blog import Blog, Images
    try:
        Blog(db,ckeditor)
        Images(db)
    except:
        pass
    posts = db(db.blog.public==True).select(db.blog.ALL, orderby=~db.blog.created_on)
    for item in posts:
        #sitemap.append(TAG.url(TAG.loc('%s/%s/blog/show/%s' % (urldomain, request.application,item.id))))
        sitemap.append(TAG.url(TAG.loc('%s/blog/show/%s' % (urldomain, item.urlfriendly))))
    
    return '<?xml version="1.0" encoding="UTF-8"?>\n%s' % sitemap.xml()
Exemplo n.º 16
0
def index():
    from blog import Blog, Images
    Blog(db,ckeditor), Images(db)
    response.files.append(URL('static', 'js/vendor/layerslider/jquery-easing-1.3.js'))
    response.files.append(URL('static', 'js/vendor/layerslider/jquery-transit-modified.js'))
    #LayerSlider from Kreatura Media with Transitions 
    response.files.append(URL('static', 'js/vendor/layerslider/layerslider.transitions.js'))
    response.files.append(URL('static', 'js/vendor/layerslider/layerslider.kreaturamedia.jquery.js'))
    #Grove Layerslider initiation script
    response.files.append(URL('static', 'js/grove-slider.js'))
    return dict()
Exemplo n.º 17
0
    def test_create_blog(self):
        b = Blog("Test Title", "Test Author")
        self.assertEqual("Test Title", b.title,
                         "The title is not valid for the test")
        self.assertEqual("Test Author", b.author,
                         "The author is not valid for the test")
        self.assertListEqual([], b.posts, "The list is not valid for the test")

        self.assertIsInstance(b.title, str, "Title should be a string")
        self.assertIsInstance(b.author, str, "Author should be a string")
        self.assertIsInstance(b.posts, list, "Posts should be a list")
Exemplo n.º 18
0
    def test_repr_multiple_posts(self):
        b = Blog("Testbloggen", "Alexandra Wåhlander")
        b.posts = ["test", "Hej"]

        b2 = Blog("Testbloggen", "Alexandra Wåhlander")
        b2.posts = []

        b3 = Blog("Testbloggen", "Alexandra Wåhlander")
        b3.posts = ["Ett"]

        self.assertEqual("Testbloggen by Alexandra Wåhlander (2 posts)", b.__repr__())
        self.assertEqual("Testbloggen by Alexandra Wåhlander (0 posts)", b2.__repr__())
        self.assertEqual("Testbloggen by Alexandra Wåhlander (1 post)", b3.__repr__())


   # def test_json(self):
    #    b = Blog("Testbloggen", "Alexandra Wåhlander")
     #   expected = {"Title": Testbloggen, "Author": Alexandra Wåhlander, "Posts": []}

      #  self.assertEqual(expected, b.json())
Exemplo n.º 19
0
 def test_json_with_post(self):
     b = Blog('TestTitle', 'TestAuthor')
     b.create_post('TestPostTitle', 'TestContent')
     self.assertDictEqual(
         b.json(), {
             'title': 'TestTitle',
             'author': 'TestAuthor',
             'posts': [{
                 'title': 'TestPostTitle',
                 'content': 'TestContent'
             }]
         })
Exemplo n.º 20
0
 def test_json(self):
     b = Blog('The best book', 'John Doe')
     b.create_post('Test Post', 'Test content')
     expect = {
         'title': 'The best book',
         'author': 'John Doe',
         'posts': [{
             'title': 'Test Post',
             'content': 'Test content',
         }]
     }
     self.assertDictEqual(expect, b.json())
Exemplo n.º 21
0
    def test_menu_calls_ask_create_post(self):
        b = Blog('MyNote', 'Nat')
        b.create_post('Programming Tips', 'Be Lazy!!')
        b.create_post('Work Tips', 'Work Hard...')
        target_post = b.posts[0]

        with patch('builtins.input') as mocked_input:
            mocked_input.side_effect = ('p', 'MyNote', 'Programming Tips',
                                        'Be Lazy!!', 'q')
            with patch('app.ask_create_post') as mocked_ask_create_post:
                app.menu()
                mocked_ask_create_post.assert_called_once_with()
Exemplo n.º 22
0
 def test_json(self):
     b = Blog("Test", "Test Author")
     b.create_post("Test Post", "Test Content")
     expected = {
         "title": "Test",
         "author": "Test Author",
         "posts": [{
             "title": "Test Post",
             "content": "Test Content"
         }],
     }
     self.assertDictEqual(expected, b.json())
Exemplo n.º 23
0
    def test_create_post_in_blog(self):

        # Load Blog class
        b = Blog('Test', 'Test Author')

        # Create post that receives a title and a content
        b.create_post('Test Post', 'Test Content')

        # Make asserts
        self.assertEqual(len(b.posts), 1)
        self.assertEqual(b.posts[0].title, 'Test Post')
        self.assertEqual(b.posts[0].content, 'Test Content')
Exemplo n.º 24
0
    def test_json(self):
        b = Blog('Test', 'Test Author')
        b.create_post('Test Post', 'Test Content')

        expected = {'title': 'Test',
                    'author': 'Test Author',
                    'posts': [
                        {'title': 'Test Post',
                         'content': 'Test Content'}]}


        self.assertDictEqual(expected, b.json())
Exemplo n.º 25
0
 def test_json(self):
     b = Blog('Test', 'Test Author')
     b.create_post('Test Post', 'Test Content')
     expected = {
         "title": "Test",
         "author": "Test Author",
         "posts": [{
             "title": "Test Post",
             "content": "Test Content",
         }]
     }
     self.assertDictEqual(b.json(), expected)
def test_blog_json():
    b = Blog('Test', 'Test Author')
    b.create_post('Test Post', 'Test Content')
    expected = {
        'title': 'Test',
        'author': 'Test Author',
        'posts': [{
            'title': 'Test Post',
            'content': 'Test Content'
        }]
    }
    assert b.json() == expected
Exemplo n.º 27
0
 def post(self):
     title = self.request.get('subject')
     text = self.request.get('content')
     if title and text:
         # both title and text are required
         blog = Blog(title=title, body=text, user_id=self.user_id)
         blog_id = blog.put().id()
         self.redirect("/blog/%d" % blog_id)
     else:
         error = 'Both fields are required.'
         self.render('newblog.html', error=error, title=title,
                     text=text)
Exemplo n.º 28
0
    def test_create_post(self):
        b = Blog('Test Blog', 'Manuel')
        b.create_post('post title', 'blah blah blah')

        self.assertEqual(1, len(b.posts))
        self.assertEqual('post title', b.posts[0].title)
        self.assertEqual('blah blah blah', b.posts[0].content)

        b.create_post('second post', 'foo')
        self.assertEqual(2, len(b.posts))
        self.assertEqual('second post', b.posts[1].title)
        self.assertEqual('foo', b.posts[1].content)
Exemplo n.º 29
0
    def test_print_posts(self):
        """
        This is a test for print_posts function
        """
        blog = Blog("My days", "RW")
        blog.create_post('Post 1', 'This is my first post')
        blog.create_post('Post 2', 'This is my second post')
        app.blogs.update({"My days": blog})

        with patch('app.print_post') as mocked_print_post:
            app.print_posts(blog)

            mocked_print_post.assert_called_with(blog.posts[1])
Exemplo n.º 30
0
 def test_json_no_posts(self):
     b = Blog('Test', 'Test Author')
     b.posts = [Post('', '')]
     expected_json = {
         'title': 'Test',
         'author': 'Test Author',
         'posts': [
             {
                 'title': '', 'content': ''
             }
         ]
     }
     self.assertEqual(expected_json, b.json())