<s> from datetime import date <EOL> from decimal import Decimal <EOL> from urllib . parse import urlencode <EOL> from django . contrib . auth import get_user_model <EOL> from django . http import QueryDict <EOL> from rest_framework . test import APIClient , APIRequestFactory <EOL> from ralph . api . filters import ExtendedFiltersBackend , LookupFilterBackend <EOL> from ralph . api . tests . api import ( <EOL> Bar , <EOL> BarViewSet , <EOL> Manufacturer , <EOL> ManufacturerViewSet <EOL> ) <EOL> from ralph . tests import RalphTestCase <EOL> from ralph . tests . factories import ManufacturerFactory <EOL> class TestExtendedFiltersBackend ( RalphTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( ) . setUp ( ) <EOL> self . request_factory = APIRequestFactory ( ) <EOL> self . manufacture_1 = ManufacturerFactory ( <EOL> name = '<STR_LIT:test>' , country = '<STR_LIT>' <EOL> ) <EOL> self . manufacture_2 = ManufacturerFactory ( <EOL> name = '<STR_LIT>' , country = '<STR_LIT:test>' <EOL> ) <EOL> get_user_model ( ) . objects . create_superuser ( <EOL> '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT:test>' <EOL> ) <EOL> self . client = APIClient ( ) <EOL> self . client . login ( username = '<STR_LIT:test>' , password = '<STR_LIT:test>' ) <EOL> self . extended_filters_backend = ExtendedFiltersBackend ( ) <EOL> def test_extended_filter_fields ( self ) : <EOL> request = self . request_factory . get ( '<STR_LIT:/>' ) <EOL> request . query_params = QueryDict ( urlencode ( { '<STR_LIT>' : '<STR_LIT:test>' } ) ) <EOL> mvs = ManufacturerViewSet ( ) <EOL> mvs . request = request <EOL> self . assertEqual ( len ( self . extended_filters_backend . filter_queryset ( <EOL> request , Manufacturer . objects . all ( ) , mvs ) <EOL> ) , <NUM_LIT:2> ) <EOL> request . query_params = QueryDict ( urlencode ( { '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> mvs . request = request <EOL> self . assertEqual ( len ( self . extended_filters_backend . filter_queryset ( <EOL> request , Manufacturer . objects . all ( ) , mvs ) <EOL> ) , <NUM_LIT:1> ) <EOL> class TestLookupFilterBackend ( RalphTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( ) . setUp ( ) <EOL> self . request_factory = APIRequestFactory ( ) <EOL> get_user_model ( ) . objects . create_superuser ( <EOL> '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT:test>' <EOL> ) <EOL> self . client = APIClient ( ) <EOL> self . client . login ( username = '<STR_LIT:test>' , password = '<STR_LIT:test>' ) <EOL> Bar . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> date = date ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:1> ) , <EOL> price = Decimal ( '<STR_LIT>' ) , <EOL> count = <NUM_LIT:1> <EOL> ) <EOL> Bar . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> date = date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> ) , <EOL> price = Decimal ( '<STR_LIT>' ) , <EOL> count = <NUM_LIT:2> <EOL> ) <EOL> Bar . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> date = date ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:1> ) , <EOL> price = Decimal ( '<STR_LIT>' ) , <EOL> count = <NUM_LIT:3> <EOL> ) <EOL> self . lookup_filter = LookupFilterBackend ( ) <EOL> def test_query_filters_charfield ( self ) : <EOL> request = self . request_factory . get ( '<STR_LIT>' ) <EOL> bvs = BarViewSet ( ) <EOL> request . query_params = QueryDict ( <EOL> urlencode ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> ) <EOL> bvs . request = request <EOL> self . assertEqual ( len ( self . lookup_filter . filter_queryset ( <EOL> request , Bar . objects . all ( ) , bvs ) <EOL> ) , <NUM_LIT:1> ) <EOL> request . query_params = QueryDict ( urlencode ( { '<STR_LIT>' : <NUM_LIT:10> } ) ) <EOL> self . assertEqual ( len ( self . lookup_filter . filter_queryset ( <EOL> request , Bar . objects . all ( ) , bvs ) <EOL> ) , <NUM_LIT:3> ) <EOL> def test_query_filters_decimalfield ( self ) : <EOL> request = self . request_factory . get ( '<STR_LIT>' ) <EOL> bvs = BarViewSet ( ) <EOL> request . query_params = QueryDict ( urlencode ( { '<STR_LIT>' : <NUM_LIT:20> } ) ) <EOL> bvs . request = request <EOL> self . assertEqual ( len ( self . lookup_filter . filter_queryset ( <EOL> request , Bar . objects . all ( ) , bvs ) <EOL> ) , <NUM_LIT:2> ) <EOL> request . query_params = QueryDict ( urlencode ( { '<STR_LIT>' : <NUM_LIT:10> } ) ) <EOL> self . assertEqual ( len ( self . lookup_filter . filter_queryset ( <EOL> request , Bar . objects . all ( ) , bvs ) <EOL> ) , <NUM_LIT:3> ) <EOL> def test_query_filters_integerfield ( self ) : <EOL> request = self . request_factory . get ( '<STR_LIT>' ) <EOL> bvs = BarViewSet ( ) <EOL> request . query_params = QueryDict ( urlencode ( { '<STR_LIT>' : <NUM_LIT:2> } ) ) <EOL> bvs . request = request <EOL> self . assertEqual ( len ( self . lookup_filter . filter_queryset ( <EOL> request , Bar . objects . all ( ) , bvs ) <EOL> ) , <NUM_LIT:2> ) <EOL> request . query_params = QueryDict ( urlencode ( { '<STR_LIT>' : <NUM_LIT:10> } ) ) <EOL> self . assertEqual ( len ( self . lookup_filter . filter_queryset ( <EOL> request , Bar . objects . all ( ) , bvs ) <EOL> ) , <NUM_LIT:3> ) <EOL> def test_query_filters_datefield ( self ) : <EOL> request = self . request_factory . get ( '<STR_LIT>' ) <EOL> bvs = BarViewSet ( ) <EOL> request . query_params = QueryDict ( urlencode ( { '<STR_LIT>' : <NUM_LIT> } ) ) <EOL> bvs . request = request <EOL> self . assertEqual ( len ( self . lookup_filter . filter_queryset ( <EOL> request , Bar . objects . all ( ) , bvs ) <EOL> ) , <NUM_LIT:1> ) <EOL> request . query_params = QueryDict ( urlencode ( { '<STR_LIT>' : <NUM_LIT:10> } ) ) <EOL> self . assertEqual ( len ( self . lookup_filter . filter_queryset ( <EOL> request , Bar . objects . all ( ) , bvs ) <EOL> ) , <NUM_LIT:3> ) <EOL> def test_query_filters_datetimefield ( self ) : <EOL> request = self . request_factory . get ( '<STR_LIT>' ) <EOL> bvs = BarViewSet ( ) <EOL> request . query_params = QueryDict ( urlencode ( <EOL> { '<STR_LIT>' : date . today ( ) . year } ) <EOL> ) <EOL> bvs . request = request <EOL> self . assertEqual ( len ( self . lookup_filter . filter_queryset ( <EOL> request , Bar . objects . all ( ) , bvs ) <EOL> ) , <NUM_LIT:3> ) <EOL> request . query_params = QueryDict ( <EOL> urlencode ( { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : date . today ( ) . month <EOL> } ) <EOL> ) <EOL> bvs . request = request <EOL> self . assertEqual ( len ( self . lookup_filter . filter_queryset ( <EOL> request , Bar . objects . all ( ) , bvs ) <EOL> ) , <NUM_LIT:1> ) <EOL> request . query_params = QueryDict ( <EOL> urlencode ( { '<STR_LIT>' : <NUM_LIT:10> } ) <EOL> ) <EOL> self . assertEqual ( len ( self . lookup_filter . filter_queryset ( <EOL> request , Bar . objects . all ( ) , bvs ) <EOL> ) , <NUM_LIT:3> ) </s>
