<s> import copy <EOL> import datetime <EOL> from dateutil . relativedelta import relativedelta <EOL> from ddt import data , ddt , unpack <EOL> from django . db . models import Q <EOL> from django . test import SimpleTestCase <EOL> from ralph . dashboards . filter_parser import FilterParser <EOL> from ralph . dashboards . models import Graph <EOL> from ralph . tests . models import Bar <EOL> ARGS , KWARGS = ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> @ ddt <EOL> class ParserFiltersTest ( SimpleTestCase ) : <EOL> def setUp ( self ) : <EOL> self . parser = FilterParser ( Bar . objects . all ( ) , None ) <EOL> @ unpack <EOL> @ data ( <EOL> ( '<STR_LIT>' , relativedelta ( years = <NUM_LIT:2> ) ) , <EOL> ( '<STR_LIT>' , relativedelta ( years = - <NUM_LIT:2> ) ) , <EOL> ( '<STR_LIT>' , relativedelta ( months = <NUM_LIT:9> ) ) , <EOL> ( '<STR_LIT>' , relativedelta ( months = - <NUM_LIT:9> ) ) , <EOL> ( '<STR_LIT>' , relativedelta ( days = <NUM_LIT> ) ) , <EOL> ( '<STR_LIT>' , relativedelta ( days = - <NUM_LIT> ) ) , <EOL> ) <EOL> def test_filter_from_now ( self , filter_str , expect ) : <EOL> key = '<STR_LIT:foo>' <EOL> result = self . parser . filter_from_now ( key , filter_str ) <EOL> pp = datetime . date . today ( ) + expect <EOL> self . assertEqual ( <EOL> result [ KWARGS ] , { key : pp . strftime ( '<STR_LIT>' ) } <EOL> ) <EOL> @ unpack <EOL> @ data ( <EOL> ( '<STR_LIT:1>' , Q ( key = '<STR_LIT:1>' ) ) , <EOL> ( '<STR_LIT>' , Q ( key = '<STR_LIT:1>' ) | Q ( key = '<STR_LIT:2>' ) ) , <EOL> ) <EOL> def test_process_value ( self , value , expect ) : <EOL> result = self . parser . filter_or ( '<STR_LIT:key>' , value ) <EOL> self . assertEqual ( str ( result [ ARGS ] [ <NUM_LIT:0> ] ) , str ( expect ) ) <EOL> @ unpack <EOL> @ data ( <EOL> ( [ '<STR_LIT:1>' ] , Q ( key = '<STR_LIT:1>' ) ) , <EOL> ( [ '<STR_LIT:1>' , '<STR_LIT:2>' ] , Q ( key = '<STR_LIT:1>' ) & Q ( key = '<STR_LIT:2>' ) ) , <EOL> ) <EOL> def test_process_value ( self , value , expect ) : <EOL> result = self . parser . filter_and ( '<STR_LIT:key>' , value ) <EOL> self . assertEqual ( str ( result [ ARGS ] [ <NUM_LIT:0> ] ) , str ( expect ) ) <EOL> @ ddt <EOL> class GraphModelTest ( SimpleTestCase ) : <EOL> @ unpack <EOL> @ data ( <EOL> ( { } , <NUM_LIT:0> ) , <EOL> ( { '<STR_LIT>' : <NUM_LIT:3> } , <NUM_LIT:1> ) , <EOL> ( { '<STR_LIT>' : <NUM_LIT:5> , '<STR_LIT>' : <NUM_LIT:3> } , <NUM_LIT:2> ) , <EOL> ) <EOL> def test_annotate_fitler_should_pop_from_filters ( <EOL> self , orig_filters , length <EOL> ) : <EOL> graph = Graph ( ) <EOL> filters = copy . deepcopy ( orig_filters ) <EOL> result = graph . pop_annotate_filters ( filters ) <EOL> self . assertEqual ( len ( result ) , length ) <EOL> self . assertEqual ( len ( orig_filters ) - length , len ( filters ) ) </s>
