示例#1
0
    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")
        self.config.include("shootout.addroutes")
        request = testing.DummyRequest(
            params={
                "form.submitted": u"Shoot",
                "tags": u"abc def, bar",
                "text": u"My comment is cool",
                "title": u"My comment",
                "target": unicode(idea.idea_id),
            }
        )
        request.method = "POST"
        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")
示例#2
0
 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')
     self.config.include('shootout.addroutes')
     request = testing.DummyRequest(
         params={
             'form.submitted': u'Shoot',
             'tags': u'abc def, bar',
             'text': u'My comment is cool',
             'title': u'My comment',
             'target': unicode(idea.idea_id),
         })
     request.method = 'POST'
     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')
示例#3
0
 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')
     self.config.include('shootout.addroutes')
     request = testing.DummyRequest(
         params={
             'form.submitted': u'Shoot',
             'tags': u'abc def, bar',
             'text': u'My comment is cool',
             'title': u'My comment',
             'target': unicode(idea.idea_id),
         }
     )
     request.method = 'POST'
     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')
示例#4
0
 def test_idea_add_not_existing_target(self):
     from shootout.views import idea_add
     self.config.testing_securitypolicy(u'username')
     _registerCommonTemplates(self.config)
     request = testing.DummyRequest(params={'target': 100})
     result = idea_add(request)
     self.assertEqual(result.code, 404)
示例#5
0
 def test_idea_add_submit_schema_succeed(self):
     from shootout.views import idea_add
     from shootout.models import Idea
     self.config.testing_securitypolicy('username')
     _registerRoutes(self.config)
     request = testing.DummyRequest(
         post={
             'form.submitted': u'Shoot',
             'tags': u'abc def, bar',
             'text': u'My idea is cool',
             'title': u'My idea',
         }
     )
     user = self._addUser(u'username')
     result = idea_add(request)
     self.assertEqual(result.location, 'http://example.com/ideas/1')
     ideas = self.session.query(Idea).all()
     self.assertEqual(len(ideas), 1)
     idea = ideas[0]
     self.assertEqual(idea.idea_id, 1)
     self.assertEqual(idea.text, u'My idea is cool')
     self.assertEqual(idea.title, u'My idea')
     self.assertEqual(idea.author, user)
     self.assertEqual(len(idea.tags), 3)
     self.assertEqual(idea.tags[0].name, u'abc')
     self.assertEqual(idea.tags[1].name, u'bar')
     self.assertEqual(idea.tags[2].name, u'def')
示例#6
0
 def test_idea_add_not_existing_target(self):
     from shootout.views import idea_add
     self.config.testing_securitypolicy(u'username')
     self.config.include(register_templates)
     request = testing.DummyRequest(params={'target': 100})
     result = idea_add(request)
     self.assertEqual(result.code, 404)
示例#7
0
 def test_idea_add_submit_schema_succeed(self):
     from shootout.views import idea_add
     from shootout.models import Idea
     self.config.testing_securitypolicy(u'username')
     self.config.include('shootout.addroutes')
     request = testing.DummyRequest(
         post={
             'form.submitted': u'Shoot',
             'tags': u'abc def, bar',
             'text': u'My idea is cool',
             'title': u'My idea',
         })
     user = self._addUser(u'username')
     result = idea_add(request)
     self.assertEqual(result.location, 'http://example.com/ideas/1')
     ideas = self.session.query(Idea).all()
     self.assertEqual(len(ideas), 1)
     idea = ideas[0]
     self.assertEqual(idea.idea_id, 1)
     self.assertEqual(idea.text, u'My idea is cool')
     self.assertEqual(idea.title, u'My idea')
     self.assertEqual(idea.author, user)
     self.assertEqual(len(idea.tags), 3)
     self.assertEqual(idea.tags[0].name, u'abc')
     self.assertEqual(idea.tags[1].name, u'bar')
     self.assertEqual(idea.tags[2].name, u'def')
示例#8
0
 def test_idea_add_nosubmit_idea(self):
     from shootout.views import idea_add
     self.config.testing_securitypolicy('username')
     _registerCommonTemplates(self.config)
     request = testing.DummyRequest()
     result = idea_add(request)
     self.assertEqual(result['target'], None)
     self.assertEqual(result['kind'], 'idea')
示例#9
0
 def test_idea_add_nosubmit_idea(self):
     from shootout.views import idea_add
     self.config.testing_securitypolicy(u'username')
     self.config.include(register_templates)
     request = testing.DummyRequest()
     result = idea_add(request)
     self.assertEqual(result['target'], None)
     self.assertEqual(result['kind'], 'idea')
示例#10
0
 def test_idea_add_not_existing_target(self):
     from shootout.views import idea_add
     from pyramid.httpexceptions import HTTPNotFound
     self.config.testing_securitypolicy('username')
     _registerCommonTemplates(self.config)
     request = testing.DummyRequest(params={'target': 100})
     result = idea_add(request)
     self.assertEqual(result.code, 404)
示例#11
0
    def test_idea_add_not_existing_target(self):
        from shootout.views import idea_add

        self.config.testing_securitypolicy(u"username")
        self.config.include(register_templates)
        request = testing.DummyRequest(params={"target": 100})
        result = idea_add(request)
        self.assertEqual(result.code, 404)
示例#12
0
 def test_idea_add_nosubmit_comment(self):
     from shootout.views import idea_add
     self.config.testing_securitypolicy('username')
     _registerCommonTemplates(self.config)
     idea = self._addIdea()
     request = testing.DummyRequest(params={'target': idea.idea_id})
     result = idea_add(request)
     self.assertEqual(result['target'], idea)
     self.assertEqual(result['kind'], 'comment')
示例#13
0
 def test_idea_add_nosubmit_comment(self):
     from shootout.views import idea_add
     self.config.testing_securitypolicy(u'username')
     self.config.include(register_templates)
     idea = self._addIdea()
     request = testing.DummyRequest(params={'target': idea.idea_id})
     result = idea_add(request)
     self.assertEqual(result['target'], idea)
     self.assertEqual(result['kind'], 'comment')
示例#14
0
    def test_idea_add_nosubmit_idea(self):
        from shootout.views import idea_add

        self.config.testing_securitypolicy(u"username")
        self.config.include(register_templates)
        request = testing.DummyRequest()
        result = idea_add(request)
        self.assertEqual(result["target"], None)
        self.assertEqual(result["kind"], "idea")
示例#15
0
    def test_idea_add_nosubmit_comment(self):
        from shootout.views import idea_add

        self.config.testing_securitypolicy(u"username")
        self.config.include(register_templates)
        idea = self._addIdea()
        request = testing.DummyRequest(params={"target": idea.idea_id})
        result = idea_add(request)
        self.assertEqual(result["target"], idea)
        self.assertEqual(result["kind"], "comment")
示例#16
0
    def test_idea_add_submit_schema_fail_empty_params(self):
        from shootout.views import idea_add

        self.config.testing_securitypolicy(u"username")
        self.config.include(register_templates)
        self.config.include("shootout.addroutes")
        request = testing.DummyRequest(post={"form.submitted": "Shoot"})
        result = idea_add(request)
        self.assertEqual(
            result["form"].form.errors, {"text": u"Missing value", "tags": u"Missing value", "title": u"Missing value"}
        )
示例#17
0
 def test_idea_add_submit_schema_fail_empty_params(self):
     from shootout.views import idea_add
     self.config.testing_securitypolicy(u'username')
     self.config.include(register_templates)
     self.config.include('shootout.addroutes')
     request = testing.DummyRequest(post={'form.submitted': 'Shoot'})
     result = idea_add(request)
     self.assertEqual(
         result['form'].form.errors, {
             'text': u'Missing value',
             'tags': u'Missing value',
             'title': u'Missing value'
         })
示例#18
0
 def test_idea_add_submit_schema_fail_empty_params(self):
     from shootout.views import idea_add
     self.config.testing_securitypolicy('username')
     _registerCommonTemplates(self.config)
     _registerRoutes(self.config)
     request = testing.DummyRequest(post={'form.submitted': 'Shoot'})
     result = idea_add(request)
     self.assertEqual(
         result['form'].form.errors,
         {
             'text': u'Missing value',
             'tags': u'Missing value',
             'title': u'Missing value'
         }
     )
示例#19
0
    def test_idea_add_submit_schema_succeed(self):
        from shootout.views import idea_add
        from shootout.models import Idea

        self.config.testing_securitypolicy(u"username")
        self.config.include("shootout.addroutes")
        request = testing.DummyRequest(
            post={"form.submitted": u"Shoot", "tags": u"abc def, bar", "text": u"My idea is cool", "title": u"My idea"}
        )
        user = self._addUser(u"username")
        result = idea_add(request)
        self.assertEqual(result.location, "http://example.com/ideas/1")
        ideas = self.session.query(Idea).all()
        self.assertEqual(len(ideas), 1)
        idea = ideas[0]
        self.assertEqual(idea.idea_id, 1)
        self.assertEqual(idea.text, u"My idea is cool")
        self.assertEqual(idea.title, u"My idea")
        self.assertEqual(idea.author, user)
        self.assertEqual(len(idea.tags), 3)
        self.assertEqual(idea.tags[0].name, u"abc")
        self.assertEqual(idea.tags[1].name, u"bar")
        self.assertEqual(idea.tags[2].name, u"def")