def test_post_no_title(self):
        self.users_login('admin@localhost', is_admin=True)
        data = {'tagline': 'new_tagline'}

        self.client.post(self.url, data)

        self.assertEqual(Blog.get_unique().title, 'blog_title')
        self.assertEqual(Blog.get_unique().tagline, 'blog_tagline')
 def get_context_data(self, *args, **kwargs):
     context = super(BlogMixin, self).get_context_data(*args, **kwargs)
     blog = Blog.get_unique()
     context.update({
         'blog': blog,
         'active_user': users.get_current_user(),
         'is_admin': users.is_current_user_admin()
     })
     return context
    def test_post_valid(self):
        self.users_login('admin@localhost', is_admin=True)
        data = {'title': 'new_blog_title', 'tagline': 'new_tagline'}

        resp = self.client.post(self.url, data)

        blog = Blog.get_unique()
        self.assertRedirects(resp, reverse('index'))
        self.assertEqual(blog.title, 'new_blog_title')
        self.assertEqual(blog.tagline, 'new_tagline')
def create():
    form = BlogForm()
    if request.method == 'POST' and form.validate_on_submit():
        f = form.image.data
        file_path = save_file(f)
        blog = Blog(title=form.title.data, description=form.description.data, image=file_path, user_id=current_user.id)
        db.session.add(blog)
        db.session.commit()
        flash('Melumat elave edildi')
        return redirect('/')
    context = {
        'form': form
    }
    return render_template('core/create.html', **context)
 def test_get_unique_one_blogs(self):
     create_blog(title='Existing Blog', tagline='123')
     blog = Blog.get_unique()
     self.assertEqual(blog.title, 'Existing Blog')
     self.assertEqual(blog.tagline, '123')
     self.assertEqual(Blog.objects.all().count(), 1)
 def test_get_unique_no_blogs(self):
     blog = Blog.get_unique()
     self.assertEqual(blog.title, 'My Blog')
     self.assertEqual(blog.tagline, None)
     self.assertEqual(Blog.objects.all().count(), 1)
 def get_object(self):
     return Blog.get_unique()