Exemplo n.º 1
0
def test_missing_argument_error(api_url,
                                api_key,
                                product_id,
                                endpoint,
                                version=1):
    '''Testing missing argument errors'''

    tomorrow = get_tomorrow()
    warnings: List[str] = []

    # end is missing
    response = client(f'{api_url}/v{version}/products/{product_id}/{endpoint}',
                      api_key, {
                          'start': tomorrow.isoformat(),
                      })
    api_error = get_api_error(response)
    expected_error = ApiError(
        error_code=1000,
        error='Missing argument',
        message="Required argument end was not found",
    )
    result = check_api_error(api_error, expected_error)
    if result.is_warning:
        warnings.append(result.message)

    # start is missing
    response = client(f'{api_url}/v{version}/products/{product_id}/{endpoint}',
                      api_key, {
                          'end': tomorrow.isoformat(),
                      })
    api_error = get_api_error(response)
    expected_error = ApiError(
        error_code=1000,
        error='Missing argument',
        message="Required argument start was not found",
    )
    result = check_api_error(api_error, expected_error)
    if result.is_warning:
        warnings.append(result.message)

    # start and end are missing
    response = client(f'{api_url}/v{version}/products/{product_id}/{endpoint}',
                      api_key)
    api_error = get_api_error(response)
    expected_error = ApiError(
        error_code=1000,
        error='Missing argument',
        message="Required argument start was not found",
    )
    result = check_api_error(api_error, expected_error)
    if result.is_warning:
        warnings.append(result.message)

    if warnings:
        return TestResult(status=1, message='\n '.join(warnings))
    return TestResult()
Exemplo n.º 2
0
def incorrect_date_format(api_url, api_key, product_id, endpoint, version=1):
    '''Checking incorrect date format'''
    tomorrow = get_tomorrow()
    bad_date_format = tomorrow.strftime('%d-%m-%Y')

    # start date in a bad format
    response = client(f'{api_url}/v{version}/products/{product_id}/{endpoint}',
                      api_key, {
                          'start': bad_date_format,
                          'end': tomorrow.isoformat(),
                      })
    api_error = get_api_error(response)
    expected_error = ApiError(
        error_code=2000,
        error='Incorrect date format',
        message=
        f'Incorrect date format {bad_date_format}, please use the YYYY-dd-mm format',
    )
    check_api_error(api_error, expected_error)

    # end date in a bad format
    response = client(f'{api_url}/v{version}/products/{product_id}/{endpoint}',
                      api_key, {
                          'start': tomorrow.isoformat(),
                          'end': bad_date_format,
                      })
    api_error = get_api_error(response)
    expected_error = ApiError(
        error_code=2000,
        error='Incorrect date format',
        message=
        f'Incorrect date format {bad_date_format}, please use the YYYY-dd-mm format',
    )
    check_api_error(api_error, expected_error)

    return TestResult()
Exemplo n.º 3
0
def end_before_start_error(api_url, api_key, product_id, endpoint, version=1):
    '''Checking incorrect range error'''
    tomorrow = get_tomorrow()
    next_week = tomorrow + timedelta(days=7)
    response = client(f'{api_url}/v{version}/products/{product_id}/{endpoint}',
                      api_key, {
                          'start': next_week.isoformat(),
                          'end': tomorrow.isoformat(),
                      })
    api_error = get_api_error(response)
    expected_error = ApiError(
        error_code=2001,
        error='Incorrect date range',
        message='The end date cannot be earlier then start date',
    )
    return check_api_error(api_error, expected_error)
Exemplo n.º 4
0
def huge_date_range(api_url, api_key, product_id, endpoint, version=1):
    '''Checking availability with huge date range'''
    today = datetime.utcnow().date()
    start = today
    end = today + timedelta(days=365 * 10)

    response = client(f'{api_url}/v{version}/products/{product_id}/{endpoint}',
                      api_key, {
                          'start': start.isoformat(),
                          'end': end.isoformat(),
                      })
    api_error = get_api_error(response)
    expected_error = ApiError(
        error_code=2008,
        error='Date range is too wide',
        message='Maximum date range is',
    )
    return check_api_error(api_error, expected_error)
Exemplo n.º 5
0
def past_start_date(api_url, api_key, product_id, endpoint, version=1):
    '''Checking availability with start date from the past'''
    today = datetime.utcnow().date()
    start = today - timedelta(days=1)
    end = today

    response = client(f'{api_url}/v{version}/products/{product_id}/{endpoint}',
                      api_key, {
                          'start': start.isoformat(),
                          'end': end.isoformat(),
                      })
    api_error = get_api_error(response)
    expected_error = ApiError(
        error_code=2007,
        error='Incorrect start date',
        message='Start date cannot be from the past',
    )
    return check_api_error(api_error, expected_error)
Exemplo n.º 6
0
def test_error_for_timeslot_product(api_url,
                                    api_key,
                                    product_id,
                                    endpoint,
                                    version=1):
    '''Testing variant availability for timeslot product'''
    tomorrow = get_tomorrow()
    raw_response, response = client(
        f'{api_url}/v{version}/products/{product_id}/{endpoint}', api_key, {
            'start': tomorrow.isoformat(),
            'end': tomorrow.isoformat(),
        })
    api_error = get_api_error(raw_response, response)
    expected_error = ApiError(
        error_code=1003,
        error='Non-timeslot product expected',
        message=
        f'Requested non timeslot availability for timeslot product ID {product_id}',
    )
    return check_api_error(raw_response, api_error, expected_error)
Exemplo n.º 7
0
def test_error_for_non_existing_product(api_url,
                                        api_key,
                                        product_id,
                                        endpoint,
                                        version=1):
    '''Testing availability for non existing product'''
    tomorrow = get_tomorrow()
    raw_response, response = client(
        f'{api_url}/v{version}/products/NON-EXISTING-PRODUCT-ID/{endpoint}',
        api_key, {
            'start': tomorrow.isoformat(),
            'end': tomorrow.isoformat(),
        })
    api_error = get_api_error(raw_response, response)
    expected_error = ApiError(
        error_code=1001,
        error='Missing product',
        message='Product with ID NON-EXISTING-PRODUCT-ID doesn\'t exist',
    )
    return check_api_error(raw_response, api_error, expected_error)