From a73c2e0a3dd38f701a0cbeafa7b00866d06ed540 Mon Sep 17 00:00:00 2001 From: NamazovMaksim Date: Wed, 6 May 2026 21:48:41 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=20test=5Fget=5Fitems=5Fpositi?= =?UTF-8?q?ve=5Fcases=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BA=D0=B8=20=D0=BF=D0=BE=D0=B7=D0=B8=D1=82=D0=B8?= =?UTF-8?q?=D0=B2=D0=BD=D1=8B=D1=85=20=D0=BA=D0=B5=D0=B9=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_routes/test_item.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/test_routes/test_item.py b/tests/test_routes/test_item.py index e21a3e8..22698f9 100644 --- a/tests/test_routes/test_item.py +++ b/tests/test_routes/test_item.py @@ -50,11 +50,43 @@ def test_get_item_id(client, dbsession, items_with_types, item_n, response_statu 'item_n,response_status', [(0, status.HTTP_200_OK), (1, status.HTTP_200_OK)], ) -def test_get_items_by_type_id(client, items_with_types, item_n, response_status): +def test_get_items_by_type_id(client, items_with_types, item_n, response_status): query = {"type_id": f'{items_with_types[item_n].type_id}'} response = client.get(f'{url}', params=query) assert response.status_code == response_status +@pytest.mark.parametrize( + "type_id, order_by, order, is_available, response_status", + [(0, None, None, True, status.HTTP_200_OK), + (0, "id", None, True, status.HTTP_200_OK), + (0, "type_id", "asc", False, status.HTTP_200_OK), + (0, "is_available", "desc", False, status.HTTP_200_OK), + (0, None, None, False, status.HTTP_200_OK), + (1, "id", "asc", False, status.HTTP_200_OK), + (1, "type_id", "desc", True, status.HTTP_200_OK), + (1, "is_available", None, True, status.HTTP_200_OK), + (1, None, "asc", True, status.HTTP_200_OK), + (2, "id", "desc", True, status.HTTP_200_OK), + (2, "type_id", None, False, status.HTTP_200_OK), + (2, "is_available", "asc", False, status.HTTP_200_OK), + (2, None, "desc", False, status.HTTP_200_OK), + (None, "id", None, True, status.HTTP_200_OK), + (None, "type_id", "asc", False, status.HTTP_200_OK), + (None, "is_available", "desc", False, status.HTTP_200_OK), + (None, "is_available", "desc", False, status.HTTP_200_OK), + ] + ) +def test_get_items_positive_cases(client, type_id, order_by, order, is_available, response_status): + dict_of_params = {"type_id" : type_id, + "order_by" : order_by, + "order" : order, + "is_availible" : str(is_available).lower() if is_available is not None else None + } + query = {k : v for k, v in dict_of_params.items() if v is not None} + response = client.get(url, params=query) + assert response.status_code == response_status + + @pytest.mark.parametrize( 'item_n,body,response_status', From f6d27f3858a915cbfdc92d73200a0ec90d0ce885 Mon Sep 17 00:00:00 2001 From: NamazovMaksim Date: Thu, 7 May 2026 01:04:53 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=20tests=5Fget=5Fitems=5Fpositive=5Fcases,=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0=20=D0=B2=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B4=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BA=D0=B0=D0=B6=D0=B4=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20item?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_routes/test_item.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/tests/test_routes/test_item.py b/tests/test_routes/test_item.py index 22698f9..522bbbc 100644 --- a/tests/test_routes/test_item.py +++ b/tests/test_routes/test_item.py @@ -56,7 +56,7 @@ def test_get_items_by_type_id(client, items_with_types, item_n, response_status) assert response.status_code == response_status @pytest.mark.parametrize( - "type_id, order_by, order, is_available, response_status", + "item_n, order_by, order, is_available, response_status", [(0, None, None, True, status.HTTP_200_OK), (0, "id", None, True, status.HTTP_200_OK), (0, "type_id", "asc", False, status.HTTP_200_OK), @@ -66,27 +66,42 @@ def test_get_items_by_type_id(client, items_with_types, item_n, response_status) (1, "type_id", "desc", True, status.HTTP_200_OK), (1, "is_available", None, True, status.HTTP_200_OK), (1, None, "asc", True, status.HTTP_200_OK), - (2, "id", "desc", True, status.HTTP_200_OK), - (2, "type_id", None, False, status.HTTP_200_OK), - (2, "is_available", "asc", False, status.HTTP_200_OK), - (2, None, "desc", False, status.HTTP_200_OK), + (0, "id", "desc", True, status.HTTP_200_OK), + (1, "type_id", None, False, status.HTTP_200_OK), + (0, "is_available", "asc", False, status.HTTP_200_OK), + (0, None, "desc", False, status.HTTP_200_OK), (None, "id", None, True, status.HTTP_200_OK), (None, "type_id", "asc", False, status.HTTP_200_OK), (None, "is_available", "desc", False, status.HTTP_200_OK), (None, "is_available", "desc", False, status.HTTP_200_OK), ] ) -def test_get_items_positive_cases(client, type_id, order_by, order, is_available, response_status): - dict_of_params = {"type_id" : type_id, +def test_get_items_positive_cases(client, items_with_same_type, item_n, order_by, order, is_available, response_status): + dict_of_params = {"type_id" : items_with_same_type[item_n].type_id if item_n is not None else None, "order_by" : order_by, "order" : order, "is_availible" : str(is_available).lower() if is_available is not None else None } + pytest.set_trace() query = {k : v for k, v in dict_of_params.items() if v is not None} response = client.get(url, params=query) assert response.status_code == response_status - - + data = response.json() + assert isinstance(data, list) + assert len(data) > 0 + for item in data: + assert "id" in item + assert "type_id" in item + +""" +@pytest.parametrize( + ) +def test_get_items_check_desc_order(client,): + ... + response = client.get(url, params=query) + data = response.json() + assert data[0]["id"] > data[-1]["id"] +""" @pytest.mark.parametrize( 'item_n,body,response_status', From c20cd7998498610fa55fe9b8abf41d42debacaf8 Mon Sep 17 00:00:00 2001 From: NamazovMaksim Date: Thu, 7 May 2026 19:49:46 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=20=D1=81=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B7=D0=B8=D1=82=D0=B8=D0=B2=D0=BD=D1=8B=D0=BC=D0=B8=20=D0=BA?= =?UTF-8?q?=D0=B5=D0=B9=D1=81=D0=B0=D0=BC=D0=B8,=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B8=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20=D1=81=D0=BE=D1=80=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=BA=D0=B8=20item-=D0=BE=D0=B2.=20=D0=92=20?= =?UTF-8?q?conftest.py=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=84=D0=B8=D0=BA=D1=81=D1=82=D1=83=D1=80=D0=B0,=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D1=8E=D1=89=D0=B0=D1=8F=206=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=BD=D1=8B=D1=85=20item-=D0=BE=D0=B2,=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=B0=D0=B7=D1=83=D1=8E=D1=89=D0=B8=D1=85=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=80=D1=8B=20=D0=BF=D0=BE=20=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=D0=BA=D0=BE=D0=B2=D1=8B=D0=BC=20type=5Fid,=20?= =?UTF-8?q?=D0=BD=D0=BE=20=D1=80=D0=B0=D0=B7=D0=BD=D1=8B=D0=BC=D0=B8=20is?= =?UTF-8?q?=5Favailable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/conftest.py | 32 +++++++++++++++ tests/test_routes/test_item.py | 75 ++++++++++++++++++++++++++++++---- 2 files changed, 98 insertions(+), 9 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index dba7c9e..fd8a0b2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -278,6 +278,37 @@ def items_with_types(dbsession): dbsession.commit() yield items +@pytest.fixture() +def items_with_different_types(dbsession): + """Фикстура Item. + + .. note:: + Фикстура создает 6 item. Каждые 2 с одинаковым типом и разными значениями is_available. + """ + + item_types = [ + ItemType(name="Type1"), + ItemType(name="Type2"), + ItemType(name="Type3"), + ] + for item_type in item_types: + dbsession.add(item_type) + dbsession.commit() + + items = [ + Item(type_id=item_types[0].id, is_available=True), + Item(type_id=item_types[0].id, is_available=False), + Item(type_id=item_types[1].id, is_available=True), + Item(type_id=item_types[1].id, is_available=False), + Item(type_id=item_types[2].id, is_available=True), + Item(type_id=item_types[2].id, is_available=False), + ] + for item in items: + dbsession.add(item) + dbsession.commit() + yield items + + @pytest.fixture() def items_with_same_type_id(dbsession): @@ -338,6 +369,7 @@ def blocking_session(request, dbsession, two_available_items_same_type, authlib_ items[0].is_available = False dbsession.add(session, items[0]) dbsession.commit() + return item_type diff --git a/tests/test_routes/test_item.py b/tests/test_routes/test_item.py index 522bbbc..4189ac1 100644 --- a/tests/test_routes/test_item.py +++ b/tests/test_routes/test_item.py @@ -76,13 +76,12 @@ def test_get_items_by_type_id(client, items_with_types, item_n, response_status) (None, "is_available", "desc", False, status.HTTP_200_OK), ] ) -def test_get_items_positive_cases(client, items_with_same_type, item_n, order_by, order, is_available, response_status): - dict_of_params = {"type_id" : items_with_same_type[item_n].type_id if item_n is not None else None, +def test_get_items_positive_cases(client, items_with_types, item_n, order_by, order, is_available, response_status): + dict_of_params = {"type_id" : items_with_types[item_n].type_id if item_n is not None else None, "order_by" : order_by, "order" : order, "is_availible" : str(is_available).lower() if is_available is not None else None } - pytest.set_trace() query = {k : v for k, v in dict_of_params.items() if v is not None} response = client.get(url, params=query) assert response.status_code == response_status @@ -93,15 +92,73 @@ def test_get_items_positive_cases(client, items_with_same_type, item_n, order_by assert "id" in item assert "type_id" in item -""" -@pytest.parametrize( + +@pytest.mark.parametrize( + "item_n, order_by, order, response_status", + [(None, None, "desc", status.HTTP_200_OK), + (0, None, "desc", status.HTTP_200_OK), + ] ) -def test_get_items_check_desc_order(client,): - ... +def test_get_items_check_desc_order_by_id(client, items_with_different_types, item_n, order_by, order, response_status): + dict_of_params = {"type_id" : items_with_different_types[item_n].type_id if item_n is not None else None, + "order_by" : order_by, + "order" : order, + } + pytest.set_trace() + query = {k : v for k, v in dict_of_params.items() if v is not None} response = client.get(url, params=query) + assert response.status_code == response_status + data = response.json() - assert data[0]["id"] > data[-1]["id"] -""" + + key = lambda x: x["id"] + compare = lambda x, y: x >= y + assert all(compare(key(x), key(y)) for x, y in zip(data, data[1:])) is True + + +@pytest.mark.parametrize( + "item_n, order_by, order, response_status", + [(None, "type_id", "desc", status.HTTP_200_OK), + (1, "type_id", "desc", status.HTTP_200_OK), + ] + ) +def test_get_items_check_desc_order_by_type_id(client, items_with_different_types, item_n, order_by, order, response_status): + dict_of_params = {"type_id" : items_with_different_types[item_n].type_id if item_n is not None else None, + "order_by" : order_by, + "order" : order, + } + query = {k : v for k, v in dict_of_params.items() if v is not None} + response = client.get(url, params=query) + assert response.status_code == response_status + + data = response.json() + + key = lambda x: x["type_id"] + compare = lambda x, y: x >= y + assert all(compare(key(x), key(y)) for x, y in zip(data, data[1:])) is True + +@pytest.mark.parametrize( + "item_n, order_by, order, response_status", + [(None, "is_available", "desc", status.HTTP_200_OK), + (1, "is_available", "desc", status.HTTP_200_OK), + ] + ) +def test_get_items_check_desc_order_by_is_available(client, items_with_different_types, item_n, order_by, order, response_status): + dict_of_params = {"type_id" : items_with_different_types[item_n].type_id if item_n is not None else None, + "order_by" : order_by, + "order" : order, + } + query = {k : v for k, v in dict_of_params.items() if v is not None} + response = client.get(url, params=query) + assert response.status_code == response_status + + data = response.json() + + key = lambda x: x["is_available"] + compare = lambda x, y: x >= y + assert all(compare(key(x), key(y)) for x, y in zip(data, data[1:])) is True + + @pytest.mark.parametrize( 'item_n,body,response_status', From 7c49d5691ffe696b5267e92ae506fb5e1d8f19a7 Mon Sep 17 00:00:00 2001 From: NamazovMaksim Date: Thu, 7 May 2026 20:04:26 +0300 Subject: [PATCH 4/6] pdb breackpoint removed, formatting was performed --- tests/conftest.py | 4 +- tests/test_routes/test_item.py | 132 ++++++++++++++++++--------------- 2 files changed, 74 insertions(+), 62 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index fd8a0b2..17b9b70 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -278,10 +278,11 @@ def items_with_types(dbsession): dbsession.commit() yield items + @pytest.fixture() def items_with_different_types(dbsession): """Фикстура Item. - + .. note:: Фикстура создает 6 item. Каждые 2 с одинаковым типом и разными значениями is_available. """ @@ -309,7 +310,6 @@ def items_with_different_types(dbsession): yield items - @pytest.fixture() def items_with_same_type_id(dbsession): """Фикстура Item. diff --git a/tests/test_routes/test_item.py b/tests/test_routes/test_item.py index 4189ac1..8e0dfa3 100644 --- a/tests/test_routes/test_item.py +++ b/tests/test_routes/test_item.py @@ -50,39 +50,42 @@ def test_get_item_id(client, dbsession, items_with_types, item_n, response_statu 'item_n,response_status', [(0, status.HTTP_200_OK), (1, status.HTTP_200_OK)], ) -def test_get_items_by_type_id(client, items_with_types, item_n, response_status): +def test_get_items_by_type_id(client, items_with_types, item_n, response_status): query = {"type_id": f'{items_with_types[item_n].type_id}'} response = client.get(f'{url}', params=query) assert response.status_code == response_status + @pytest.mark.parametrize( "item_n, order_by, order, is_available, response_status", - [(0, None, None, True, status.HTTP_200_OK), - (0, "id", None, True, status.HTTP_200_OK), - (0, "type_id", "asc", False, status.HTTP_200_OK), - (0, "is_available", "desc", False, status.HTTP_200_OK), - (0, None, None, False, status.HTTP_200_OK), - (1, "id", "asc", False, status.HTTP_200_OK), - (1, "type_id", "desc", True, status.HTTP_200_OK), - (1, "is_available", None, True, status.HTTP_200_OK), - (1, None, "asc", True, status.HTTP_200_OK), - (0, "id", "desc", True, status.HTTP_200_OK), - (1, "type_id", None, False, status.HTTP_200_OK), - (0, "is_available", "asc", False, status.HTTP_200_OK), - (0, None, "desc", False, status.HTTP_200_OK), - (None, "id", None, True, status.HTTP_200_OK), - (None, "type_id", "asc", False, status.HTTP_200_OK), - (None, "is_available", "desc", False, status.HTTP_200_OK), - (None, "is_available", "desc", False, status.HTTP_200_OK), - ] - ) + [ + (0, None, None, True, status.HTTP_200_OK), + (0, "id", None, True, status.HTTP_200_OK), + (0, "type_id", "asc", False, status.HTTP_200_OK), + (0, "is_available", "desc", False, status.HTTP_200_OK), + (0, None, None, False, status.HTTP_200_OK), + (1, "id", "asc", False, status.HTTP_200_OK), + (1, "type_id", "desc", True, status.HTTP_200_OK), + (1, "is_available", None, True, status.HTTP_200_OK), + (1, None, "asc", True, status.HTTP_200_OK), + (0, "id", "desc", True, status.HTTP_200_OK), + (1, "type_id", None, False, status.HTTP_200_OK), + (0, "is_available", "asc", False, status.HTTP_200_OK), + (0, None, "desc", False, status.HTTP_200_OK), + (None, "id", None, True, status.HTTP_200_OK), + (None, "type_id", "asc", False, status.HTTP_200_OK), + (None, "is_available", "desc", False, status.HTTP_200_OK), + (None, "is_available", "desc", False, status.HTTP_200_OK), + ], +) def test_get_items_positive_cases(client, items_with_types, item_n, order_by, order, is_available, response_status): - dict_of_params = {"type_id" : items_with_types[item_n].type_id if item_n is not None else None, - "order_by" : order_by, - "order" : order, - "is_availible" : str(is_available).lower() if is_available is not None else None - } - query = {k : v for k, v in dict_of_params.items() if v is not None} + dict_of_params = { + "type_id": items_with_types[item_n].type_id if item_n is not None else None, + "order_by": order_by, + "order": order, + "is_availible": str(is_available).lower() if is_available is not None else None, + } + query = {k: v for k, v in dict_of_params.items() if v is not None} response = client.get(url, params=query) assert response.status_code == response_status data = response.json() @@ -95,22 +98,23 @@ def test_get_items_positive_cases(client, items_with_types, item_n, order_by, or @pytest.mark.parametrize( "item_n, order_by, order, response_status", - [(None, None, "desc", status.HTTP_200_OK), - (0, None, "desc", status.HTTP_200_OK), - ] - ) + [ + (None, None, "desc", status.HTTP_200_OK), + (0, None, "desc", status.HTTP_200_OK), + ], +) def test_get_items_check_desc_order_by_id(client, items_with_different_types, item_n, order_by, order, response_status): - dict_of_params = {"type_id" : items_with_different_types[item_n].type_id if item_n is not None else None, - "order_by" : order_by, - "order" : order, - } - pytest.set_trace() - query = {k : v for k, v in dict_of_params.items() if v is not None} + dict_of_params = { + "type_id": items_with_different_types[item_n].type_id if item_n is not None else None, + "order_by": order_by, + "order": order, + } + query = {k: v for k, v in dict_of_params.items() if v is not None} response = client.get(url, params=query) assert response.status_code == response_status data = response.json() - + key = lambda x: x["id"] compare = lambda x, y: x >= y assert all(compare(key(x), key(y)) for x, y in zip(data, data[1:])) is True @@ -118,48 +122,56 @@ def test_get_items_check_desc_order_by_id(client, items_with_different_types, it @pytest.mark.parametrize( "item_n, order_by, order, response_status", - [(None, "type_id", "desc", status.HTTP_200_OK), - (1, "type_id", "desc", status.HTTP_200_OK), - ] - ) -def test_get_items_check_desc_order_by_type_id(client, items_with_different_types, item_n, order_by, order, response_status): - dict_of_params = {"type_id" : items_with_different_types[item_n].type_id if item_n is not None else None, - "order_by" : order_by, - "order" : order, - } - query = {k : v for k, v in dict_of_params.items() if v is not None} + [ + (None, "type_id", "desc", status.HTTP_200_OK), + (1, "type_id", "desc", status.HTTP_200_OK), + ], +) +def test_get_items_check_desc_order_by_type_id( + client, items_with_different_types, item_n, order_by, order, response_status +): + dict_of_params = { + "type_id": items_with_different_types[item_n].type_id if item_n is not None else None, + "order_by": order_by, + "order": order, + } + query = {k: v for k, v in dict_of_params.items() if v is not None} response = client.get(url, params=query) assert response.status_code == response_status data = response.json() - + key = lambda x: x["type_id"] compare = lambda x, y: x >= y assert all(compare(key(x), key(y)) for x, y in zip(data, data[1:])) is True + @pytest.mark.parametrize( "item_n, order_by, order, response_status", - [(None, "is_available", "desc", status.HTTP_200_OK), - (1, "is_available", "desc", status.HTTP_200_OK), - ] - ) -def test_get_items_check_desc_order_by_is_available(client, items_with_different_types, item_n, order_by, order, response_status): - dict_of_params = {"type_id" : items_with_different_types[item_n].type_id if item_n is not None else None, - "order_by" : order_by, - "order" : order, - } - query = {k : v for k, v in dict_of_params.items() if v is not None} + [ + (None, "is_available", "desc", status.HTTP_200_OK), + (1, "is_available", "desc", status.HTTP_200_OK), + ], +) +def test_get_items_check_desc_order_by_is_available( + client, items_with_different_types, item_n, order_by, order, response_status +): + dict_of_params = { + "type_id": items_with_different_types[item_n].type_id if item_n is not None else None, + "order_by": order_by, + "order": order, + } + query = {k: v for k, v in dict_of_params.items() if v is not None} response = client.get(url, params=query) assert response.status_code == response_status data = response.json() - + key = lambda x: x["is_available"] compare = lambda x, y: x >= y assert all(compare(key(x), key(y)) for x, y in zip(data, data[1:])) is True - @pytest.mark.parametrize( 'item_n,body,response_status', [ From b08c590e716f1f7116f9bb875ca89adb212b8166 Mon Sep 17 00:00:00 2001 From: NamazovMaksim Date: Fri, 8 May 2026 21:03:44 +0300 Subject: [PATCH 5/6] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D0=B0=20=D1=81=20test=5Fget=5Fitems=5F?= =?UTF-8?q?positive=5Fcases=20=D0=BD=D0=B0=20test=5Fget=5Fitems=5Fvarious?= =?UTF-8?q?=5Ffilters.=20=D0=92=20test=5Fget=5Fitems=5Fvarious=5Ffilters?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=BE=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D0=BC?= =?UTF-8?q?=D1=8B=D1=85=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= =?UTF-8?q?.=20=D0=A2=D0=B0=D0=BA=20=D0=B6=D0=B5=20=D0=B2=D0=BC=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=BE=20=D1=84=D0=B8=D0=BA=D1=81=D1=82=D1=83=D1=80?= =?UTF-8?q?=D1=8B=20items=5Fwith=5Ftypes=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D1=8C=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D1=84=D0=B8=D0=BA=D1=81=D1=82=D1=83=D1=80?= =?UTF-8?q?=D0=B0=20items=5Fwith=5Fdifferent=5Ftypes.=20=D0=A2=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D1=8B=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=BE=D1=80=D1=8F=D0=B4=D0=BA=D0=B0=20=D1=81=D0=BE?= =?UTF-8?q?=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=8A=D0=B5=D0=B4=D0=B8=D0=BD=D0=B8=D0=BD=D1=8B=20=D0=B2=20?= =?UTF-8?q?=D0=BE=D0=B4=D0=B8=D0=BD,=20test=5Fget=5Fitems=5Fcheck=5Forder?= =?UTF-8?q?=20=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20asc=20=D0=BF=D0=BE=D1=80?= =?UTF-8?q?=D1=8F=D0=B4=D0=BA=D0=B0=20item-=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_routes/test_item.py | 110 ++++++++++----------------------- 1 file changed, 31 insertions(+), 79 deletions(-) diff --git a/tests/test_routes/test_item.py b/tests/test_routes/test_item.py index 8e0dfa3..3673c8d 100644 --- a/tests/test_routes/test_item.py +++ b/tests/test_routes/test_item.py @@ -57,43 +57,40 @@ def test_get_items_by_type_id(client, items_with_types, item_n, response_status) @pytest.mark.parametrize( - "item_n, order_by, order, is_available, response_status", + "item_n, order_by, order, is_available, response_status, expected_len", [ - (0, None, None, True, status.HTTP_200_OK), - (0, "id", None, True, status.HTTP_200_OK), - (0, "type_id", "asc", False, status.HTTP_200_OK), - (0, "is_available", "desc", False, status.HTTP_200_OK), - (0, None, None, False, status.HTTP_200_OK), - (1, "id", "asc", False, status.HTTP_200_OK), - (1, "type_id", "desc", True, status.HTTP_200_OK), - (1, "is_available", None, True, status.HTTP_200_OK), - (1, None, "asc", True, status.HTTP_200_OK), - (0, "id", "desc", True, status.HTTP_200_OK), - (1, "type_id", None, False, status.HTTP_200_OK), - (0, "is_available", "asc", False, status.HTTP_200_OK), - (0, None, "desc", False, status.HTTP_200_OK), - (None, "id", None, True, status.HTTP_200_OK), - (None, "type_id", "asc", False, status.HTTP_200_OK), - (None, "is_available", "desc", False, status.HTTP_200_OK), - (None, "is_available", "desc", False, status.HTTP_200_OK), + (0, None, None, True, status.HTTP_200_OK, 1), + (0, "id", None, True, status.HTTP_200_OK, 1), + (0, "type_id", "asc", False, status.HTTP_200_OK, 1), + (0, "is_available", "desc", False, status.HTTP_200_OK, 1), + (0, None, None, None, status.HTTP_200_OK, 2), + (1, "id", "asc", False, status.HTTP_200_OK, 1), + (1, "type_id", "desc", True, status.HTTP_200_OK, 1), + (1, "is_available", None, True, status.HTTP_200_OK, 1), + (1, None, "asc", True, status.HTTP_200_OK, 1), + (2, "id", "desc", True, status.HTTP_200_OK, 1), + (2, "type_id", None, False, status.HTTP_200_OK, 1), + (2, "is_available", "asc", False, status.HTTP_200_OK, 1), + (2, None, "desc", None, status.HTTP_200_OK, 2), + (-1, "id", None, True, status.HTTP_200_OK, 3), + (-1, "type_id", "asc", False, status.HTTP_200_OK, 3), + (-1, "is_available", "desc", None, status.HTTP_200_OK, 6), + (-1, None, "desc", None, status.HTTP_200_OK, 6), ], ) -def test_get_items_positive_cases(client, items_with_types, item_n, order_by, order, is_available, response_status): +def test_get_items_by_various_filters(client, items_with_different_types, item_n, order_by, order, is_available, response_status, expected_len): dict_of_params = { - "type_id": items_with_types[item_n].type_id if item_n is not None else None, + "type_id": items_with_different_types[item_n].type_id if item_n != -1 else None, "order_by": order_by, "order": order, - "is_availible": str(is_available).lower() if is_available is not None else None, + "is_available": is_available if is_available is not None else None, } query = {k: v for k, v in dict_of_params.items() if v is not None} response = client.get(url, params=query) assert response.status_code == response_status + data = response.json() - assert isinstance(data, list) - assert len(data) > 0 - for item in data: - assert "id" in item - assert "type_id" in item + assert len(data) == expected_len @pytest.mark.parametrize( @@ -101,61 +98,13 @@ def test_get_items_positive_cases(client, items_with_types, item_n, order_by, or [ (None, None, "desc", status.HTTP_200_OK), (0, None, "desc", status.HTTP_200_OK), - ], -) -def test_get_items_check_desc_order_by_id(client, items_with_different_types, item_n, order_by, order, response_status): - dict_of_params = { - "type_id": items_with_different_types[item_n].type_id if item_n is not None else None, - "order_by": order_by, - "order": order, - } - query = {k: v for k, v in dict_of_params.items() if v is not None} - response = client.get(url, params=query) - assert response.status_code == response_status - - data = response.json() - - key = lambda x: x["id"] - compare = lambda x, y: x >= y - assert all(compare(key(x), key(y)) for x, y in zip(data, data[1:])) is True - - -@pytest.mark.parametrize( - "item_n, order_by, order, response_status", - [ (None, "type_id", "desc", status.HTTP_200_OK), (1, "type_id", "desc", status.HTTP_200_OK), - ], -) -def test_get_items_check_desc_order_by_type_id( - client, items_with_different_types, item_n, order_by, order, response_status -): - dict_of_params = { - "type_id": items_with_different_types[item_n].type_id if item_n is not None else None, - "order_by": order_by, - "order": order, - } - query = {k: v for k, v in dict_of_params.items() if v is not None} - response = client.get(url, params=query) - assert response.status_code == response_status - - data = response.json() - - key = lambda x: x["type_id"] - compare = lambda x, y: x >= y - assert all(compare(key(x), key(y)) for x, y in zip(data, data[1:])) is True - - -@pytest.mark.parametrize( - "item_n, order_by, order, response_status", - [ (None, "is_available", "desc", status.HTTP_200_OK), - (1, "is_available", "desc", status.HTTP_200_OK), + (2, "is_available", "desc", status.HTTP_200_OK), ], ) -def test_get_items_check_desc_order_by_is_available( - client, items_with_different_types, item_n, order_by, order, response_status -): +def test_get_items_check_order(client, items_with_different_types, item_n, order_by, order, response_status): dict_of_params = { "type_id": items_with_different_types[item_n].type_id if item_n is not None else None, "order_by": order_by, @@ -167,9 +116,12 @@ def test_get_items_check_desc_order_by_is_available( data = response.json() - key = lambda x: x["is_available"] - compare = lambda x, y: x >= y - assert all(compare(key(x), key(y)) for x, y in zip(data, data[1:])) is True + check_order_by = query.get("order_by") or "id" + check_order = query.get("order") or "asc" + + key = lambda x: x[check_order_by] + compare = (lambda x, y: x >= y) if check_order == "desc" else (lambda x, y: x <= y) + assert all(compare(key(x), key(y)) for x, y in zip(data, data[1:])) @pytest.mark.parametrize( From 9c3475222200609ed0adba60614897ff34354e00 Mon Sep 17 00:00:00 2001 From: NamazovMaksim Date: Sat, 9 May 2026 00:32:20 +0300 Subject: [PATCH 6/6] formatting was performed --- tests/test_routes/test_item.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_routes/test_item.py b/tests/test_routes/test_item.py index 3673c8d..5f0e4d7 100644 --- a/tests/test_routes/test_item.py +++ b/tests/test_routes/test_item.py @@ -78,7 +78,9 @@ def test_get_items_by_type_id(client, items_with_types, item_n, response_status) (-1, None, "desc", None, status.HTTP_200_OK, 6), ], ) -def test_get_items_by_various_filters(client, items_with_different_types, item_n, order_by, order, is_available, response_status, expected_len): +def test_get_items_by_various_filters( + client, items_with_different_types, item_n, order_by, order, is_available, response_status, expected_len +): dict_of_params = { "type_id": items_with_different_types[item_n].type_id if item_n != -1 else None, "order_by": order_by,