class TestBlog(unittest.TestCase): def setUp(self): ''' method to run before each test case ''' self.new_blog = Blogs( blog_id=234, blog_title='tech', blog_content='technology has greatly revolutionised the universe', posted='24/11/2019', writer_id=34) def tearDown(self): ''' method that runs after each test case ''' Blogs.query.delete() Writer.query.delete() def test_check_instance_variables(self): self.assertEquals(self.new_blog.blog_id, 234) self.assertEquals(self.new_blog.blog_title, 'tech') self.assertEquals(self.new_blog.writer_id, 34) self.assertEquals( self.new_blog.blog_content, 'technology has greatly revolutionised the universe') def test_save_blog(self): self.new_blog.save_blog() self.assertTrue(len(Blogs.query.all()) > 0) def test_get_blog_by_id(self): self.new_blog.save_blogs() blog = Blogs.get_blog(1) self.assertTrue(blog is not None)
class BlogModelTest(unittest.TestCase): def setUp(self): self.user_charles = User(username='******', password='******', email='*****@*****.**') self.new_blog = Blogs(id=1, title='Test', content='This is a test blog', user_id=self.user_alex.id) def tearDown(self): Blogs.query.delete() User.query.delete() def test_check_instance_variables(self): self.assertEquals(self.new_blog.title, 'Test') self.assertEquals(self.new_blog.content, 'This is a test blog') self.assertEquals(self.new_blog.user_id, self.user_charles.id) def test_save_blog(self): self.new_blog.save() self.assertTrue(len(Blogs.query.all()) > 0) def test_get_blog(self): self.new_blog.save() get_blogs = Blogs.get_blogs(1) self.assertTrue(get_blogs is not None)
def setUp(self): self.user_charles = User(username='******', password='******', email='*****@*****.**') self.new_blog = Blogs(id=1, title='Test', content='This is a test blog', user_id=self.user_alex.id)
def setUp(self): ''' method to run before each test case ''' self.new_blog = Blogs( blog_id=234, blog_title='tech', blog_content='technology has greatly revolutionised the universe', posted='24/11/2019', writer_id=34)
def create_blog(username): user = Users.query.filter_by(username=username).first_or_404() if user != current_user: flash('This is not your page!') return redirect(url_for('main.index')) form = CreateBlogForm() if form.validate_on_submit(): blog = Blogs(title=form.title.data, synopsis=form.synopsis.data, body=form.body.data, author=current_user) db.session.add(blog) db.session.commit() flash('Your blog has been posted!') return redirect(url_for('main.index')) return render_template('blogs/create_blog.html', title='Write a Blog!', form=form)
def upload_blog(): form = UploadBlog() if form.validate_on_submit(): blog = Blogs(category=form.category.data, blog=form.blog.data, user=current_user) db.session.add(blog) db.session.commit() flash('Blog Posted!') return redirect(url_for('main.index')) return render_template('new_blog.html', form=form, title='New Blog', legend='Upload Blog', page='upload')
class test_blog(unittest.TestCase): def setUp(self): self.new_blog = Blogs(title ='Sereni', body = 'I got you') def tearDown(self): Blogs.query.delete() def test_instance(self): self.assertTrue(isinstance(self.new_blog,Blogs)) def test_save_blog(self): self.new_blog.save_blog() self.assertEqual(len(Blogs.query.all()),1) def test_delete_blog(self): self.new_blog.save_blog() self.assertEqual(len(Blogs.query.all()),1) self.new_blog.delete_blog() self.assertEqual(len(Blogs.query.all()),0)
def setUp(self): self.new_blog = Blogs(blog='i love life') self.new_comment = Comment(comment='live life', blogs=self.new_blog)
def test_get_blog_by_id(self): self.new_blog.save_blogs() blog = Blogs.get_blog(1) self.assertTrue(blog is not None)
def test_get_blog(self): self.new_blog.save() get_blogs = Blogs.get_blogs(1) self.assertTrue(get_blogs is not None)
def setUp(self): self.new_blog = Blogs(title="money", body="money money")
def setUp(self): self.new_blog = Blogs(title ='Sereni', body = 'I got you')
def setUp(self): self.users = User(username='******', password='******', email='*****@*****.**') self.new_blog = Blogs(id=1, blogs='comment', date_posted = datetime.now, users_id=self.users.id) self.new_comment = Comments(id=1, comment ='This is a test comment', user_id=self.users.id, blogs_id = self.new_blog.id )