def test_view_election(self):
     request = self._get_request()
     request.POST['username'] = '******'
     request.POST['password'] = '******'
     response = auth(request)
     auth_session = request.session
     self.assertTrue(auth_session['authentication'].is_authenticated())
     request = self._get_request()
     request.session = auth_session
     request.POST['name'] = 'Test'
     request.POST['body'] = 'An election for testing.'
     request.POST['method'] = 'TestMethod'
     response = create_election(request)
     self.assertEqual(response.status_int, 302)
     requet = self._get_request()
     request.session = auth_session
     response = view_all_elections(request)
     self.assertEqual(len(response), 3)
     self.assertEqual(response['Test']['name'], 'Test')
     self._get_request()
     request.session = auth_session
     request.url = response['Test']['view_url']
     uuid = DBSession.query(Election).filter_by(name='Test').first().id.urn
     request.matchdict['election_id'] = uuid
     response = view_election(request)
     self.assertEqual(response['name'], 'Test')
     self.assertEqual(response['body'], 'An election for testing.')
     self.assertEqual(response['method']['name'], 'Test Method')
 def test_create_election(self):
     request = self._get_request() 
     request.POST['username'] = '******'
     request.POST['password'] = '******'
     response = auth(request)
     auth_session = request.session
     self.assertTrue(auth_session['authentication'].is_authenticated())
     request = self._get_request() 
     request.session = auth_session
     request.POST['name'] = 'Test'
     request.POST['body'] = 'An election for testing.'
     request.POST['method'] = 'TestMethod'
     response = create_election(request)
     self.assertEqual(response.status_int, 302)
 def test_create_election_no_auth(self):
     request = self._get_request()
     response = create_election(request)
     self.assertEqual(response.status_int, 401)