class PostTestCase(unittest.TestCase): def setUp(self): self.server = Server(settings.COUCHDB_SERVER) try: self.db = self.server.create('comfy_blog_test') except: self.db = self.server['comfy_blog_test'] self.post1 = Post(title=u"Hello, World!", slug=u"foo-bar", published=datetime(2008, 8, 8), author={'name': 'Myles Braithwaite', 'email': '*****@*****.**'}) self.post2 = Post(title=u"Hello, World!", published=datetime(2007, 7, 7)) self.post1.store() self.post2.store() def testURL(self): self.assertEquals(self.post1.get_absolute_url(), '/blog/2008/8/8/foo-bar/') self.assertEquals(self.post2.get_absolute_url(), '/blog/2007/7/7/hello-world/') def testSlugify(self): self.assertEquals(self.post2.slug, 'hello-world') #def testAddComment(self): # post = Post.load(self.db, self.post1.id) # coment = post.comments() # comment.author = {'name': u"Myles Braithwaite", 'email': "*****@*****.**", 'url': u"http://mylesbraithwaite.com/"} # comment.comment = u"Hello, World!" # comment.time = datetime.now() # comment.user_agent = u"Python Unit Test" # comment.ip_address = u"127.0.0.1" # comment.is_spam = False # post.store() # # TODO Still working on doing something here to see if the test actually worked. def tearDown(self): del self.server['comfy_blog_test']
def post_add_edit(request, id=None): if id: post = Post.load(db, id) form = PostForm(initial={ 'title': post.title, 'slug': post.slug, 'body': post.body, 'published': post.published, 'tags': ', '.join(post.tags), 'allow_comments': post.allow_comments, 'allow_pings': post.allow_pings }) add = False else: post = None form = PostForm() add = True if request.method == 'POST': new_data = request.POST.copy() form = PostForm(new_data) if form.is_valid(): if add: # Adding a new Post post = Post() post.title = form.cleaned_data['title'] post.slug = form.cleaned_data['slug'] post.body = form.cleaned_data['body'] post.published = form.cleaned_data['published'] post.tags = form.cleaned_data['tags'] post.allow_comments = form.cleaned_data['allow_comments'] post.allow_pings = form.cleaned_data['allow_pings'] post.store() else: # Updating a new Post post = Post.load(db, id) post.title = form.cleaned_data['title'] post.slug = form.cleaned_data['slug'] post.body = form.cleaned_data['body'] post.published = form.cleaned_data['published'] post.tags = form.cleaned_data['tags'] post.allow_comments = form.cleaned_data['allow_comments'] post.allow_pings = form.cleaned_data['allow_pings'] post.store() return render_to_response('comfy_admin/blog/posts/post_add_edit.html', { 'title': u'%s %s' % (add and _('Add') or _('Edit'), _('page')), 'post': post, 'form': form, 'add': add, }, context_instance=RequestContext(request))