<s> from random import randint <EOL> from mongu import CounterValueError <EOL> from . base import CounterTestCase <EOL> class CounterTests ( CounterTestCase ) : <EOL> def test_mixin ( self ) : <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> u = self . User ( username = name ) <EOL> u . save ( ) <EOL> u . age = randint ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> u . save ( ) <EOL> self . assertEqual ( self . User . count ( ) , <NUM_LIT:3> ) <EOL> def test_initial ( self ) : <EOL> self . assertEqual ( <NUM_LIT:0> , self . Counter . count ( '<STR_LIT>' ) ) <EOL> def test_inc_counter ( self ) : <EOL> c = self . User . count ( ) <EOL> self . User . inc_counter ( ) <EOL> self . assertEqual ( self . User . count ( ) , c + <NUM_LIT:1> ) <EOL> def test_dec_counter ( self ) : <EOL> self . User . inc_counter ( ) <EOL> c = self . User . count ( ) <EOL> self . User . dec_counter ( ) <EOL> self . assertEqual ( self . User . count ( ) , c - <NUM_LIT:1> ) <EOL> def test_chg_counter ( self ) : <EOL> c = self . User . count ( ) <EOL> self . User . chg_counter ( <NUM_LIT:100> ) <EOL> self . assertEqual ( self . User . count ( ) , c + <NUM_LIT:100> ) <EOL> def test_set_counter ( self ) : <EOL> self . User . set_counter ( <NUM_LIT> ) <EOL> self . assertEqual ( self . User . count ( ) , <NUM_LIT> ) <EOL> def test_increase ( self ) : <EOL> k = '<STR_LIT>' <EOL> self . assertEqual ( <NUM_LIT:1> , self . Counter . increase ( k ) ) <EOL> def test_decrease ( self ) : <EOL> k = '<STR_LIT>' <EOL> self . Counter . increase ( k ) <EOL> self . Counter . decrease ( k ) <EOL> self . assertEqual ( <NUM_LIT:0> , self . Counter . count ( k ) ) <EOL> def test_change_by ( self ) : <EOL> k = '<STR_LIT>' <EOL> self . assertEqual ( <NUM_LIT:3> , self . Counter . change_by ( k , <NUM_LIT:3> ) ) <EOL> self . assertEqual ( <NUM_LIT:3> - <NUM_LIT:1> , self . Counter . change_by ( k , - <NUM_LIT:1> ) ) <EOL> def test_set_to ( self ) : <EOL> k = '<STR_LIT>' <EOL> r = randint ( <NUM_LIT:0> , <NUM_LIT:100> ) <EOL> self . Counter . set_to ( k , r ) <EOL> self . assertEqual ( self . Counter . count ( k ) , r ) <EOL> self . assertRaises ( CounterValueError , self . Counter . set_to , k , - r ) <EOL> def test_base ( self ) : <EOL> class CounterBase ( object ) : <EOL> @ classmethod <EOL> def increase_by_6 ( self , key ) : <EOL> return self . change_by ( key , <NUM_LIT:6> ) <EOL> Counter , _ = self . client . enable_counter ( base = CounterBase ) <EOL> self . assertEqual ( Counter . increase_by_6 ( '<STR_LIT>' ) , <NUM_LIT:6> ) <EOL> def test_change_by_exception ( self ) : <EOL> self . assertRaises ( CounterValueError , self . Counter . change_by , '<STR_LIT>' , - <NUM_LIT> ) <EOL> def test_on_delete ( self ) : <EOL> user = self . User ( username = '<STR_LIT>' ) <EOL> user . save ( ) <EOL> before = self . User . count ( ) <EOL> user . delete ( ) <EOL> self . assertEqual ( before - <NUM_LIT:1> , self . User . count ( ) ) </s>
