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))
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)
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')
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)
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')
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')
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())
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())
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))
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()
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
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())
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))
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()
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()
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")
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())
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' }] })
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())
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()
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())
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')
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())
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
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)
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)
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])
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())