def test_results_index__with_votes(self):
        from nuorisovaalit.models import Candidate
        from nuorisovaalit.models import School
        from nuorisovaalit.models import Vote
        from nuorisovaalitadmin.views.allianssi import results_index

        self.config.add_route('results_total_xls', '/results-total.xls')
        session = DBSession()
        populate_testing_db()

        candidate = session.query(Candidate).first()
        school = session.query(School)\
                 .filter_by(district_id=candidate.district_id)\
                 .first()
        self.assertTrue(candidate is not None)
        self.assertTrue(school is not None)

        self.assertEquals(0, session.query(Vote).count())

        session.add(Vote(candidate, school, Vote.PAPER, 15))
        session.add(Vote(candidate, school, Vote.ELECTRONIC))
        session.add(Vote(candidate, school, Vote.ELECTRONIC))

        options = results_index(DummyRequest())
        options.pop('voted')
        options.pop('not_voted')

        self.assertEquals({
            'title': u'Tulokset',
            'vote_count_total': 17,
            'vote_count_electronic': 2,
            'results_total_xls': 'http://example.com/results-total.xls',
        }, options)
    def test_results_index__no_votes(self):
        from nuorisovaalit.models import Vote
        from nuorisovaalitadmin.views.allianssi import results_index

        self.config.add_route('results_total_xls', '/results-total.xls')
        session = DBSession()
        populate_testing_db()

        self.assertEquals(0, session.query(Vote).count())

        self.assertEquals({
            'title': u'Tulokset',
            'vote_count_total': 0,
            'vote_count_electronic': 0,
            'voted': '0.00',
            'not_voted': '100.00',
            'results_total_xls': 'http://example.com/results-total.xls',
        }, results_index(DummyRequest()))