Ejemplo n.º 1
0
async def sample(page_number: int = 1,
                 page_size: int = 20,
                 start_page_as_1: bool = True):
    dataset = requests.get(
        "https://api.punkapi.com/v2/beers?brewed_before=11-2012&abv_gt=6")
    data_json = dataset.json()
    data = get_sample(data_json)

    total_count = len(data)
    result = pagenation(page_number, page_size, total_count, data,
                        start_page_as_1)

    return SampleInResponse(
        pageNumber=page_number,
        pageSize=page_size,
        totalCount=total_count,
        listings=result["listings"],
    )
Ejemplo n.º 2
0
def test_pagenation_400_initial_default():

    d = pagenation(1, 20, 400, list(range(0, 400)))
    print(d["listings"])
    print(list(range(0, 20)))
    assert d["listings"] == list(range(0, 20))
Ejemplo n.º 3
0
def test_pagenation_400_set_start_1_equals_True_and_init_as_pagenumber_as_0():
    """Exception case
    """
    with pytest.raises(Exception, match=r".* starts > 0. *"):
        d = pagenation(0, 20, 400, list(range(0, 400)))
Ejemplo n.º 4
0
def test_pagenation_400_start_1():

    d = pagenation(20, 20, 400, list(range(0, 400)))
    print(d["listings"])
    print(list(range(380, 400)))
    assert d["listings"] == list(range(380, 400))
Ejemplo n.º 5
0
def test_pagenation_400_start_0():

    d = pagenation(19, 20, 400, list(range(0, 400)), start_page_as_1=False)
    print(d["listings"])
    print(list(range(380, 400)))
    assert d["listings"] == list(range(380, 400))
Ejemplo n.º 6
0
def test_pagenation_400_10th_page():

    d = pagenation(10, 20, 400, list(range(0, 400)))
    print(d["listings"])
    print(list(range(180, 200)))
    assert d["listings"] == list(range(180, 200))