def test_get_votes_user(self): """ Test the get_votes_user function. """ create_elections(self.session) create_candidates(self.session) create_votes(self.session) votes = nuancierlib.get_votes_user(self.session, 1, 'pingou') self.assertEqual(2, len(votes)) self.assertEqual(1, votes[0].candidate_id) self.assertEqual(2, votes[1].candidate_id)
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 test_votes_repr(self): """ Test the __repr__ function of Votes. """ create_elections(self.session) create_candidates(self.session) create_votes(self.session) votes = nuancierlib.get_votes_user(self.session, 1, 'pingou') self.assertTrue( votes[0].__repr__().startswith( "Votes(name:u'pingou', candidate_id:1, created:" ) )
def test_get_results(self): """ Test the get_results function. """ create_elections(self.session) create_candidates(self.session) create_votes(self.session) results = nuancierlib.get_results(self.session, 1) self.assertEqual(2, len(results)) self.assertEqual('Image ok', results[0][0].candidate_name) # candidate self.assertEqual(3, results[0][1]) # number of votes self.assertEqual('Image too narrow', results[1][0].candidate_name) self.assertEqual(2, results[1][1])
def test_votes_repr(self): """ Test the __repr__ function of Votes. """ create_elections(self.session) create_candidates(self.session) create_votes(self.session) votes = nuancierlib.get_votes_user(self.session, 1, 'pingou') if six.PY2: self.assertTrue(votes[0].__repr__().startswith( "Votes(name:u'pingou', candidate_id:1, created:")) else: self.assertTrue(votes[0].__repr__().startswith( "Votes(name:'pingou', candidate_id:1, created:"))