Permalink
Browse files

Merge branch 'comment_fix' of github.com:brodul/shootout into brodul-…

…comment_fix
  • Loading branch information...
2 parents 513e57c + bfff163 commit aa2c86d7c4a95930f69f163241905128776c5686 @mcdonc mcdonc committed Feb 10, 2013
Showing with 32 additions and 2 deletions.
  1. +31 −0 shootout/tests/test_views.py
  2. +1 −2 shootout/views.py
@@ -130,6 +130,37 @@ def test_idea_add_submit_schema_succeed(self):
self.assertEqual(idea.tags[1].name, u'bar')
self.assertEqual(idea.tags[2].name, u'def')
+ def test_comment_add_submit_schema_succeed(self):
+ from shootout.views import idea_add
+ from shootout.models import Idea
+ idea = self._addIdea()
+ self.config.testing_securitypolicy(u'commentator')
+ _registerRoutes(self.config)
+ request = testing.DummyRequest(
+ post={
+ 'form.submitted': u'Shoot',
+ 'tags': u'abc def, bar',
+ 'text': u'My comment is cool',
+ 'title': u'My comment',
+ 'target': unicode(idea.idea_id),
+ }
+ )
+ user = self._addUser(u'commentator')
+ result = idea_add(request)
+ self.assertEqual(result.location, 'http://example.com/ideas/2')
+ ideas = self.session.query(Idea).all()
+ self.assertEqual(len(ideas), 2)
+ comment = ideas[1]
+ self.assertEqual(comment.idea_id, 2)
+ self.assertEqual(comment.target_id, 1)
+ self.assertEqual(comment.text, u'My comment is cool')
+ self.assertEqual(comment.title, u'My comment')
+ self.assertEqual(comment.author, user)
+ self.assertEqual(len(comment.tags), 3)
+ self.assertEqual(comment.tags[0].name, u'abc')
+ self.assertEqual(comment.tags[1].name, u'bar')
+ self.assertEqual(comment.tags[2].name, u'def')
+
def test_vote_on_own_idea(self):
from shootout.views import idea_vote
from shootout.models import User
View
@@ -139,7 +139,7 @@ class AddIdeaSchema(formencode.Schema):
@view_config(permission='post', route_name='idea_add',
renderer='templates/idea_add.pt')
def idea_add(request):
- target = request.GET.get('target')
+ target = request.POST.get('target') or request.GET.get('target')
session = DBSession()
if target:
target = Idea.get_by_id(target, with_joinedload=False)
@@ -301,4 +301,3 @@ def cloud_view(request):
cloud = sorted(totalcounts, key=itemgetter(0))
return render('templates/cloud.pt', {'cloud': cloud}, request)
-

0 comments on commit aa2c86d

Please sign in to comment.