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_elections_api_repr(self): """ Test the api_repr function of Elections. """ create_elections(self.session) create_candidates(self.session) election = nuancierlib.get_election(self.session, 1) self.assertEqual( election.api_repr(1), {'name': 'Wallpaper F19', 'year': 2013} )
def test_candidates_api_repr(self): """ Test the api_repr function of Elections. """ create_elections(self.session) create_candidates(self.session) candidate = nuancierlib.get_candidate(self.session, 1) self.assertEqual( candidate.api_repr(1), {'election': u'Wallpaper F19', 'name': u'DSC_0951'} )
def test_get_candidate(self): """ Test the get_candidate function. """ create_elections(self.session) create_candidates(self.session) candidate = nuancierlib.get_candidate(self.session, 1) self.assertEqual('DSC_0951', candidate.candidate_name) candidate = nuancierlib.get_candidate(self.session, 4) self.assertEqual('DSC_0922', candidate.candidate_name)
def test_get_candidate(self): """ Test the get_candidate function. """ create_elections(self.session) create_candidates(self.session) candidate = nuancierlib.get_candidate(self.session, 1) self.assertEqual('Image ok', candidate.candidate_name) candidate = nuancierlib.get_candidate(self.session, 10) self.assertEqual(None, candidate)
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_elections_repr(self): """ Test the __repr__ function of Elections. """ create_elections(self.session) create_candidates(self.session) election = nuancierlib.get_election(self.session, 1) self.assertEqual( election.__repr__(), "Elections(id:1, name:u'Wallpaper F19', year:2013)" )
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_candidates_repr(self): """ Test the __repr__ function of Candidates. """ create_elections(self.session) create_candidates(self.session) candidate = nuancierlib.get_candidate(self.session, 1) self.assertTrue( candidate.__repr__().startswith( "Candidates(file:u'DSC_0951.JPG', " "name:u'DSC_0951', " "election_id: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:"))
def test_get_candidates(self): """ Test the get_candidates function. """ create_elections(self.session) create_candidates(self.session) candidates = nuancierlib.get_candidates(self.session, 1) self.assertEqual(2, len(candidates)) self.assertEqual('DSC_0930', candidates[0].candidate_name) self.assertEqual('DSC_0951', candidates[1].candidate_name) candidates = nuancierlib.get_candidates(self.session, 2) self.assertEqual(2, len(candidates)) self.assertEqual('DSC_0922', candidates[0].candidate_name) self.assertEqual('DSC_0923', candidates[1].candidate_name)
def test_elections_repr(self): """ Test the __repr__ function of Elections. """ create_elections(self.session) create_candidates(self.session) election = nuancierlib.get_election(self.session, 1) if six.PY2: self.assertEqual( election.__repr__(), "Elections(id:1, name:u'Wallpaper F19', year:2013)") else: self.assertEqual( election.__repr__(), "Elections(id:1, name:'Wallpaper F19', year:2013)")
def test_add_vote(self): """ Test the add_vote function. """ create_elections(self.session) create_candidates(self.session) nuancierlib.add_vote(session=self.session, candidate_id=2, username='******') self.session.commit() votes = nuancierlib.get_votes_user(self.session, 1, 'pingou') self.assertEqual(1, len(votes)) self.assertEqual(2, votes[0].candidate_id)
def test_candidates_api_repr(self): """ Test the api_repr function of Elections. """ create_elections(self.session) create_candidates(self.session) candidate = nuancierlib.get_candidate(self.session, 1) self.assertEqual( candidate.api_repr(1), { 'author': u'pingou', 'license': u'CC-BY-SA', 'name': u'Image ok', 'original_url': None, 'submitter': u'pingou', })
def test_candidates_repr(self): """ Test the __repr__ function of Candidates. """ create_elections(self.session) create_candidates(self.session) candidate = nuancierlib.get_candidate(self.session, 1) if six.PY2: self.assertTrue(candidate.__repr__().startswith( "Candidates(file:u'ok.JPG', " "name:u'Image ok', " "election_id:1, ")) else: self.assertTrue(candidate.__repr__().startswith( "Candidates(file:'ok.JPG', " "name:'Image ok', " "election_id:1, "))
def test_add_vote(self): """ Test the add_vote function. """ create_elections(self.session) create_candidates(self.session) nuancierlib.add_vote( session=self.session, candidate_id=2, username='******' ) self.session.commit() votes = nuancierlib.get_votes_user(self.session, 1, 'pingou') self.assertEqual(1, len(votes)) self.assertEqual(2, votes[0].candidate_id)
def test_elections_api_repr(self): """ Test the api_repr function of Elections. """ create_elections(self.session) create_candidates(self.session) election = nuancierlib.get_election(self.session, 1) self.assertEqual( election.api_repr(1), { 'date_end': TODAY - timedelta(days=8), 'date_start': TODAY - timedelta(days=10), 'id': 1, 'name': u'Wallpaper F19', 'submission_date_start': TODAY - timedelta(days=15), 'submission_date_end': TODAY - timedelta(days=13), 'year': 2013 })
def test_generate_cache(self): """ Test the generate_cache function. """ create_elections(self.session) create_candidates(self.session) election = nuancierlib.get_election(self.session, 2) self.assertFalse(os.path.exists(CACHE_FOLDER)) nuancierlib.generate_cache(session=self.session, election=election, picture_folder=PICTURE_FOLDER, cache_folder=CACHE_FOLDER, size=(128, 128)) self.assertTrue(os.path.exists(CACHE_FOLDER))
def test_candidates_api_repr(self): """ Test the api_repr function of Elections. """ create_elections(self.session) create_candidates(self.session) candidate = nuancierlib.get_candidate(self.session, 1) self.assertEqual( candidate.api_repr(1), { 'author': u'pingou', 'license': u'CC-BY-SA', 'name': u'Image ok', 'original_url': None, 'submitter': u'pingou', } )
def test_elections_api_repr(self): """ Test the api_repr function of Elections. """ create_elections(self.session) create_candidates(self.session) election = nuancierlib.get_election(self.session, 1) self.assertEqual( election.api_repr(1), { 'date_end': TODAY - timedelta(days=8), 'date_start': TODAY - timedelta(days=10), 'id': 1, 'name': u'Wallpaper F19', 'submission_date_start': TODAY - timedelta(days=15), 'year': 2013 } )
def test_generate_cache(self): """ Test the generate_cache function. """ create_elections(self.session) create_candidates(self.session) election = nuancierlib.get_election(self.session, 2) self.assertFalse(os.path.exists(CACHE_FOLDER)) nuancierlib.generate_cache( session=self.session, election=election, picture_folder=PICTURE_FOLDER, cache_folder=CACHE_FOLDER, size=(128, 128) ) self.assertTrue(os.path.exists(CACHE_FOLDER))
def test_get_candidates(self): """ Test the get_candidates function. """ create_elections(self.session) create_candidates(self.session) candidates = nuancierlib.get_candidates(self.session, 1, False) self.assertEqual(2, len(candidates)) self.assertEqual('Image too narrow', candidates[0].candidate_name) self.assertEqual('Image ok', candidates[1].candidate_name) candidates = nuancierlib.get_candidates(self.session, 1, True) self.assertEqual(0, len(candidates)) candidates = nuancierlib.get_candidates(self.session, 3, False) self.assertEqual(2, len(candidates)) self.assertEqual('Image too small2.0', candidates[0].candidate_name) self.assertEqual('Image too small2.1', candidates[1].candidate_name) candidates = nuancierlib.get_candidates(self.session, 2, True) self.assertEqual(0, len(candidates))
def test_candidates_repr(self): """ Test the __repr__ function of Candidates. """ create_elections(self.session) create_candidates(self.session) candidate = nuancierlib.get_candidate(self.session, 1) if six.PY2: self.assertTrue( candidate.__repr__().startswith( "Candidates(file:u'ok.JPG', " "name:u'Image ok', " "election_id:1, " ) ) else: self.assertTrue( candidate.__repr__().startswith( "Candidates(file:'ok.JPG', " "name:'Image ok', " "election_id:1, " ) )
def test_get_candidates(self): """ Test the get_candidates function. """ create_elections(self.session) create_candidates(self.session) candidates = nuancierlib.get_candidates(self.session, 1, False) self.assertEqual(2, len(candidates)) self.assertEqual('Image too narrow', candidates[0].candidate_name) self.assertEqual('Image ok', candidates[1].candidate_name) candidates = nuancierlib.get_candidates(self.session, 1, True) self.assertEqual(0, len(candidates)) candidates = nuancierlib.get_candidates(self.session, 3, False) self.assertEqual(4, len(candidates)) self.assertEqual('Image too small2.0', candidates[0].candidate_name) self.assertEqual('Image too small2.1', candidates[1].candidate_name) self.assertEqual('Image too small2.2', candidates[2].candidate_name) self.assertEqual('Image too small2.3', candidates[3].candidate_name) candidates = nuancierlib.get_candidates(self.session, 2, True) self.assertEqual(0, len(candidates))