From 4ded32cc644763ba857a5e0ed37e33d79e11c70a Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 3 Jan 2024 22:03:08 +0530 Subject: [PATCH] Test 1000 file upload limit to index/update API endpoint Due to FastAPI limitation --- tests/test_client.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_client.py b/tests/test_client.py index 0bc3c02f..0a25bea2 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -169,6 +169,7 @@ def test_index_update_normal_file_unsubscribed(client, api_user4: KhojApiUser): assert response.status_code == 200 +# ---------------------------------------------------------------------------------------------------- @pytest.mark.django_db(transaction=True) def test_index_update_big_files_no_billing(client): # Arrange @@ -197,6 +198,26 @@ def test_index_update(client): assert response.status_code == 200 +# ---------------------------------------------------------------------------------------------------- +@pytest.mark.django_db(transaction=True) +def test_index_update_fails_if_more_than_1000_files(client, api_user4: KhojApiUser): + # Arrange + api_token = api_user4.token + state.billing_enabled = True + files = [("files", (f"path/to/filename{i}.org", f"Symphony No {i}", "text/org")) for i in range(1001)] + + headers = {"Authorization": f"Bearer {api_token}"} + + # Act + ok_response = client.post("/api/v1/index/update", files=files[:1000], headers=headers) + bad_response = client.post("/api/v1/index/update", files=files, headers=headers) + + # Assert + assert ok_response.status_code == 200 + assert bad_response.status_code == 400 + assert bad_response.content.decode("utf-8") == '{"detail":"Too many files. Maximum number of files is 1000."}' + + # ---------------------------------------------------------------------------------------------------- @pytest.mark.django_db(transaction=True) def test_regenerate_with_valid_content_type(client):