<s> from mocktest import * <EOL> from pyqcy import * <EOL> import datetime <EOL> import neat . globals . db_cleaner as cleaner <EOL> import neat . common as common <EOL> import neat . db_utils as db_utils <EOL> import logging <EOL> logging . disable ( logging . CRITICAL ) <EOL> class DbCleaner ( TestCase ) : <EOL> @ qc ( <NUM_LIT:10> ) <EOL> def start ( <EOL> iterations = int_ ( min = <NUM_LIT:0> , max = <NUM_LIT:10> ) , <EOL> time_interval = int_ ( min = <NUM_LIT:0> ) <EOL> ) : <EOL> with MockTransaction : <EOL> state = { '<STR_LIT>' : '<STR_LIT:value>' } <EOL> config = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : str ( time_interval ) } <EOL> paths = [ cleaner . DEFAILT_CONFIG_PATH , cleaner . CONFIG_PATH ] <EOL> fields = cleaner . REQUIRED_FIELDS <EOL> expect ( cleaner ) . read_and_validate_config ( paths , fields ) . and_return ( config ) . once ( ) <EOL> expect ( common ) . init_logging ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:2> ) . once ( ) <EOL> expect ( common ) . start ( cleaner . init_state , <EOL> cleaner . execute , <EOL> config , <EOL> time_interval ) . and_return ( state ) . once ( ) <EOL> assert cleaner . start ( ) == state <EOL> @ qc ( <NUM_LIT:1> ) <EOL> def init_state ( ) : <EOL> with MockTransaction : <EOL> db = mock ( '<STR_LIT>' ) <EOL> expect ( cleaner ) . init_db ( '<STR_LIT>' ) . and_return ( db ) . once ( ) <EOL> config = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> } <EOL> state = cleaner . init_state ( config ) <EOL> assert state [ '<STR_LIT>' ] == db <EOL> assert state [ '<STR_LIT>' ] == datetime . timedelta ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> @ qc ( <NUM_LIT:1> ) <EOL> def execute ( <EOL> uuid = str_ ( of = '<STR_LIT>' , min_length = <NUM_LIT> , max_length = <NUM_LIT> ) <EOL> ) : <EOL> with MockTransaction : <EOL> db = db_utils . init_db ( '<STR_LIT>' ) <EOL> result = db . vms . insert ( ) . execute ( uuid = uuid ) <EOL> vm_id = result . inserted_primary_key [ <NUM_LIT:0> ] <EOL> time = datetime . datetime . today ( ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> db . vm_resource_usage . insert ( ) . execute ( <EOL> vm_id = <NUM_LIT:1> , <EOL> cpu_mhz = i , <EOL> timestamp = time . replace ( second = i ) ) <EOL> state = { <EOL> '<STR_LIT>' : db , <EOL> '<STR_LIT>' : datetime . timedelta ( seconds = <NUM_LIT:5> ) } <EOL> expect ( cleaner ) . today ( ) . and_return ( time . replace ( second = <NUM_LIT:10> ) ) . once ( ) <EOL> assert db . select_cpu_mhz_for_vm ( uuid , <NUM_LIT:100> ) == range ( <NUM_LIT:10> ) <EOL> cleaner . execute ( { } , state ) <EOL> assert db . select_cpu_mhz_for_vm ( uuid , <NUM_LIT:100> ) == range ( <NUM_LIT:5> , <NUM_LIT:10> ) </s>
