# coding: utf-8

"""
    Marketcheck Cars API

    <b>Access the New, Used and Certified cars inventories for all Car Dealers in US.</b> <br/>The data is sourced from online listings by over 44,000 Car dealers in US. At any time, there are about 6.2M searchable listings (about 1.9M unique VINs) for Used & Certified cars and about 6.6M (about 3.9M unique VINs) New Car listings from all over US. We use this API at the back for our website <a href='https://www.marketcheck.com' target='_blank'>www.marketcheck.com</a> and our Android and iOS mobile apps too.<br/><h5> Few useful links : </h5><ul><li>A quick view of the API and the use cases is depicated <a href='https://portals.marketcheck.com/mcapi/' target='_blank'>here</a></li><li>The Postman collection with various usages of the API is shared here https://www.getpostman.com/collections/2752684ff636cdd7bac2</li></ul>  # noqa: E501

    OpenAPI spec version: 1.0.3
    
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


from __future__ import absolute_import
from pprint import pprint
import unittest
import pdb
import itertools
import marketcheck_api_sdk
from marketcheck_api_sdk.api.listings_api import ListingsApi  # noqa: E501
from marketcheck_api_sdk.rest import ApiException


class TestListingsApi(unittest.TestCase):
    """ListingsApi unit test stubs"""

    def setUp(self):
        self.api = marketcheck_api_sdk.api.listings_api.ListingsApi()  # noqa: E501

    def tearDown(self):
        pass

    def test_get_listing(self):
        """Test case for get_listing

        Listing by id  # noqa: E501
        """
        #####    validate listing formats    #######
        api_instance = marketcheck_api_sdk.ListingsApi(marketcheck_api_sdk.ApiClient())
        listing_id = ["1FTNE2CM2FKA81288-62fc00a9-7a8c-435b-bd55-5d862759683f","1GYS4BKJ8FR290257-1c4e667b-cef1-47b7-9669-2aabf42a7011",
        "3GYFNBE3XFS537500-3d95698a-4195-4612-af97-6dcd69a21ce0"]
        vins = ["1FTNE2CM2FKA81288","1GYS4BKJ8FR290257","3GYFNBE3XFS537500"]
        api_key = "YOUR API KEY"
        try:
            for listing in listing_id:
                api_response = api_instance.get_listing(listing, api_key=api_key)
                #pprint(api_response)
                assert isinstance(api_response.media,object)
                assert isinstance(api_response.extra,object)
                assert isinstance(api_response.dealer,object)
                assert isinstance(api_response.build,object)
                assert isinstance(api_response.media.photo_links,list)
                if api_response.extra.options != None: assert isinstance(api_response.extra.options,list)
                if api_response.extra.features != None: assert isinstance(api_response.extra.features,list)
                if api_response.extra.seller_comments != None: assert isinstance(api_response.extra.seller_comments,str)
                assert isinstance(api_response.build.model,str)
                assert isinstance(api_response.build.make,str)
                if api_response.build.engine != None: assert isinstance(api_response.build.engine,str)
                if api_response.build.transmission != None: assert isinstance(api_response.build.transmission,str)
                assert isinstance(api_response.build.year,int)
                assert api_response.id == listing
        except ApiException as e:
            pprint("Exception when calling ListingsApi->get_listing: %s\n" % e)
        pass

    def test_get_listing_extra(self):
        """Test case for get_listing_extra

        Long text Listings attributes for Listing with the given id  # noqa: E501
        """
        api_instance = marketcheck_api_sdk.ListingsApi(marketcheck_api_sdk.ApiClient())
        listing_id = ["1FTNE2CM2FKA81288-62fc00a9-7a8c-435b-bd55-5d862759683f","1GYS4BKJ8FR290257-1c4e667b-cef1-47b7-9669-2aabf42a7011",
                      "3GYFNBE3XFS537500-3d95698a-4195-4612-af97-6dcd69a21ce0"]
        vins = ["1FTNE2CM2FKA81288","1GYS4BKJ8FR290257","3GYFNBE3XFS537500"]
        api_key = "YOUR API KEY"
        try:
            for id in listing_id:
                api_response = api_instance.get_listing_extra(id, api_key=api_key)
                #pprint(api_response)
                assert api_response.id == id
                assert hasattr(api_response,"features")
                assert hasattr(api_response,"options")
                assert isinstance(api_response.id,str)
                if api_response.options != None: assert isinstance(api_response.options,list)
                if api_response.features != None: assert isinstance(api_response.features,list)
                if api_response.seller_cmts != None: assert isinstance(api_response.seller_cmts,str)
        except ApiException as e:
            pprint("Exception when calling ListingsApi->get_listing_extra: %s\n" % e)
        pass

    def test_get_listing_media(self):
        """Test case for get_listing_media

        Listing media by id  # noqa: E501
        """
        api_instance = marketcheck_api_sdk.ListingsApi(marketcheck_api_sdk.ApiClient())
        listing_id = ["1FTNE2CM2FKA81288-62fc00a9-7a8c-435b-bd55-5d862759683f","1GYS4BKJ8FR290257-1c4e667b-cef1-47b7-9669-2aabf42a7011",
                      "3GYFNBE3XFS537500-3d95698a-4195-4612-af97-6dcd69a21ce0"]
        vins = ["1FTNE2CM2FKA81288","1GYS4BKJ8FR290257","3GYFNBE3XFS537500"]
        api_key = "YOUR API KEY"
        try:
            for id in listing_id:
                api_response = api_instance.get_listing_media(id, api_key=api_key)
                #pprint(api_response)
                assert api_response.id ==id
                assert isinstance(api_response.id,str)
                if api_response.photo_links != None: assert isinstance(api_response.photo_links,list)
                if api_response.photo_url != None: assert isinstance(api_response.photo_url,str)
        except ApiException as e:
            pprint("Exception when calling ListingsApi->get_listing_media %s\n" % e)

        pass

    def test_get_listing_vdp(self):
        """Test case for get_listing_vdp

        Get listing HTML  # noqa: E501
        """
        pass

    def test_get_summary_report(self):
        """Test case for get_summary_report

        Get Summary Report  # noqa: E501
        """
        pass

    def test_search(self):
        """Test case for search

        Gets active car listings for the given search criteria  # noqa: E501
        """
        api_instance = marketcheck_api_sdk.ListingsApi(marketcheck_api_sdk.ApiClient())
        api_key = "YOUR API KEY"
        try:
            years=["2017", "2018", "2014", "2016", "2015"]
            makes=["Ford", "Chevrolet", "Toyota", "Nissan", "Honda"]
            models=["F-150", "Civic", "Escape", "Equinox", "Malibu"]
            trims=["Base", "Limited", "Sport", "Platinum", "Touring"]
            exterior_colors=["Black", "White", "Silver", "Red", "Blue"]
            interior_colors=["Black", "Gray", "Graphite", "Cloth", "Ash"]
            body_types=["Sedan", "Pickup", "Hatchback", "Coupe", "Wagon"]
            body_subtypes=["Crew Cab", "Extended Cab", "Regular Cab", "Super Cab"]
            vehicle_types=["SUV", "Van", "Car", "Truck"]
            latitudes=["35.94","37.34","35.41","33.54","43.06"]
            seller_types=["dealer", "fsbo"]
            longitudes= ["-117.29","-75.65","-86.8","-80.64","-84.16"]
            vins=["1FTEW1EFXFFB17341",
                  "1FTEW1CP0FKD64953",
                  "1FTEW1CG5FKE15329",
                  "1FTEW1EF4FKD18109",
                  "1FTFW1EG3FFB34334"]
            taxonomy_vins= ["1FTEW1EFFF", "1FTEW1CPFK", "1FTEW1CGFK", "1FTEW1EFFK", "1FTFW1EGFF"]
            miles_ranges=["3000", "5000", "8000", "10000"]
            price_ranges=["30000", "40000", "50000", "60000"]
            dom_ranges=["20", "30", "40", "50"]
            sort_orders= ["asc", "desc"]
            sort_by=["price", "miles", "dom", "year"]
            lease_term=[36, 39, 48]
            lease_emp=[200, 300, 400]
            lease_down_payment=[1000, 2000, 3000]
            finance_loan_term=[36, 48, 72]
            finance_loan_apr=[4, 4.5, 4.75, 5]
            finance_down_payment=[2000, 3000, 5000]
            finance_emp=[200, 250, 300]
            dealer_id=[1007324, 1000466, 1016299, 1016499, 1015942]
            zips=["90007", "75209", "02110", "84102"]
            cylinders=["4", "6", "8", "5", "3"]
            doors=["4", "2", "5", "3", "6"]
            transmissions=["Automatic", "Manual", "Automated Manual", "Direct Drive", "Manual/Standard"]
            drivetrains=["Front Wheel Drive", "4-Wheel Drive", "All Wheel Drive", "Rear Wheel Drive", "4x2"]
            countrys=["CA", "US"]
            car_types=["new", "used"]
            engine_blocks=["v", "i", "h"]
            rows=["5", "10", "20", "30", "50"]
            ym_cmobo = list(itertools.product(years,makes))
            mm_cmobo = list(itertools.product(makes,models))
            mt_cmobo = list(itertools.product(models,trims))
            ymm_cmobo = list(itertools.product(years,makes,models))
            ymmt_cmobo = list(itertools.product(years,makes,models,trims))
            ext_int_clr_combo = list(itertools.product(exterior_colors,interior_colors))
            ext_clr_bd_type_combo = list(itertools.product(exterior_colors,body_types))
            ext_clr_bd_and_bds_type_combo = list(itertools.product(exterior_colors,body_types,body_subtypes))
            seller_and_vehicle_type = list(itertools.product(seller_types,vehicle_types))
            lat_lng_combo = list(itertools.product(latitudes,longitudes))
            vin_combo = list(itertools.product(vins,vins))
            taxonomy_vins_combo = list(itertools.product(taxonomy_vins,taxonomy_vins))
            stats_fields = ["price","miles","dom"]
            sort_by_and_order_combo = list(itertools.product(sort_by,sort_orders))
            miles_range_combo = list(itertools.product(miles_ranges[:2],miles_ranges[-2:]))
            price_range_combo = list(itertools.product(price_ranges[:2],price_ranges[-2:]))
            dom_range_combo = list(itertools.product(dom_ranges[:2],dom_ranges[-2:]))
            sort_by_and_order_combo = list(itertools.product(sort_by,sort_orders))
            sort_by_fields_combo = list(itertools.product(sort_by[:2],sort_by[-2:],sort_orders))
            ##########        validate stats           #############
            for field in stats_fields:
                api_response = api_instance.search(api_key=api_key,latitude=39.73,longitude=-104.99,radius=200,stats=field,start=0,rows=10,sort_by=field,sort_order="desc",car_type="used")
                assert api_response.stats[field].has_key("sum")
                assert api_response.stats[field].has_key("min")
                assert api_response.stats[field].has_key("max")
                assert api_response.stats[field].has_key("mean")
                assert api_response.stats[field].has_key("count")
                assert api_response.stats[field].has_key("median")
                assert api_response.stats[field].has_key("stddev")
                if field == "price": assert api_response.listings[0].price == api_response.stats[field]["max"]
                if field == "miles": assert api_response.listings[0].miles == api_response.stats[field]["max"]
                if field == "dom": assert api_response.listings[0].dom == api_response.stats[field]["max"]
            ########        validate stats with multiple fields given     ########
            api_response = api_instance.search(api_key=api_key,latitude=39.73,longitude=-104.99,radius=200,stats="price,miles,dom",start=1,rows=0,car_type="used")
            assert hasattr(api_response,"stats")
            assert api_response.stats.has_key(stats_fields[0])
            assert api_response.stats.has_key(stats_fields[1])
            assert api_response.stats.has_key(stats_fields[2])
            ######     validate near by response  #########
            ######## validate makes     ###########
            for make in makes:
                api_response = api_instance.search(api_key=api_key,make=make,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.make == make
            #########  validate model     ##########
            for model in models:
                api_response = api_instance.search(api_key=api_key,model=model,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.model == model
            #########     validate trim     ##########
            for trim in trims:
                api_response = api_instance.search(api_key=api_key,trim=trim,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.trim.lower() == trim.lower()
            #########    Validate Year        ###########
            for year in years:
                api_response = api_instance.search(api_key=api_key,year=year,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.year == int(year)
            ###########    Validate zip code search    #########make=ford&year=2016&zip=#{_zip}&car_type=used&sort_by=id&sort_order=desc
            for zip in zips:
                api_response = api_instance.search(api_key=api_key,year="2016",make="ford",zip=zip,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.dealer.zip == zip
            ###########      Validate carafax attributes    #################
            api_response = api_instance.search(api_key=api_key,make="ford",year="2015",carfax_1_owner="true",carfax_clean_title="true")
            for listing in api_response.listings:
                assert listing.carfax_1_owner == True
                assert listing.carfax_clean_title == True
            for year,make in ym_cmobo[0:4]:
                api_response = api_instance.search(api_key=api_key,year=year,make=make,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.make == make
                    assert isinstance(listing.build.year,int)
                    assert listing.build.year == int(year)
            for make,model in mm_cmobo[0:4]:
                api_response = api_instance.search(api_key=api_key,make=make,model=model,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.make == make
                    assert listing.build.model == model
            for model,trim in mt_cmobo[0:4]:
                api_response = api_instance.search(api_key=api_key,model=model,trim=trim,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.model == model
                    assert listing.build.trim == trim
            for year,make,model in ymm_cmobo[0:4]:
                api_response = api_instance.search(api_key=api_key,model=model,make=make,year=year,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.model == model
                    assert listing.build.year == int(year)
                    assert isinstance(listing.build.year,int)
                    assert listing.build.make == make
            for year,make,model,trim in ymmt_cmobo[0:4]:
                api_response = api_instance.search(api_key=api_key,model=model,year=year,make=make,trim=trim,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.model == model
                    assert listing.build.year == int(year)
                    assert isinstance(listing.build.year,int)
                    assert listing.build.make == make
                    assert listing.build.trim == trim
            for exterior_color in exterior_colors:
                api_response = api_instance.search(api_key=api_key,exterior_color=exterior_color,latitude=37.998,longitude=-84.522,radius=200,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.exterior_color.lower() == exterior_color.lower()
            for interior_color in interior_colors:
                api_response = api_instance.search(api_key=api_key,interior_color=interior_color,latitude=37.998,longitude=-84.522,radius=200,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.interior_color.lower() == interior_color.lower()
            for body_type in body_types:
                api_response = api_instance.search(api_key=api_key,body_type=body_type,latitude=37.998,longitude=-84.522,radius=200,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.body_type == body_type
            for body_subtype in body_subtypes:
                api_response = api_instance.search(api_key=api_key,body_subtype=body_subtype,latitude=37.998,longitude=-84.522,radius=200,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.body_subtype == body_subtype
            for exterior_color,body_type in ext_clr_bd_type_combo[0:4]:
                api_response = api_instance.search(api_key=api_key,exterior_color=exterior_color,body_type=body_type,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.exterior_color.lower() == exterior_color.lower()
                    assert listing.build.body_type == body_type
            for exterior_color,interior_color in ext_int_clr_combo[0:4]:
                api_response = api_instance.search(api_key=api_key,exterior_color=exterior_color,interior_color=interior_color,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.exterior_color.lower() == exterior_color.lower()
                    assert listing.interior_color.lower() == interior_color.lower()
            for exterior_color,body_type,body_subtype in ext_clr_bd_and_bds_type_combo[0:4]:
                api_response = api_instance.search(api_key=api_key,exterior_color=exterior_color,body_type=body_type,body_subtype=body_subtype,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.exterior_color.lower() == exterior_color.lower()
                    assert listing.build.body_type == body_type
                    assert listing.build.body_subtype == body_subtype
            for seller_type in seller_types:
                api_response = api_instance.search(api_key=api_key,seller_type=seller_type,latitude=37.998,longitude=-84.522,radius=200,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.seller_type == seller_type
            for vehicle_type in vehicle_types:
                api_response = api_instance.search(api_key=api_key,vehicle_type=vehicle_type,latitude=37.998,longitude=-84.522,radius=200,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.vehicle_type == vehicle_type
            ############     validate seller and vehicle type    ###########
            for s_type,v_type in seller_and_vehicle_type:
                api_response = api_instance.search(api_key=api_key,vehicle_type=v_type,seller_type=s_type,latitude=37.998,longitude=-84.522,radius=200,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.vehicle_type == v_type
                    assert listing.seller_type == s_type
            #######    validate lease_term    #####
            for l_term in lease_term:
                api_response = api_instance.search(api_key=api_key,lease_term=l_term,rows=50,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.leasing_options[0].lease_term == l_term
            ##########    validate lease_emp      #####
            for l_emp in lease_emp:
                api_response = api_instance.search(api_key=api_key,lease_emp=l_emp,rows=50,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.leasing_options[0].estimated_monthly_payment == l_emp
            ##########        validate lease_down_payment   ########
            for l_dp in lease_down_payment:
                api_response = api_instance.search(api_key=api_key,lease_down_payment=l_dp,rows=50,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.leasing_options[0].down_payment == l_dp
            ########        validate finance_loan_term       ###########
            for f_term in finance_loan_term:
                api_response = api_instance.search(api_key=api_key,finance_loan_term=f_term,rows=50,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.financing_options[0].loan_term == f_term
            ##########       validate finance_loan_apr        ############
            for f_apr in finance_loan_apr:
                api_response = api_instance.search(api_key=api_key,finance_loan_apr=f_apr,rows=50,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.financing_options[0].loan_apr == f_apr
            ##########       validate finance_emp             ##############
            for f_emp in finance_emp:
                api_response = api_instance.search(api_key=api_key,finance_emp=f_emp,rows=50,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.financing_options[0].estimated_monthly_payment == f_emp
            ###########      validate finance_down_payment    ############
            for f_dp in finance_down_payment:
                api_response = api_instance.search(api_key=api_key,finance_down_payment=f_dp,rows=50,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.financing_options[0].down_payment == f_dp
            #############      validate drivetrain         #############
            for d_train in drivetrains:
                api_response = api_instance.search(api_key=api_key,drivetrain=cgi.escape(d_train),car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.drivetrain == d_train
            ##############      validate cylinders          ##############
            for cylinder in cylinders:
                api_response = api_instance.search(api_key=api_key,cylinders=cylinder,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.cylinders == int(cylinder)
            ##############        validate transmission        ###########
            for transmission in transmissions:
                api_response = api_instance.search(api_key=api_key,transmission=cgi.escape(transmission),car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.transmission == transmission
            ##############       validate Doors        ############
            for door in doors:
                api_response = api_instance.search(api_key=api_key,doors=door,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.doors == int(door)
            ################       validate engine block      #########
            for e_block in engine_blocks:
                api_response = api_instance.search(api_key=api_key,engine_block=e_block,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.build.engine_block.lower() == e_block.lower()
            ##############        validate vin         ###########
            for vin in vins:
                api_response = api_instance.search(api_key=api_key,vin=vin,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.vin == vin
            ##############        validate rows         ############
            for row in rows:
                api_response = api_instance.search(api_key=api_key,exterior_color="black",rows=row,car_type="used",sort_by="id",sort_order="desc")
                assert len(api_response.listings) == int(row)
            #############       validate dealer id       #########
            for d_id in dealer_id:
                api_response = api_instance.search(api_key=api_key,dealer_id=d_id,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    listing.dealer.id == d_id
            ############        validate inventory type     ######
            for inv_type in car_types:
                api_response = api_instance.search(api_key=api_key,latitude=37.998,longitude=-84.522,radius=200,car_type=inv_type,sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    listing.inventory_type == inv_type
            ##############       validate country     ##########
            for country in countrys:
                api_response = api_instance.search(api_key=api_key,country=country,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    listing.dealer.country == country
            #############       validate miles range   #########
            for mile1,mile2 in miles_range_combo[0:4]:
                api_response = api_instance.search(api_key=api_key,miles_range=mile1+"-"+mile2,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.miles >= int(mile1)
                    assert listing.miles <= int(mile2)
            #############        validate price range   #########
            for price1,price2 in price_range_combo[0:4]:
                api_response = api_instance.search(api_key=api_key,price_range=price1+"-"+price2,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.price >= int(price1)
                    assert listing.price <= int(price2)
            #############       validate dom range     ########
            for dom1,dom2 in dom_range_combo[0:4]:
                api_response = api_instance.search(api_key=api_key,dom_range=dom1+"-"+dom2,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert listing.dom >= int(dom1)
                    assert listing.dom <= int(dom2)
            ############      validate lat and lan     ##########

            ###########      validate multiple vins   ###########
            for vin1,vin2 in vin_combo[0:2]:
                api_response = api_instance.search(api_key=api_key,vins=vin1+","+vin2,latitude=37.998,longitude=-84.522,rows=50,radius=200)
                is_taxonomy_vins = False
                vins = [vin1, vin2]
                for vin in vins:
                    if len(vin) == 10:
                        is_taxonomy_vins = True
                taxonomy_vins_of_listing = []
                taxonomy_vins_of_request = []
                for listing in api_response.listings:
                    taxonomy_vins_of_listing.append(listing.vin[0:8]+listing.vin[9])
                if is_taxonomy_vins:
                    taxonomy_vins_of_request = vins
                else:
                    for vin in vins:
                        taxonomy_vins_of_request.append(vin[0:8] + vin[9])
                taxonomy_vins_of_listing=sorted(list(set(taxonomy_vins_of_listing)))
                taxonomy_vins_of_request=sorted(list(set(taxonomy_vins_of_request)))
                assert len(taxonomy_vins_of_listing) - len(taxonomy_vins_of_request) == 0
            #################        validate taxonomy vins     ##############
            for vin1,vin2 in taxonomy_vins_combo[0:2]:
                api_response = api_instance.search(api_key=api_key,taxonomy_vins=vin1+","+vin2,rows=50,latitude=37.998,longitude=-84.522,radius=200)
                is_taxonomy_vins = False
                vins = [vin1, vin2]
                for vin in vins:
                    if len(vin) == 10:
                        is_taxonomy_vins = True
                taxonomy_vins_of_listing = []
                taxonomy_vins_of_request = []
                for listing in api_response.listings:
                    taxonomy_vins_of_listing.append(listing.vin[0:8]+listing.vin[9:11])
                if is_taxonomy_vins:
                    taxonomy_vins_of_request = vins
                else:
                    for vin in vins:
                        taxonomy_vins_of_request.append(vin[0:8] + vin[9:11])
                taxonomy_vins_of_listing=sorted(list(set(taxonomy_vins_of_listing)))
                taxonomy_vins_of_request=sorted(list(set(taxonomy_vins_of_request)))
                assert len(taxonomy_vins_of_listing) - len(taxonomy_vins_of_request) == 0
            #################           validate api response for matching vins      ##########
            for vin in vins:
                api_response = api_instance.search(api_key=api_key,vins=vin,match="year,make,model,trim",latitude=37.998,longitude=-84.522,radius=500,car_type="used",sort_by="dist",sort_order="asc",start=0,rows=50,country="ALL")
                assert hasattr(api_response,"num_found")
                assert hasattr(api_response,"listings")
                assert isinstance(api_response.num_found,int)
                assert isinstance(api_response.listings,list)
            ##############            validate multiple years        #########
            year_list=[years[i:i+3] for i in range(0, len(years), 3)]
            for year in year_list:
                year_param = year[0]+","+year[1]+","+year[2] if len(year) == 3 else year[0]+","+year[1]
                api_response = api_instance.search(api_key=api_key,year=year_param,car_type="used",sort_by="id",sort_order="desc")
                for listing in api_response.listings:
                    assert str(listing.build.year) in year
            #############           validate sort by and sort order   (problem in price,miles and order as well) ##########
            for sort_by,sort_order in sort_by_and_order_combo[0:2]:
                api_response = api_instance.search(api_key=api_key,sort_order=sort_order,sort_by=sort_by,latitude=37.998,longitude=-84.522,radius=50,car_type="used")
                field_arr = []
                if sort_by == "miles" or sort_by == "dom" or sort_by == "price" or sort_by == "year":    #
                    for listing in api_response.listings:
                        if sort_by == "dom": field_arr.append(listing.dom)
                        if sort_by == "miles": field_arr.append(listing.miles)
                        if sort_by == "price": field_arr.append(listing.price)
                        if sort_by == "year": field_arr.append(listing.build.year)
                if sort_order == "asc":

                    field_arr = filter(None,field_arr)
                    assert field_arr == sorted(field_arr)
                else:
                    field_arr = filter(None,field_arr)
                    assert field_arr == sorted(field_arr, reverse=True)
            ###########         validate lease fields in range and sort order on them     ##########
            for sort_o in sort_orders:
                for fl in ["lease_term","lease_emp","lease_down_payment"]:
                    api_response = api_instance.search(api_key=api_key,lease_term="36-48",lease_emp="200-400",lease_down_payment="1000-3000",sort_order=sort_o,sort_by=fl,rows=50,car_type="used")
                    field_arr=[]
                    for listing in api_response.listings:
                        assert listing.leasing_options[0].lease_term <= 48
                        assert listing.leasing_options[0].lease_term >= 36
                        assert listing.leasing_options[0].estimated_monthly_payment <=400
                        assert listing.leasing_options[0].estimated_monthly_payment >=200
                        assert listing.leasing_options[0].down_payment <=3000
                        assert listing.leasing_options[0].down_payment >=1000
                        if fl == "lease_down_payment": field_arr.append(listing.leasing_options[0].down_payment)
                        if fl == "lease_emp": field_arr.append(listing.leasing_options[0].estimated_monthly_payment)
                        if fl == "lease_term": field_arr.append(listing.leasing_options[0].lease_term)
                    if sort_o == "asc":
                        field_arr = filter(None,field_arr)
                        assert field_arr == sorted(field_arr)
                    else:
                        field_arr = filter(None,field_arr)
                        assert field_arr == sorted(field_arr, reverse=True)
            ##############          validate finance fields in range and sort order on them    #########
            for sort_o in sort_orders:
                for fl in ["finance_loan_term","finance_loan_apr","finance_down_payment", "finance_emp"]:
                    api_response = api_instance.search(api_key=api_key,finance_loan_term="36-48",finance_emp="200-300",finance_down_payment="2000-5000",finance_loan_apr="4-5",sort_order=sort_o,sort_by=fl,rows=50,car_type="used")
                    field_arr=[]
                    for listing in api_response.listings:
                        assert listing.financing_options[0].loan_term <= 72
                        assert listing.financing_options[0].loan_term >= 36
                        assert listing.financing_options[0].estimated_monthly_payment <=300
                        assert listing.financing_options[0].estimated_monthly_payment >=200
                        assert listing.financing_options[0].down_payment <=5000
                        assert listing.financing_options[0].down_payment >=2000
                        assert listing.financing_options[0].loan_apr <= 5
                        assert listing.financing_options[0].loan_apr >= 4
                        if fl == "finance_down_payment": field_arr.append(listing.financing_options[0].down_payment)
                        if fl == "finance_emp": field_arr.append(listing.financing_options[0].estimated_monthly_payment)
                        if fl == "finance_loan_term": field_arr.append(listing.financing_options[0].loan_term)
                        if fl == "finance_loan_apr": field_arr.append(listing.financing_options[0].loan_apr)
                    if sort_o == "asc":
                        field_arr = filter(None,field_arr)
                        assert field_arr == sorted(field_arr)
                    else:
                        field_arr = filter(None,field_arr)
                        assert field_arr == sorted(field_arr, reverse=True)
        except ApiException as e:
            pprint("Exception when calling ListingsApi->search: %s\n" % e)
        pass


if __name__ == '__main__':
    unittest.main()
