Skip to content

Commit

Permalink
Test delete and local get in integrate test
Browse files Browse the repository at this point in the history
  • Loading branch information
hv0905 committed May 14, 2024
1 parent d3bb411 commit 673138e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
25 changes: 14 additions & 11 deletions tests/api/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import importlib

import pytest
from fastapi.testclient import TestClient

Expand All @@ -6,21 +8,22 @@
TEST_ACCESS_TOKEN = 'test_token'
TEST_ADMIN_TOKEN = 'test_admin_token'

config.config.qdrant.mode = "memory"
config.config.admin_api_enable = True
config.config.access_protected = True
config.config.access_token = TEST_ACCESS_TOKEN
config.config.admin_token = TEST_ADMIN_TOKEN
config.config.storage.method = config.StorageMode.LOCAL


@pytest.fixture(scope="session")
def test_client(tmp_path_factory) -> TestClient:
# Modify the configuration for testing
config.config.qdrant.mode = "memory"
config.config.admin_api_enable = True
config.config.access_protected = True
config.config.access_token = TEST_ACCESS_TOKEN
config.config.admin_token = TEST_ADMIN_TOKEN
config.config.storage.method = config.StorageMode.LOCAL
config.config.storage.local.path = tmp_path_factory.mktemp("static_files")

from app.webapp import app
# Start the application

with TestClient(app) as client:
with TestClient(importlib.import_module('app.webapp').app) as client:
yield client


@pytest.fixture
def anyio_backend():
return 'asyncio'
11 changes: 11 additions & 0 deletions tests/api/integrate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ async def test_integrate(test_client):
assert resp.status_code == 200
assert resp.json()['result'][0]['img']['id'] in img_ids['bsn']

image_request = test_client.get(resp.json()['result'][0]['img']['url'])
assert image_request.status_code == 200
assert image_request.headers['Content-Type'] == 'image/jpeg'

resp = test_client.put(f"/admin/update_opt/{img_ids['bsn'][0]}", json={'categories': ['bsn'], 'starred': True},
headers=credentials)
assert resp.status_code == 200
Expand All @@ -68,3 +72,10 @@ async def test_integrate(test_client):
resp = test_client.get("/search/text/cat", params={'starred': True}, headers=credentials)
assert resp.status_code == 200
assert resp.json()['result'][0]['img']['id'] in img_ids['bsn']

resp = test_client.delete(f"/admin/delete/{img_ids['bsn'][0]}", headers=credentials)
assert resp.status_code == 200

resp = test_client.get("/search/text/cat", params={'categories': 'bsn'}, headers=credentials)
assert resp.status_code == 200
assert len(resp.json()['result']) == 0
13 changes: 0 additions & 13 deletions tests/api/test_home.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
import pytest
from fastapi.testclient import TestClient

from app.webapp import app

client = TestClient(app)


@pytest.fixture
def anyio_backend():
return 'asyncio'


class TestHome:

def test_get_home_no_tokens(self, test_client):
Expand Down

0 comments on commit 673138e

Please sign in to comment.