import datetime

from django.test import TestCase

from notorhot._tests.factories import mixer
from notorhot.models import CandidateCategory, Candidate, Competition

class NotorHotCategoryTestCase(TestCase):
    def test_category_publicity_manager(self):
        mixer.blend('notorhot.CandidateCategory', is_public=True)
        mixer.blend('notorhot.CandidateCategory', is_public=False)
        self.assertEqual(CandidateCategory.objects.count(), 2)
        self.assertEqual(CandidateCategory.public.count(), 1)

    def test_category_competition_generator(self):
        cat = mixer.blend('notorhot.CandidateCategory')
        enabled = mixer.cycle(3).blend('notorhot.Candidate', category=cat, is_enabled=True)
        disabled = mixer.cycle(2).blend('notorhot.Candidate', category=cat, is_enabled=False)
        
        comp = cat.generate_competition()
        self.assertTrue(comp.left in enabled)
        self.assertTrue(comp.right in enabled)
        self.assertEqual(comp.category, cat)
        
    def test_category_num_candidates(self):
        cat = mixer.blend('notorhot.CandidateCategory')
        mixer.cycle(3).blend('notorhot.Candidate', category=cat, is_enabled=True)
        mixer.cycle(2).blend('notorhot.Candidate', category=cat, is_enabled=False)
        self.assertEqual(cat.num_candidates, 3)
        
    def test_category_num_voted_comps(self):
        cat = mixer.blend('notorhot.CandidateCategory')
        mixer.cycle(3).blend('notorhot.Competition', category=cat, date_voted=None)
        mixer.cycle(2).blend('notorhot.Competition', category=cat, 
            date_voted=datetime.datetime.now())
        self.assertEqual(cat.num_voted_competitions, 2)
        
    
class NotorHotCandidateTestCase(TestCase):
    pass
    
    
class NotorHotCompetitionTestCase(TestCase):
    pass
@@ -1742,17 +1742,580 @@
     
-pass%0A    
+def test_order_by_wins(self):%0A        # test ordered by %25 wins, not # wins%0A        mixer.blend('notorhot.Candidate', votes=18, wins=9) # .5%0A        mixer.blend('notorhot.Candidate', votes=15, wins=8) # .5333%0A        mixer.blend('notorhot.Candidate', votes=12, wins=7) # .58333%0A        mixer.blend('notorhot.Candidate', votes=9, wins=6) # .6667%0A            %0A        in_order = Candidate.objects.all().order_by_wins()%0A        # get win count for ordered candidates = should be 6, 7, 8, 9%0A        wins = %5Bc.wins for c in in_order%5D%0A        self.assertEqual(wins, %5B6, 7, 8, 9%5D)
 %0A   

Test win percentage ordering.