Beispiel #1
0
 def test_registration_submit_schema_succeed(self):
     from flow.security.views import user_add
     from flow.security.models import User
     _register_routes(self.config)
     _register_common_templates(self.config)
     request = testing.DummyRequest(
         post={
             'form.submitted': u'Register',
             'username': u'username',
             'passphrase': u'secret',
             'confirm_passphrase': u'secret',
             'email': u'*****@*****.**',
             'name': u'John Doe',
         }
     )
     user_add(request)
     users = self.session.query(User).all()
     self.assertEqual(len(users), 1)
     user = users[0]
     self.assertEqual(user.username, u'username')
     self.assertEqual(user.name, u'John Doe')
     self.assertEqual(user.email, u'*****@*****.**')
     self.assertEqual(user.hits, 0)
     self.assertEqual(user.misses, 0)
     self.assertEqual(user.delivered_hits, 0)
     self.assertEqual(user.delivered_misses, 0)
     self.assertEqual(user.ideas, [])
     self.assertEqual(user.voted_ideas, [])
Beispiel #2
0
 def test_registration_nosubmit(self):
     from flow.security.views import user_add
     _register_routes(self.config)
     _register_common_templates(self.config)
     request = testing.DummyRequest()
     result = user_add(request)
     self.assertTrue('form' in result)
Beispiel #3
0
    def test_tag_view(self):
        from flow.shootout.views import tag_view
        from flow.shootout.models import Tag
        self.config.testing_securitypolicy(u'username')
        _register_routes(self.config)
        _register_common_templates(self.config)
        user = self._addUser()
        tag1 = Tag(u'bar')
        tag2 = Tag(u'foo')
        self.session.add_all([tag1, tag2])
        idea1 = self._addIdea(user=user)
        idea1.tags.append(tag1)
        idea2 = self._addIdea(user=user)
        idea2.tags.append(tag1)
        idea3 = self._addIdea(user=user)
        idea3.tags.append(tag2)
        self.session.flush()

        request = testing.DummyRequest()
        request.matchdict = {'tag_name': u'bar'}
        result = tag_view(request)
        ideas = result['ideas'].all()
        self.assertEqual(ideas[0].idea_id, idea1.idea_id)
        self.assertEqual(ideas[1].idea_id, idea2.idea_id)
        self.assertEqual(result['tag'], u'bar')

        request = testing.DummyRequest()
        request.matchdict = {'tag_name': u'foo'}
        result = tag_view(request)
        self.assertEqual(result['ideas'].one().idea_id, idea3.idea_id)
        self.assertEqual(result['tag'], u'foo')
Beispiel #4
0
 def test_idea_add_not_existing_target(self):
     from flow.shootout.views import idea_add
     self.config.testing_securitypolicy(u'username')
     _register_routes(self.config)
     _register_common_templates(self.config)
     request = testing.DummyRequest(params={'target': 100})
     result = idea_add(request)
     self.assertEqual(result.code, 404)
Beispiel #5
0
 def test_idea_add_nosubmit_idea(self):
     from flow.shootout.views import idea_add
     self.config.testing_securitypolicy(u'username')
     _register_routes(self.config)
     _register_common_templates(self.config)
     request = testing.DummyRequest()
     result = idea_add(request)
     self.assertEqual(result['target'], None)
     self.assertEqual(result['kind'], 'idea')
Beispiel #6
0
 def test_ideas_main(self):
     from flow.shootout.views import ideas_main
     self.config.testing_securitypolicy(u'username')
     _register_routes(self.config)
     _register_common_templates(self.config)
     request = testing.DummyRequest()
     result = ideas_main(request)
     self.assertEqual(result['username'], u'username')
     self.assertEqual(len(result['toplists']), 4)
Beispiel #7
0
 def test_idea_add_nosubmit_comment(self):
     from flow.shootout.views import idea_add
     self.config.testing_securitypolicy(u'username')
     _register_routes(self.config)
     _register_common_templates(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')
Beispiel #8
0
 def test_user_view(self):
     from flow.security.views import user_view
     self.config.testing_securitypolicy(u'username')
     _register_routes(self.config)
     _register_common_templates(self.config)
     request = testing.DummyRequest()
     request.matchdict = {'username': u'username'}
     self._addUser()
     result = user_view(request)
     self.assertEqual(result['user'].username, u'username')
     self.assertEqual(result['user'].user_id, 1)
Beispiel #9
0
 def test_idea_view(self):
     from flow.shootout.views import idea_view
     self.config.testing_securitypolicy(u'username')
     _register_routes(self.config)
     _register_common_templates(self.config)
     self._addIdea()
     request = testing.DummyRequest()
     request.matchdict = {'idea_id': 1}
     result = idea_view(request)
     self.assertEqual(result['idea'].title, u'title')
     self.assertEqual(result['idea'].idea_id, 1)
     self.assertEqual(result['viewer_username'], u'username')
Beispiel #10
0
 def test_idea_add_submit_schema_fail_empty_params(self):
     from flow.shootout.views import idea_add
     self.config.testing_securitypolicy(u'username')
     _register_routes(self.config)
     _register_common_templates(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'
         })
Beispiel #11
0
 def test_registration_submit_empty(self):
     from flow.security.views import user_add
     _register_routes(self.config)
     _register_common_templates(self.config)
     request = testing.DummyRequest()
     result = user_add(request)
     self.assertTrue('form' in result)
     request = testing.DummyRequest(post={'form.submitted': 'Shoot'})
     result = user_add(request)
     self.assertEqual(
         result['form'].form.errors,
         {
             'username': u'Missing value',
             'confirm_passphrase': u'Missing value',
             'passphrase': u'Missing value',
             'email': u'Missing value',
             'name': u'Missing value'
         }
     )