<s> """<STR_LIT>""" <EOL> from datetime import datetime , timedelta <EOL> from django . http import HttpRequest <EOL> from django . utils . timezone import utc <EOL> from django . test import TestCase <EOL> from guardian . models import User <EOL> from guardian . shortcuts import assign_perm <EOL> from nose . tools import assert_equals <EOL> from cardbox . card_model import Card <EOL> from cardbox . deck_model import Deck <EOL> from deckglue . models import DelayablePractice <EOL> from deckglue . views import PracticeDeckList , next_practice_item <EOL> def delayCard ( dpid ) : <EOL> dp = DelayablePractice . objects . get ( id = dpid ) <EOL> dp . next_practice = datetime . utcnow ( ) . replace ( tzinfo = utc ) + timedelta ( minutes = <NUM_LIT:1000> ) <EOL> dp . save ( ) <EOL> return dp <EOL> def makeCardDue ( dpid , in_minutes ) : <EOL> dp = DelayablePractice . objects . get ( id = dpid ) <EOL> dp . next_practice = datetime . utcnow ( ) . replace ( tzinfo = utc ) - timedelta ( minutes = in_minutes ) <EOL> dp . save ( ) <EOL> return dp <EOL> class PracticeDeckListTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_get_query_no_decks ( self ) : <EOL> """<STR_LIT>""" <EOL> testuser = User . objects . create ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> dl = PracticeDeckList ( ) <EOL> dl . request = HttpRequest ( ) <EOL> dl . request . user = testuser <EOL> lod = dl . get_queryset ( ) <EOL> assert_equals ( lod . count ( ) , <NUM_LIT:0> ) <EOL> def test_get_query_one_deck ( self ) : <EOL> """<STR_LIT>""" <EOL> dl = PracticeDeckList ( ) <EOL> dl . request = HttpRequest ( ) <EOL> dl . request . user = User . objects . get ( username = "<STR_LIT>" ) <EOL> lod = dl . get_queryset ( ) <EOL> assert_equals ( lod . count ( ) , <NUM_LIT:1> ) <EOL> def test_get_query_percentage_due_0_no_cards ( self ) : <EOL> """<STR_LIT>""" <EOL> testuser = User . objects . create ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> testdeck = Deck . objects . create ( ID = <NUM_LIT:3> , title = "<STR_LIT>" , description = "<STR_LIT:test>" ) <EOL> assign_perm ( '<STR_LIT>' , testuser , testdeck ) <EOL> dl = PracticeDeckList ( ) <EOL> dl . request = HttpRequest ( ) <EOL> dl . request . user = testuser <EOL> lod = dl . get_queryset ( ) <EOL> assert_equals ( lod [ <NUM_LIT:0> ] . due_percentage , <NUM_LIT:0> ) <EOL> def test_get_query_percentage_due_0_all_cards_learned ( self ) : <EOL> """<STR_LIT>""" <EOL> dl = PracticeDeckList ( ) <EOL> dl . request = HttpRequest ( ) <EOL> dl . request . user = User . objects . get ( username = "<STR_LIT>" ) <EOL> delayCard ( <NUM_LIT:1> ) <EOL> delayCard ( <NUM_LIT:2> ) <EOL> lod = dl . get_queryset ( ) <EOL> assert_equals ( lod [ <NUM_LIT:0> ] . due_percentage , <NUM_LIT:0> ) <EOL> def test_get_query_percentage_due_100_all_cards_due ( self ) : <EOL> """<STR_LIT>""" <EOL> dl = PracticeDeckList ( ) <EOL> dl . request = HttpRequest ( ) <EOL> dl . request . user = User . objects . get ( username = "<STR_LIT>" ) <EOL> lod = dl . get_queryset ( ) <EOL> assert_equals ( lod [ <NUM_LIT:0> ] . due_percentage , <NUM_LIT:100> ) <EOL> class NextPracticeTemplateTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def getNextPracticeTemplate ( self ) : <EOL> npi = next_practice_item ( ) <EOL> npi . template_name = "<STR_LIT>" <EOL> npi . request = HttpRequest ( ) <EOL> npi . request . user = User . objects . get ( username = "<STR_LIT>" ) <EOL> return npi <EOL> def test_get_cards_when_cards_due ( self ) : <EOL> """<STR_LIT>""" <EOL> npi = npi = self . getNextPracticeTemplate ( ) <EOL> makeCardDue ( <NUM_LIT:1> , <NUM_LIT:10> ) <EOL> itms = npi . get ( npi . request , deck_id = <NUM_LIT:1> ) <EOL> text = str ( itms . render ( ) ) <EOL> assert_equals ( "<STR_LIT>" in text , True ) <EOL> def test_get_cards_when_force ( self ) : <EOL> """<STR_LIT>""" <EOL> npi = self . getNextPracticeTemplate ( ) <EOL> delayCard ( <NUM_LIT:1> ) <EOL> delayCard ( <NUM_LIT:2> ) <EOL> itms = npi . get ( npi . request , deck_id = <NUM_LIT:1> ) <EOL> assert_equals ( "<STR_LIT>" in str ( itms ) , True ) <EOL> def test_get_cards_when_force ( self ) : <EOL> """<STR_LIT>""" <EOL> npi = self . getNextPracticeTemplate ( ) <EOL> delayCard ( <NUM_LIT:1> ) <EOL> delayCard ( <NUM_LIT:2> ) <EOL> itms = npi . get ( npi . request , deck_id = <NUM_LIT:1> , force = True ) <EOL> text = str ( itms . render ( ) ) <EOL> assert_equals ( "<STR_LIT>" in text , True ) <EOL> class SignalTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> pass <EOL> def test_create_card_signal ( self ) : <EOL> """<STR_LIT>""" <EOL> user = User . objects . get ( username = "<STR_LIT>" ) <EOL> delaypractice = DelayablePractice ( ) <EOL> alldue = delaypractice . get_all_due_for_user ( user ) <EOL> assert_equals ( alldue . count ( ) , <NUM_LIT:2> ) <EOL> def test_delete_card_signal ( self ) : <EOL> """<STR_LIT>""" <EOL> user = User . objects . get ( username = "<STR_LIT>" ) <EOL> card = Card . objects . get ( ID = <NUM_LIT:1> ) <EOL> card . delete ( ) <EOL> delaypractice = DelayablePractice ( ) <EOL> alldue = delaypractice . get_all_due_for_user ( user ) <EOL> assert_equals ( alldue . count ( ) , <NUM_LIT:1> ) <EOL> def test_delete_user_signal ( self ) : <EOL> """<STR_LIT>""" <EOL> user = User . objects . get ( username = "<STR_LIT>" ) <EOL> user . delete ( ) <EOL> allDps = DelayablePractice . objects . all ( ) <EOL> assert_equals ( allDps . count ( ) , <NUM_LIT:0> ) <EOL> class DelayablePracticeTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> pass <EOL> def test_get_all_due_in_card_id_list ( self ) : <EOL> """<STR_LIT>""" <EOL> user = User . objects . get ( username = "<STR_LIT>" ) <EOL> dp = delayCard ( <NUM_LIT:1> ) <EOL> numberOfDueCardsInList = dp . get_all_due_in_card_id_list ( user , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . count ( ) <EOL> assert_equals ( numberOfDueCardsInList , <NUM_LIT:1> ) <EOL> def test_delay_nothing_if_no_cards_are_due ( self ) : <EOL> """<STR_LIT>""" <EOL> dp_1 = delayCard ( <NUM_LIT:1> ) <EOL> dp_2 = delayCard ( <NUM_LIT:2> ) <EOL> time_1 = dp_1 . next_practice <EOL> time_2 = dp_2 . next_practice <EOL> dp_1 . delay ( ) <EOL> dp_2 . delay ( ) <EOL> assert_equals ( time_1 , dp_1 . next_practice ) <EOL> assert_equals ( time_2 , dp_2 . next_practice ) <EOL> def test_delay_after_latest_card_are_due ( self ) : <EOL> """<STR_LIT>""" <EOL> dp_1 = makeCardDue ( <NUM_LIT:1> , <NUM_LIT:5> ) <EOL> dp_2 = makeCardDue ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> pre_delay = dp_1 . next_practice > dp_2 . next_practice <EOL> dp_1 . delay ( ) <EOL> assert_equals ( pre_delay , False ) <EOL> assert_equals ( dp_1 . next_practice > dp_2 . next_practice , True ) <EOL> def test_delay_for_10_min ( self ) : <EOL> """<STR_LIT>""" <EOL> makeCardDue ( <NUM_LIT:1> , <NUM_LIT:20> ) <EOL> dp_2 = makeCardDue ( <NUM_LIT:2> , <NUM_LIT> ) <EOL> dp_2 . delay ( ) <EOL> assert_equals ( dp_2 . next_practice > datetime . utcnow ( ) . replace ( tzinfo = utc ) , True ) </s>
