def test_get_stats(self): """ Test the get_stats function. """ create_elections(self.session) create_candidates(self.session) create_votes(self.session) stats = nuancierlib.get_stats(self.session, 1) self.assertEqual(5, stats['votes']) self.assertEqual(3, stats['voters']) self.assertEqual([[1, 1], [2, 2]], stats['data'])
def stats(election_id): ''' Return some stats about this election. ''' election = nuancierlib.get_election(SESSION, election_id) if not election: flask.flash('No election found', 'error') return flask.render_template('msg.html') if not election.election_public: flask.flash('The results this election are not public yet', 'error') return flask.redirect(flask.url_for('results_list')) statsinfo = nuancierlib.get_stats(SESSION, election_id) return flask.render_template('stats.html', stats=statsinfo, election=election)
def stats(election_id): ''' Return some stats about this election. ''' election = nuancierlib.get_election(SESSION, election_id) if not election: flask.flash('No election found', 'error') return flask.render_template('msg.html') if not election.election_public: flask.flash('The results this election are not public yet', 'error') return flask.redirect(flask.url_for('results_list')) statsinfo = nuancierlib.get_stats(SESSION, election_id) return flask.render_template( 'stats.html', stats=statsinfo, election=election)