def test_create_post_without_tag(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Log in self.client.login(username='******', password="******") # Check response code response = self.client.get('/admin/blog/post/add/') self.assertEquals(response.status_code, 200) # Create the new post response = self.client.post('/admin/blog/post/add/', { 'title': 'My first post', 'text': 'This is my first post', 'pub_date_0': '2013-12-28', 'pub_date_1': '22:00:04', 'slug': 'my-first-post', 'site': '1', 'category': '1' }, follow=True) self.assertEquals(response.status_code, 200) # Check added successfully self.assertTrue('adicionado com sucesso' in response.content) # Check new post now in database all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1)
def test_all_post_feed(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Create the tag tag = Tag() tag.name = 'python' tag.description = 'The Python programming language' tag.save() # Create the author author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() # Create the site site = Site() site.name = 'example.com' site.domain = 'example.com' site.save() # Create a post post = Post() post.title = 'My first post' post.text = 'This is my first blog post' post.slug = 'my-first-post' post.pub_date = timezone.now() post.author = author post.site = site post.category = category # Save it post.save() # Add the tag post.tags.add(tag) post.save() # Check we can find it all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) only_post = all_posts[0] self.assertEquals(only_post, post) # Fetch the feed response = self.client.get('/feeds/posts/') self.assertEquals(response.status_code, 200) # Parse the feed feed = feedparser.parse(response.content) # Check length self.assertEquals(len(feed.entries), 1) # Check post retrieved is the correct one feed_post = feed.entries[0] self.assertEquals(feed_post.title, post.title) self.assertEquals(feed_post.description, post.text)
def test_edit_category(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Log in self.client.login(username='******', password="******") # Edit the category response = self.client.post( '/admin/blog/category/1/', { 'name': 'perl', 'description': 'The Perl programming language' }, follow=True) self.assertEquals(response.status_code, 200) # Check modificado com sucesso self.assertTrue('modificado com sucesso' in response.content) # Check category amended all_categories = Category.objects.all() self.assertEquals(len(all_categories), 1) only_category = all_categories[0] self.assertEquals(only_category.name, 'perl') self.assertEquals(only_category.description, 'The Perl programming language')
def post(self): from .models import FontIcon,FontIconLibrary iconclass = None i = request.form.get('icon',None) if i is not None: lib,icon = i.split('-')[0],i.split('-')[1:] iconclass = FontIcon.query.filter(FontIcon.name==''.join(map(str,icon)),FontIconLibrary.name==lib).first() self._context['form_args'] = {'heading':self._form_heading} self._form = self._form(request.form) if self._form.validate(): from blog.models import Category c = Category.query.filter(Category.name==self._form.name.data).first() if c is None: c = Category() if iconclass is not None: c.icon_id = iconclass.id c.name = self._form.name.data c.description = self._form.description.data c.save() self.flash('You added category: {}'.format(c.name)) if request.args.get('last_url'): return self.redirect(request.args.get('last_url'),raw=True) else: self.flash('There is already a category by that name, try again') return self.redirect('core.index')
def test_edit_category(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Log in self.client.login(username='******', password="******") # Edit the category response = self.client.post('/admin/blogengine/category/1/', { 'name': 'perl', 'description': 'The Perl programming language' }, follow=True) self.assertEquals(response.status_code, 200) # Check changed successfully self.assertTrue('changed successfully' in response.content) # Check category amended all_categories = Category.objects.all() self.assertEquals(len(all_categories), 1) only_category = all_categories[0] self.assertEquals(only_category.name, 'perl') self.assertEquals(only_category.description, 'The Perl programming language')
def test_create_post_without_tag(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Log in self.client.login(username='******', password="******") # Check response code response = self.client.get('/admin/blog/post/add/') self.assertEquals(response.status_code, 200) # Create the new post response = self.client.post('/admin/blog/post/add/', { 'title': 'My first post', 'text': 'This is my first post', 'pub_date_0': '2013-12-28', 'pub_date_1': '22:00:04', 'slug': 'my-first-post', # 'site': '1', 'category': '1' }, follow=True ) self.assertEquals(response.status_code, 200) # Check added successfully self.assertTrue('added successfully' in response.content) # Check new post now in database all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1)
def post(self): from .models import FontIcon, FontIconLibrary iconclass = None i = request.form.get('icon', None) if i is not None: lib, icon = i.split('-')[0], i.split('-')[1:] iconclass = FontIcon.query.filter( FontIcon.name == ''.join(map(str, icon)), FontIconLibrary.name == lib).first() self._context['form_args'] = {'heading': self._form_heading} self._form = self._form(request.form) if self._form.validate(): from blog.models import Category c = Category.query.filter( Category.name == self._form.name.data).first() if c is None: c = Category() if iconclass is not None: c.icon_id = iconclass.id c.name = self._form.name.data c.description = self._form.description.data c.save() self.flash('You added category: {}'.format(c.name)) if request.args.get('last_url'): return self.redirect(request.args.get('last_url'), raw=True) else: self.flash( 'There is already a category by that name, try again') return self.redirect('core.index')
def test_category_page(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Create the author author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() # Create the site site = Site() site.name = 'example.com' site.domain = 'example.com' site.save() # Create the post post = Post() post.title = 'My first post' post.text = 'This is [my first blog post](http://127.0.0.1:8000/)' post.slug = 'my-first-post' post.pub_date = timezone.now() post.author = author post.site = site post.category = category post.save() # Check new post saved all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) only_post = all_posts[0] self.assertEquals(only_post, post) # Get the category URL category_url = post.category.get_absolute_url() # Fetch the category response = self.client.get(category_url) self.assertEquals(response.status_code, 200) # Check the category name is in the response self.assertTrue(post.category.name in response.content) # Check the post text is in the response self.assertTrue( markdown.markdown(post.text).encode() in response.content) # Check the post date is in the response self.assertTrue(str(post.pub_date.year) in response.content) self.assertTrue( _date(post.pub_date, "F").encode('utf-8') in response.content) self.assertTrue(str(post.pub_date.day) in response.content) # Check the link is marked up properly self.assertTrue( '<a href="http://127.0.0.1:8000/">my first blog post</a>' in response.content)
def test_edit_posts(self): category = Category() category.name = 'python' category.description = 'The python language' category.save() # Create the tag tag = Tag() tag.name = 'python' tag.description = 'The Python programming language' tag.save() author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() # site = Site() # site.name = 'nunfuxgvn.com' # site.domain = 'nunfuxgvn.com' # site.save() post = Post() post.title = 'First Post' post.content = 'My first post -yay' post.slug = 'first-post' post.pub_date = timezone.now() post.author = author # post.site = site post.save() post.tags.add(tag) post.save() self.client.login(username='******', password='******') response = self.client.post('/admin/blog/post/1/', { 'title': 'Second Post', 'text': 'This is my second post', 'pub_date_0': '2014-07-17', 'pub_date_1': '11:49:24', 'slug': 'second-post', # 'site': '1', 'category': '1', 'tags': '1' }, follow=True ) self.assertEquals(response.status_code, 200) # Check post successfully changed self.assertTrue('changed successfully' in response.content) # Check post amended all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) only_post = all_posts[0] self.assertEquals(only_post.title, 'Second Post') self.assertEquals(only_post.content, 'This is my second post')
def test_delete_post(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Create the tag tag = Tag() tag.name = 'python' tag.description = 'The Python programming language' tag.save() # Create the author author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() # Create the site site = Site() site.name = 'example.com' site.domain = 'example.com' site.save() # Create the post post = Post() post.title = 'My first post' post.text = 'This is my first blog post' post.slug = 'my-first-post' post.pub_date = timezone.now() post.site = site post.author = author post.category = category post.save() post.tags.add(tag) post.save() # Check new post saved all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) # Log in self.client.login(username='******', password="******") # Delete the post response = self.client.post('/admin/blogengine/post/1/delete/', { 'post': 'yes' }, follow=True) self.assertEquals(response.status_code, 200) # Check deleted successfully self.assertTrue('deleted successfully' in response.content) # Check post deleted all_posts = Post.objects.all() self.assertEquals(len(all_posts), 0)
def test_delete_post(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Create the tag tag = Tag() tag.name = 'python' tag.description = 'The Python programming language' tag.save() # Create the author author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() # Create the site site = Site() site.name = 'example.com' site.domain = 'example.com' site.save() # Create the post post = Post() post.title = 'My first post' post.text = 'This is my first blog post' post.slug = 'my-first-post' post.pub_date = timezone.now() post.site = site post.author = author post.save() post.tags.add(tag) post.save() # Check new post saved all_posts = Post.objects.all() self.assertGreater(len(all_posts), 0) # Log in self.client.login(username='******', password="******") # Delete the post response = self.client.post('/admin/blog/post/1/delete/', {'post': 'yes'}, follow=True) self.assertEquals(response.status_code, 200) # Check excluído com sucesso self.assertTrue('excluído com sucesso' in response.content) # Check post amended all_posts = Post.objects.all() self.assertEquals(len(all_posts), 0)
def test_category_page(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Create the author author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() # Create the site site = Site() site.name = 'example.com' site.domain = 'example.com' site.save() # Create the post post = Post() post.title = 'My first post' post.text = 'This is [my first blog post](http://127.0.0.1:8000/)' post.slug = 'my-first-post' post.pub_date = timezone.now() post.author = author post.site = site post.category = category post.save() # Check new post saved all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) only_post = all_posts[0] self.assertEquals(only_post, post) # Get the category URL category_url = post.category.get_absolute_url() # Fetch the category response = self.client.get(category_url) self.assertEquals(response.status_code, 200) # Check the category name is in the response self.assertTrue(post.category.name in response.content) # Check the post text is in the response self.assertTrue(markdown.markdown(post.text) in response.content) # Check the post date is in the response self.assertTrue(str(post.pub_date.year) in response.content) self.assertTrue(post.pub_date.strftime('%b') in response.content) self.assertTrue(str(post.pub_date.day) in response.content) # Check the link is marked up properly self.assertTrue('<a href="http://127.0.0.1:8000/">my first blog post</a>' in response.content)
def test_index(self): category = Category() category.name = 'python' category.description = 'The python language' category.save() # Create the tag tag = Tag() tag.name = 'perl' tag.description = 'The Perl programming language' tag.save() author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() # site = Site() # site.name = 'nunfuxgvn.com' # site.domain = 'nunfuxgvn.com' # site.save() post = Post() post.title = 'First Post' post.content = 'My [first post](http://127.0.0.1:8000/) -yay' post.slug = 'first-post' post.pub_date = timezone.now() post.author = author # post.site = site post.category = category post.save() post.tags.add(tag) all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) # Fetch test_index response = self.client.get('/') self.assertEquals(response.status_code, 200) self.assertTrue(post.title in response.content) self.assertTrue(markdown.markdown(post.content) in response.content) self.assertTrue(post.category.name in response.content) post_tag = all_posts[0].tags.all()[0] self.assertTrue(post_tag.name in response.content) self.assertTrue(str(post.pub_date.year) in response.content) self.assertTrue(post.pub_date.strftime('%b') in response.content) self.assertTrue(str(post.pub_date.day) in response.content) self.assertTrue('<a href="http://127.0.0.1:8000/">first post</a>' in response.content)
def post(self): self._context['form_args'] = {'heading':self._form_heading} self._form = self._form(request.form) if self._form.validate(): from blog.models import Category c = Category.query.filter(Category.name==self._form.name.data).first() if c is None: c = Category() c.name = self._form.name.data c.description = self._form.description.data c.save() self.flash('You added category: {}'.format(c.name)) else: self.flash('There is already a category by that name, try again') return self.render()
def test_create_category(self): category = Category() category.name = 'python' category.description = 'The python language' category.slug = 'python' category.save() all_categories = Category.objects.all() self.assertEquals(len(all_categories), 1) only_category = all_categories[0] self.assertEquals(only_category, category) self.assertEquals(only_category.name, 'python') self.assertEquals(only_category.description, 'The python language') self.assertEquals(only_category.slug, 'python')
def test_delete_post(self): category = Category() category.name = 'python' category.description = 'The python language' category.save() # Create the tag tag = Tag() tag.name = 'python' tag.description = 'The Python programming language' tag.save() author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() # site = Site() # site.name = 'nunfuxgvn.com' # site.domain = 'nunfuxgvn.com' # site.save() post = Post() post.title = 'First Post' post.test = 'My first post' post.slug = 'first-post' post.pub_date = timezone.now() post.author = author # post.site = site post.save() post.tags.add(tag) post.save() all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) self.client.login(username='******', password='******') response = self.client.post('/admin/blog/post/1/delete/', { 'post': 'yes' }, follow=True) self.assertEquals(response.status_code, 200) self.assertTrue('deleted successfully' in response.content) all_posts = Post.objects.all() self.assertEquals(len(all_posts), 0)
def test_delete_category(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Log in self.client.login(username='******', password="******") # Delete the category response = self.client.post('/admin/blogengine/category/1/delete/', { 'post': 'yes' }, follow=True) self.assertEquals(response.status_code, 200) # Check deleted successfully self.assertTrue('deleted successfully' in response.content) # Check category deleted all_categories = Category.objects.all() self.assertEquals(len(all_categories), 0)
def test_create_category(self): # Create the category category = Category() # Add attributes category.name = 'python' category.description = 'The Python programming language' category.slug = 'python' # Save it category.save() # Check we can find it all_categories = Category.objects.all() self.assertEquals(len(all_categories), 1) only_category = all_categories[0] self.assertEquals(only_category, category) # Check attributes self.assertEquals(only_category.name, 'python') self.assertEquals(only_category.description, 'The Python programming language') self.assertEquals(only_category.slug, 'python')
def test_delete_category(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Log in self.client.login(username='******', password="******") # Delete the category response = self.client.post('/admin/blog/category/1/delete/', {'post': 'yes'}, follow=True) self.assertEquals(response.status_code, 200) # Check excluído com sucesso self.assertTrue('excluído com sucesso' in response.content) # Check category deleted all_categories = Category.objects.all() self.assertEquals(len(all_categories), 0)
def test_create_post(self): category = Category() category.name = 'python' category.description = 'The python language' category.save() # Create the tag tag = Tag() tag.name = 'python' tag.description = 'The Python programming language' tag.save() self.client.login(username='******', password='******') response = self.client.get('/admin/blog/post/add/') self.assertEquals(response.status_code, 200) response = self.client.post('/admin/blog/post/add/', { 'title': 'First Post', 'text': 'My first post -yay', 'pub_date_0': '2014-07-17', 'pub_date_1': '11:41:03', 'slug': 'first-post', # 'site': '1', 'category': '1', 'tags': '1' }, follow=True ) self.assertEquals(response.status_code, 200) self.assertTrue('added successfully' in response.content) # Check the new post is in the database all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1)
def teste_create_post(self): # Create the tag tag = Tag() tag.name = 'python' tag.description = 'The Python programming language' tag.save() # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Create the author author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() # Create the site site = Site() site.name = 'example.com' site.domain = 'example.com' site.save() # cria o post post = Post() post.title = 'Meu primeiro post' post.text = 'Este é meu primeiro post do blog' post.slug = "my-first-post" post.pub_date = timezone.now() post.author = author post.site = site post.category = category # salva o post no banco de dados post.save() # Add the tag post.tags.add(tag) post.save() # verifica se conseguimos encontrá-lo all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) only_post = all_posts[0] self.assertEqual(only_post, post) # verifica os atributos self.assertEqual(only_post.title, 'Meu primeiro post') self.assertEqual(only_post.text, u'Este é meu primeiro post do blog') self.assertEqual(only_post.slug, 'my-first-post') self.assertEquals(only_post.site.name, 'example.com') self.assertEquals(only_post.site.domain, 'example.com') self.assertEqual(only_post.pub_date.day, post.pub_date.day) self.assertEqual(only_post.pub_date.month, post.pub_date.month) self.assertEqual(only_post.pub_date.year, post.pub_date.year) self.assertEqual(only_post.pub_date.hour, post.pub_date.hour) self.assertEqual(only_post.pub_date.minute, post.pub_date.minute) self.assertEqual(only_post.pub_date.second, post.pub_date.second) self.assertEquals(only_post.author.username, 'testuser') self.assertEquals(only_post.author.email, '*****@*****.**') self.assertEquals(only_post.category.name, 'python') self.assertEquals(only_post.category.description, 'The Python programming language') # Check tags post_tags = only_post.tags.all() self.assertEquals(len(post_tags), 1) only_post_tag = post_tags[0] self.assertEquals(only_post_tag, tag) self.assertEquals(only_post_tag.name, 'python') self.assertEquals(only_post_tag.description, 'The Python programming language')
def test_create_post(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Create the tag tag = Tag() tag.name = 'python' tag.description = 'The Python programming language' tag.save() # Create the author author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() # Create the site site = Site() site.name = 'example.com' site.domain = 'example.com' site.save() # Create the post post = Post() # Set the attributes post.title = 'My first post' post.text = 'This is my first blog post' post.slug = 'my-first-post' post.pub_date = timezone.now() post.author = author post.site = site post.category = category # Save it post.save() # Add the tag post.tags.add(tag) post.save() # Check we can find it all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) only_post = all_posts[0] self.assertEquals(only_post, post) # Check attributes self.assertEquals(only_post.title, 'My first post') self.assertEquals(only_post.text, 'This is my first blog post') self.assertEquals(only_post.slug, 'my-first-post') self.assertEquals(only_post.site.name, 'example.com') self.assertEquals(only_post.site.domain, 'example.com') self.assertEquals(only_post.pub_date.day, post.pub_date.day) self.assertEquals(only_post.pub_date.month, post.pub_date.month) self.assertEquals(only_post.pub_date.year, post.pub_date.year) self.assertEquals(only_post.pub_date.hour, post.pub_date.hour) self.assertEquals(only_post.pub_date.minute, post.pub_date.minute) self.assertEquals(only_post.pub_date.second, post.pub_date.second) self.assertEquals(only_post.author.username, 'testuser') self.assertEquals(only_post.author.email, '*****@*****.**') self.assertEquals(only_post.category.name, 'python') self.assertEquals(only_post.category.description, 'The Python programming language') # Check tags post_tags = only_post.tags.all() self.assertEquals(len(post_tags), 1) only_post_tag = post_tags[0] self.assertEquals(only_post_tag, tag) self.assertEquals(only_post_tag.name, 'python') self.assertEquals(only_post_tag.description, 'The Python programming language')
def test_edit_post(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Create the tag tag = Tag() tag.name = 'python' tag.description = 'The Python programming language' tag.save() # Create the author author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() # Create the site site = Site() site.name = 'example.com' site.domain = 'example.com' site.save() # Create the post post = Post() post.title = 'My first post' post.text = 'This is my first blog post' post.slug = 'my-first-post' post.pub_date = timezone.now() post.author = author post.site = site post.save() post.tags.add(tag) post.save() # Log in self.client.login(username='******', password="******") # Edit the post response = self.client.post('/admin/blogengine/post/1/', { 'title': 'My second post', 'text': 'This is my second blog post', 'pub_date_0': '2013-12-28', 'pub_date_1': '22:00:04', 'slug': 'my-second-post', 'site': '1', 'category': '1', 'tags': '1' }, follow=True ) self.assertEquals(response.status_code, 200) # Check changed successfully self.assertTrue('changed successfully' in response.content) # Check post amended all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) only_post = all_posts[0] self.assertEquals(only_post.title, 'My second post') self.assertEquals(only_post.text, 'This is my second blog post')
def test_edit_post(self): # Create the category category = Category() category.name = 'python' category.description = 'The Python programming language' category.save() # Create the tag tag = Tag() tag.name = 'python' tag.description = 'The Python programming language' tag.save() # Create the author author = User.objects.create_user('testuser', '*****@*****.**', 'password') author.save() # Create the site site = Site() site.name = 'example.com' site.domain = 'example.com' site.save() # Create the post post = Post() post.title = 'My first post' post.text = 'This is my first blog post' post.slug = 'my-first-post' post.pub_date = timezone.now() post.author = author post.site = site post.save() post.tags.add(tag) post.save() # Log in self.client.login(username='******', password="******") # Edit the post response = self.client.post('/admin/blog/post/1/', { 'title': 'My second post', 'text': 'This is my second blog post', 'pub_date_0': '2013-12-28', 'pub_date_1': '22:00:04', 'slug': 'my-second-post', 'site': '1', 'category': '1', 'tags': '1' }, follow=True) self.assertEquals(response.status_code, 200) # Check modificado com sucesso self.assertTrue('modificado com sucesso' in response.content) # Check post amended all_posts = Post.objects.all() self.assertGreater(len(all_posts), 0) only_post = all_posts[0] self.assertEquals(only_post.title, 'My second post') self.assertEquals(only_post.text, 'This is my second blog post')