示例#1
0
def test_attr_lookup(mock_find_articles):
    etree_vehicles = \
    services.AS24WSSearch()._etree_vehicles(services.find_articles().content)
    assert services.AS24WSSearch()._attr_lookup(etree_vehicles[0], 'a:brand_id') != \
            '00', "The brand should not be equal to 00"
    assert services.AS24WSSearch()._attr_lookup(etree_vehicles[0], 'a:not_exist') == \
            '', "Should be the empty string"
示例#2
0
def test_vehicle_factory(mock_find_articles):
    etree_vehicles = \
        services.AS24WSSearch()._etree_vehicles(services.find_articles().content)
    vehicle = services.AS24WSSearch()._vehicle_factory(etree_vehicles[0])
    assert isinstance(vehicle, services.Vehicle), "Should be type of Vehicle"
    assert isinstance(vehicle.brand_id, str), \
            "Brand should be filled with a value"
示例#3
0
def test_filter_brands(mock_find_articles, mock_lookup):
    for elem in services.AS24WSSearch().get_lookup_data():
        mixer.blend('inventory.Enumeration', **elem)
    vehicles = services.AS24WSSearch().list_vehicles()
    brands = services.filter_brands(vehicles)
    assert isinstance(brands, dict), "Should return a dictionary"
    assert all([value for value in brands.values()]), \
            "No value should be equal to nothing"
示例#4
0
def test_vehicles_factory(mock_find_articles):
    etree_vehicles = \
    services.AS24WSSearch()._etree_vehicles(services.find_articles().content)
    vehicles = services.AS24WSSearch()._vehicles_factory(etree_vehicles)
    assert check_obj_not_empty(vehicles[0]), \
            "The first vehicle of the list should not be empty"
    assert all(check_obj_not_empty(obj) for obj in vehicles), \
            "None of the vehicule should be empty"
示例#5
0
def test_images_factory(mock_find_articles):
    etree_vehicles = \
        services.AS24WSSearch()._etree_vehicles(services.find_articles().content)
    all_images = \
            etree_vehicles[0].findall('a:media/a:images/a:image/a:uri',\
                                services.AS24WSSearch().name_spaces)
    result = services.AS24WSSearch()._images_factory(all_images)
    assert isinstance(result, list), "Should be an instance of list"
    assert all('.jpg' in item for item in result), \
            "Should contains images"
示例#6
0
def test_equipments_factory(mock_find_articles):
    etree_vehicles = \
    services.AS24WSSearch()._etree_vehicles(services.find_articles().content)

    etree_equipment_ids = \
            etree_vehicles[0].findall('a:equipments/a:equipment_id',\
                                    services.AS24WSSearch().name_spaces)
    result = services.AS24WSSearch()._equipments_factory(\
                                            etree_equipment_ids)
    assert isinstance(result, list), "Should be an instance of list"
    assert all(isinstance(int(item), int) for item in result), \
            "Should contains number or nothing"
    assert all(isinstance(int(item), int) for item in []), \
            "Should contains number or nothing"
示例#7
0
def test_get_enumerations(mock_lookup):
    result = services.AS24WSSearch().get_lookup_data()
    assert isinstance(result, list), "Should return a dict"
    assert isinstance(result[0], dict), \
            "The elements of the list should be dict"
    assert all([all(elem.values()) for elem in result])
    assert len(result) != 0, \
            "The number of elements is not null"
示例#8
0
def vehicles_list(request):
    """ Return the context and render templates """
    autoscout = services.AS24WSSearch()
    images_uri = autoscout.uri_images('main')
    vehicles = autoscout.list_vehicles()
    brands = services.filter_brands(vehicles)
    context = {\
        'vehicles': vehicles,
        'images_uri': images_uri,
        'brands': brands\
    }
    return render(request, 'inventory/list_cars.html', context)
示例#9
0
def test_uri():
    # pylint: disable=unnecessary-lambda
    check = lambda x: services.AS24WSSearch().uri_images(x)
    assert '/images/' in check('main'), \
            "Should return a URI containing /images/"
    assert '/images-big/' in check('big'), \
            "Should return a URI containing /images-big/"
    assert '/images-small/' in check('small'), \
            "Should return a URI containing /images-small/"
    assert '/thumbnails-big/' in check('thumb'), \
            "Should return a URI containing /thumbnails-big/"
    with pytest.raises(ValueError):
        check('anything')
示例#10
0
def test_list_vehicles(mock_find_articles):
    result = services.AS24WSSearch().list_vehicles()
    assert isinstance(result, list), \
            "Should return a list"
    assert isinstance(result[0], services.Vehicle), \
            "Should return a list of Vehicle"
    empty_vehicle = services.Vehicle()
    assert not check_obj_not_empty(empty_vehicle), \
            "This empty vehicle should be empty"
    assert check_obj_not_empty(result[0]), \
            "The first vehicle of the list should not be empty"
    assert all(check_obj_not_empty(obj) for obj in result), \
            "None of the vehicule should be empty"
示例#11
0
def vehicle_details(request, vehicle_id):
    """ Return the detail of a vehicle """
    autoscout = services.AS24WSSearch()
    vehicles = autoscout.list_vehicles()
    try:
        vehicle = autoscout.details_vehicle(vehicle_id)
    except IndexError:
        raise Http404('The page does not exists')

    uri_images_big = autoscout.uri_images('big')
    uri_images_main = autoscout.uri_images('main')
    uri_images_thumb = autoscout.uri_images('thumb')
    context = {\
        'vehicle': vehicle,
        'vehicles': vehicles,
        'uri_images_big': uri_images_big,
        'uri_images_thumb': uri_images_thumb,
        'uri_images_main': uri_images_main\
    }
    return render(request, 'inventory/details_car.html', context)
示例#12
0
def test_details_vehicle(mock_get_article_details):
    vehicle = services.AS24WSSearch().details_vehicle(3455334)
    assert isinstance(vehicle, \
                      services.Vehicle), "It should be an instance of Vehicle"
    assert check_obj_not_empty(vehicle), "This instance should not be empty"
示例#13
0
def test__parse_xml():
    soap_response = open('inventory/tests/soap_lookup_response.xml').read()
    assert isinstance(services.AS24WSSearch()._parse_xml(soap_response), \
                     ElementTree.Element)
示例#14
0
def test_initial_registration(mock_find_articles):
    vehicle = services.AS24WSSearch().list_vehicles()[0]
    assert isinstance(vehicle.initial_registration, str), \
            "The date should be of type string"
    assert search(r'\d\d/\d\d', vehicle.initial_registration), \
            "The date should have the format mm/yy"
示例#15
0
def test_etree_vehicles(mock_find_articles):
    etree_vehicles = \
    services.AS24WSSearch()._etree_vehicles(services.find_articles().content)
    assert isinstance(etree_vehicles, list), "Should be a list"
    assert isinstance(etree_vehicles[0], ElementTree.Element), \
            "Should be a ElementTree"
示例#16
0
def db_enum():
    for elem in services.AS24WSSearch().get_lookup_data():
        mixer.blend('inventory.Enumeration', **elem)