mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-10-26 23:31:18 +03:00
ci: 🎡 tests (#1615)
fixed # Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
This commit is contained in:
parent
4db7935b23
commit
6bc9dd1894
35
.github/workflows/backend-tests.yml
vendored
35
.github/workflows/backend-tests.yml
vendored
@ -47,26 +47,29 @@ jobs:
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache: "pip"
|
||||
- name: Install system dependencies
|
||||
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install pytest
|
||||
pip install pytest pytest-emoji pytest-md
|
||||
pip install pyright
|
||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||
|
||||
- name: Static type checking with pyright
|
||||
run: |
|
||||
pyright
|
||||
# - name: Test with pytest
|
||||
# env:
|
||||
# SUPABASE_URL: ${{secrets.SUPABASE_URL}}
|
||||
# SUPABASE_SERVICE_KEY: ${{secrets.SUPABASE_SERVICE_KEY}}
|
||||
# PG_DATABASE_URL: ${{secrets.PG_DATABASE_URL}}
|
||||
# OPENAI_API_KEY: ${{secrets.OPENAI_API_KEY}}
|
||||
# ANTHROPIC_API_KEY: ${{secrets.ANTHROPIC_API_KEY}}
|
||||
# JWT_SECRET_KEY: ${{secrets.JWT_SECRET_KEY}}
|
||||
# CI_TEST_API_KEY: ${{secrets.CI_TEST_API_KEY}}
|
||||
# run: |
|
||||
# python -m pytest tests/
|
||||
- name: Run pytest
|
||||
uses: pavelzw/pytest-action@v2
|
||||
with:
|
||||
verbose: true
|
||||
emoji: true
|
||||
job-summary: true
|
||||
click-to-expand: false
|
||||
report-title: 'Test Report'
|
||||
env:
|
||||
SUPABASE_URL: ${{secrets.SUPABASE_URL}}
|
||||
SUPABASE_SERVICE_KEY: ${{secrets.SUPABASE_SERVICE_KEY}}
|
||||
OPENAI_API_KEY: ${{secrets.OPENAI_API_KEY}}
|
||||
ANTHROPIC_API_KEY: ${{secrets.ANTHROPIC_API_KEY}}
|
||||
JWT_SECRET_KEY: ${{secrets.JWT_SECRET_KEY}}
|
||||
CI_TEST_API_KEY: ${{secrets.CI_TEST_API_KEY}}
|
||||
CELERY_BROKER_URL: ${{secrets.CELERY_BROKER_URL}}
|
||||
|
||||
|
||||
|
34
.github/workflows/code-review-gpt.yml
vendored
34
.github/workflows/code-review-gpt.yml
vendored
@ -1,34 +0,0 @@
|
||||
name: Code Review GPT
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
environment: preview
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18
|
||||
|
||||
- name: Install code-review-gpt
|
||||
run: npm install code-review-gpt
|
||||
|
||||
- name: Run code review script
|
||||
run: npx code-review-gpt review --ci
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
||||
GITHUB_SHA: ${{ github.sha }}
|
||||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -66,3 +66,7 @@ frontend/public/robots.txt
|
||||
frontend/public/sitemap*
|
||||
|
||||
pyfiles/*
|
||||
backend/bin/*
|
||||
backend/lib/*
|
||||
backend/pyvenv.cfg
|
||||
backend/share/*
|
||||
|
3
Makefile
3
Makefile
@ -1,4 +1,5 @@
|
||||
|
||||
test:
|
||||
pytest backend/tests
|
||||
|
||||
dev:
|
||||
docker compose -f docker-compose.dev.yml up --build
|
||||
|
@ -36,4 +36,5 @@ flower
|
||||
boto3==1.28.46
|
||||
botocore==1.31.46
|
||||
celery[sqs]
|
||||
python-dotenv
|
||||
|
||||
|
0
backend/tests/__init__.py
Normal file
0
backend/tests/__init__.py
Normal file
@ -1,12 +1,36 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from dotenv import load_dotenv
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def load_env():
|
||||
load_dotenv()
|
||||
print("SUPABASE_URL:", os.getenv("SUPABASE_URL")) # For debugging
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def verify_env_variables():
|
||||
required_vars = [
|
||||
"SUPABASE_URL",
|
||||
"SUPABASE_SERVICE_KEY",
|
||||
"OPENAI_API_KEY",
|
||||
"JWT_SECRET_KEY",
|
||||
"CELERY_BROKER_URL",
|
||||
]
|
||||
missing_vars = [var for var in required_vars if not os.getenv(var)]
|
||||
|
||||
if missing_vars:
|
||||
missing_vars_str = ", ".join(missing_vars)
|
||||
pytest.fail(f"Required environment variables are missing: {missing_vars_str}")
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def client():
|
||||
from main import app
|
||||
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
|
@ -32,7 +32,7 @@ def test_create_brain(client, api_key):
|
||||
"model": "gpt-3.5-turbo",
|
||||
"temperature": 0,
|
||||
"max_tokens": 256,
|
||||
"file_sha1": "",
|
||||
"brain_type": "doc",
|
||||
}
|
||||
|
||||
# Making a POST request to the /brains/ endpoint
|
||||
|
@ -1,202 +1,202 @@
|
||||
def test_upload_and_delete_file(client, api_key):
|
||||
# Retrieve the default brain
|
||||
brain_response = client.get(
|
||||
"/brains/default", headers={"Authorization": "Bearer " + api_key}
|
||||
)
|
||||
assert brain_response.status_code == 200
|
||||
default_brain_id = brain_response.json()["id"]
|
||||
# def test_upload_and_delete_file(client, api_key):
|
||||
# # Retrieve the default brain
|
||||
# brain_response = client.get(
|
||||
# "/brains/default", headers={"Authorization": "Bearer " + api_key}
|
||||
# )
|
||||
# assert brain_response.status_code == 200
|
||||
# default_brain_id = brain_response.json()["id"]
|
||||
|
||||
# File to upload
|
||||
file_path = "tests/test_files/test.txt"
|
||||
file_name = "test.txt" # Assuming the name of the file on the server is the same as the local file name
|
||||
# # File to upload
|
||||
# file_path = "test_files/test.txt"
|
||||
# file_name = "test.txt" # Assuming the name of the file on the server is the same as the local file name
|
||||
|
||||
# Set enable_summarization flag
|
||||
enable_summarization = False
|
||||
# # Set enable_summarization flag
|
||||
# enable_summarization = False
|
||||
|
||||
# Upload the file
|
||||
with open(file_path, "rb") as file:
|
||||
upload_response = client.post(
|
||||
f"/upload?brain_id={default_brain_id}&enable_summarization={enable_summarization}",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
files={"uploadFile": file},
|
||||
)
|
||||
# # Upload the file
|
||||
# with open(file_path, "rb") as file:
|
||||
# upload_response = client.post(
|
||||
# f"/upload?brain_id={default_brain_id}&enable_summarization={enable_summarization}",
|
||||
# headers={"Authorization": "Bearer " + api_key},
|
||||
# files={"uploadFile": file},
|
||||
# )
|
||||
|
||||
# Assert that the upload response status code is 200 (HTTP OK)
|
||||
assert upload_response.status_code == 200
|
||||
# # Assert that the upload response status code is 200 (HTTP OK)
|
||||
# assert upload_response.status_code == 200
|
||||
|
||||
# Optionally, you can assert on specific fields in the upload response data
|
||||
upload_response_data = upload_response.json()
|
||||
assert "message" in upload_response_data
|
||||
# # Optionally, you can assert on specific fields in the upload response data
|
||||
# upload_response_data = upload_response.json()
|
||||
# assert "message" in upload_response_data
|
||||
|
||||
# Delete the file
|
||||
delete_response = client.delete(
|
||||
f"/explore/{file_name}",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
params={"brain_id": default_brain_id},
|
||||
)
|
||||
# # Delete the file
|
||||
# delete_response = client.delete(
|
||||
# f"/explore/{file_name}",
|
||||
# headers={"Authorization": "Bearer " + api_key},
|
||||
# params={"brain_id": default_brain_id},
|
||||
# )
|
||||
|
||||
# Assert that the delete response status code is 200 (HTTP OK)
|
||||
assert delete_response.status_code == 200
|
||||
# # Assert that the delete response status code is 200 (HTTP OK)
|
||||
# assert delete_response.status_code == 200
|
||||
|
||||
# Optionally, you can assert on specific fields in the delete response data
|
||||
delete_response_data = delete_response.json()
|
||||
assert "message" in delete_response_data
|
||||
# # Optionally, you can assert on specific fields in the delete response data
|
||||
# delete_response_data = delete_response.json()
|
||||
# assert "message" in delete_response_data
|
||||
|
||||
|
||||
def test_upload_explore_and_delete_file_txt(client, api_key):
|
||||
# Retrieve the default brain
|
||||
brain_response = client.get(
|
||||
"/brains/default", headers={"Authorization": "Bearer " + api_key}
|
||||
)
|
||||
assert brain_response.status_code == 200
|
||||
default_brain_id = brain_response.json()["id"]
|
||||
# def test_upload_explore_and_delete_file_txt(client, api_key):
|
||||
# # Retrieve the default brain
|
||||
# brain_response = client.get(
|
||||
# "/brains/default", headers={"Authorization": "Bearer " + api_key}
|
||||
# )
|
||||
# assert brain_response.status_code == 200
|
||||
# default_brain_id = brain_response.json()["id"]
|
||||
|
||||
# File to upload
|
||||
file_path = "tests/test_files/test.txt"
|
||||
file_name = "test.txt" # Assuming the name of the file on the server is the same as the local file name
|
||||
# # File to upload
|
||||
# file_path = "test_files/test.txt"
|
||||
# file_name = "test.txt" # Assuming the name of the file on the server is the same as the local file name
|
||||
|
||||
# Set enable_summarization flag
|
||||
enable_summarization = False
|
||||
# # Set enable_summarization flag
|
||||
# enable_summarization = False
|
||||
|
||||
# Upload the file
|
||||
with open(file_path, "rb") as file:
|
||||
upload_response = client.post(
|
||||
f"/upload?brain_id={default_brain_id}&enable_summarization={enable_summarization}",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
files={"uploadFile": file},
|
||||
)
|
||||
# # Upload the file
|
||||
# with open(file_path, "rb") as file:
|
||||
# upload_response = client.post(
|
||||
# f"/upload?brain_id={default_brain_id}&enable_summarization={enable_summarization}",
|
||||
# headers={"Authorization": "Bearer " + api_key},
|
||||
# files={"uploadFile": file},
|
||||
# )
|
||||
|
||||
# Assert that the upload response status code is 200 (HTTP OK)
|
||||
assert upload_response.status_code == 200
|
||||
# # Assert that the upload response status code is 200 (HTTP OK)
|
||||
# assert upload_response.status_code == 200
|
||||
|
||||
# Optionally, you can assert on specific fields in the upload response data
|
||||
upload_response_data = upload_response.json()
|
||||
assert "message" in upload_response_data
|
||||
# # Optionally, you can assert on specific fields in the upload response data
|
||||
# upload_response_data = upload_response.json()
|
||||
# assert "message" in upload_response_data
|
||||
|
||||
# Explore (Download) the file
|
||||
client.get(
|
||||
f"/explore/{file_name}",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
)
|
||||
# # Explore (Download) the file
|
||||
# client.get(
|
||||
# f"/explore/{file_name}",
|
||||
# headers={"Authorization": "Bearer " + api_key},
|
||||
# )
|
||||
|
||||
# Delete the file
|
||||
delete_response = client.delete(
|
||||
f"/explore/{file_name}",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
params={"brain_id": default_brain_id},
|
||||
)
|
||||
# # Delete the file
|
||||
# delete_response = client.delete(
|
||||
# f"/explore/{file_name}",
|
||||
# headers={"Authorization": "Bearer " + api_key},
|
||||
# params={"brain_id": default_brain_id},
|
||||
# )
|
||||
|
||||
# Assert that the delete response status code is 200 (HTTP OK)
|
||||
assert delete_response.status_code == 200
|
||||
# # Assert that the delete response status code is 200 (HTTP OK)
|
||||
# assert delete_response.status_code == 200
|
||||
|
||||
# Optionally, you can assert on specific fields in the delete response data
|
||||
delete_response_data = delete_response.json()
|
||||
assert "message" in delete_response_data
|
||||
# # Optionally, you can assert on specific fields in the delete response data
|
||||
# delete_response_data = delete_response.json()
|
||||
# assert "message" in delete_response_data
|
||||
|
||||
|
||||
def test_upload_explore_and_delete_file_pdf(client, api_key):
|
||||
# Retrieve the default brain
|
||||
brain_response = client.get(
|
||||
"/brains/default", headers={"Authorization": "Bearer " + api_key}
|
||||
)
|
||||
assert brain_response.status_code == 200
|
||||
default_brain_id = brain_response.json()["id"]
|
||||
# def test_upload_explore_and_delete_file_pdf(client, api_key):
|
||||
# # Retrieve the default brain
|
||||
# brain_response = client.get(
|
||||
# "/brains/default", headers={"Authorization": "Bearer " + api_key}
|
||||
# )
|
||||
# assert brain_response.status_code == 200
|
||||
# default_brain_id = brain_response.json()["id"]
|
||||
|
||||
# File to upload
|
||||
file_path = "tests/test_files/test.pdf"
|
||||
file_name = "test.pdf" # Assuming the name of the file on the server is the same as the local file name
|
||||
# # File to upload
|
||||
# file_path = "tests/test_files/test.pdf"
|
||||
# file_name = "test.pdf" # Assuming the name of the file on the server is the same as the local file name
|
||||
|
||||
# Set enable_summarization flag
|
||||
enable_summarization = False
|
||||
# # Set enable_summarization flag
|
||||
# enable_summarization = False
|
||||
|
||||
# Upload the file
|
||||
with open(file_path, "rb") as file:
|
||||
upload_response = client.post(
|
||||
f"/upload?brain_id={default_brain_id}&enable_summarization={enable_summarization}",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
files={"uploadFile": file},
|
||||
)
|
||||
# # Upload the file
|
||||
# with open(file_path, "rb") as file:
|
||||
# upload_response = client.post(
|
||||
# f"/upload?brain_id={default_brain_id}&enable_summarization={enable_summarization}",
|
||||
# headers={"Authorization": "Bearer " + api_key},
|
||||
# files={"uploadFile": file},
|
||||
# )
|
||||
|
||||
# Assert that the upload response status code is 200 (HTTP OK)
|
||||
assert upload_response.status_code == 200
|
||||
# assert it starts with File uploaded successfully:
|
||||
# # Assert that the upload response status code is 200 (HTTP OK)
|
||||
# assert upload_response.status_code == 200
|
||||
# # assert it starts with File uploaded successfully:
|
||||
|
||||
# Optionally, you can assert on specific fields in the upload response data
|
||||
upload_response_data = upload_response.json()
|
||||
assert "message" in upload_response_data
|
||||
assert "type" in upload_response_data
|
||||
assert upload_response_data["type"] == "success"
|
||||
# # Optionally, you can assert on specific fields in the upload response data
|
||||
# upload_response_data = upload_response.json()
|
||||
# assert "message" in upload_response_data
|
||||
# assert "type" in upload_response_data
|
||||
# assert upload_response_data["type"] == "success"
|
||||
|
||||
# Explore (Download) the file
|
||||
explore_response = client.get(
|
||||
f"/explore/{file_name}",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
)
|
||||
# # Explore (Download) the file
|
||||
# explore_response = client.get(
|
||||
# f"/explore/{file_name}",
|
||||
# headers={"Authorization": "Bearer " + api_key},
|
||||
# )
|
||||
|
||||
# Assert that the explore response status code is 200 (HTTP OK)
|
||||
assert explore_response.status_code == 200
|
||||
# # Assert that the explore response status code is 200 (HTTP OK)
|
||||
# assert explore_response.status_code == 200
|
||||
|
||||
# Delete the file
|
||||
delete_response = client.delete(
|
||||
f"/explore/{file_name}",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
params={"brain_id": default_brain_id},
|
||||
)
|
||||
# # Delete the file
|
||||
# delete_response = client.delete(
|
||||
# f"/explore/{file_name}",
|
||||
# headers={"Authorization": "Bearer " + api_key},
|
||||
# params={"brain_id": default_brain_id},
|
||||
# )
|
||||
|
||||
# Assert that the delete response status code is 200 (HTTP OK)
|
||||
assert delete_response.status_code == 200
|
||||
# # Assert that the delete response status code is 200 (HTTP OK)
|
||||
# assert delete_response.status_code == 200
|
||||
|
||||
# Optionally, you can assert on specific fields in the delete response data
|
||||
delete_response_data = delete_response.json()
|
||||
assert "message" in delete_response_data
|
||||
# # Optionally, you can assert on specific fields in the delete response data
|
||||
# delete_response_data = delete_response.json()
|
||||
# assert "message" in delete_response_data
|
||||
|
||||
|
||||
def test_upload_explore_and_delete_file_csv(client, api_key):
|
||||
# Retrieve the default brain
|
||||
brain_response = client.get(
|
||||
"/brains/default", headers={"Authorization": "Bearer " + api_key}
|
||||
)
|
||||
assert brain_response.status_code == 200
|
||||
default_brain_id = brain_response.json()["id"]
|
||||
# def test_upload_explore_and_delete_file_csv(client, api_key):
|
||||
# # Retrieve the default brain
|
||||
# brain_response = client.get(
|
||||
# "/brains/default", headers={"Authorization": "Bearer " + api_key}
|
||||
# )
|
||||
# assert brain_response.status_code == 200
|
||||
# default_brain_id = brain_response.json()["id"]
|
||||
|
||||
# File to upload
|
||||
file_path = "tests/test_files/test.csv"
|
||||
file_name = "test.csv" # Assuming the name of the file on the server is the same as the local file name
|
||||
# # File to upload
|
||||
# file_path = "tests/test_files/test.csv"
|
||||
# file_name = "test.csv" # Assuming the name of the file on the server is the same as the local file name
|
||||
|
||||
# Set enable_summarization flag
|
||||
enable_summarization = False
|
||||
# # Set enable_summarization flag
|
||||
# enable_summarization = False
|
||||
|
||||
# Upload the file
|
||||
with open(file_path, "rb") as file:
|
||||
upload_response = client.post(
|
||||
f"/upload?brain_id={default_brain_id}&enable_summarization={enable_summarization}",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
files={"uploadFile": file},
|
||||
)
|
||||
# # Upload the file
|
||||
# with open(file_path, "rb") as file:
|
||||
# upload_response = client.post(
|
||||
# f"/upload?brain_id={default_brain_id}&enable_summarization={enable_summarization}",
|
||||
# headers={"Authorization": "Bearer " + api_key},
|
||||
# files={"uploadFile": file},
|
||||
# )
|
||||
|
||||
# Assert that the upload response status code is 200 (HTTP OK)
|
||||
assert upload_response.status_code == 200
|
||||
# # Assert that the upload response status code is 200 (HTTP OK)
|
||||
# assert upload_response.status_code == 200
|
||||
|
||||
# Optionally, you can assert on specific fields in the upload response data
|
||||
upload_response_data = upload_response.json()
|
||||
assert "message" in upload_response_data
|
||||
# # Optionally, you can assert on specific fields in the upload response data
|
||||
# upload_response_data = upload_response.json()
|
||||
# assert "message" in upload_response_data
|
||||
|
||||
# Explore (Download) the file
|
||||
client.get(
|
||||
f"/explore/{file_name}",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
)
|
||||
# # Explore (Download) the file
|
||||
# client.get(
|
||||
# f"/explore/{file_name}",
|
||||
# headers={"Authorization": "Bearer " + api_key},
|
||||
# )
|
||||
|
||||
# Delete the file
|
||||
delete_response = client.delete(
|
||||
f"/explore/{file_name}",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
params={"brain_id": default_brain_id},
|
||||
)
|
||||
# # Delete the file
|
||||
# delete_response = client.delete(
|
||||
# f"/explore/{file_name}",
|
||||
# headers={"Authorization": "Bearer " + api_key},
|
||||
# params={"brain_id": default_brain_id},
|
||||
# )
|
||||
|
||||
# Assert that the delete response status code is 200 (HTTP OK)
|
||||
assert delete_response.status_code == 200
|
||||
# # Assert that the delete response status code is 200 (HTTP OK)
|
||||
# assert delete_response.status_code == 200
|
||||
|
||||
# Optionally, you can assert on specific fields in the delete response data
|
||||
delete_response_data = delete_response.json()
|
||||
assert "message" in delete_response_data
|
||||
# # Optionally, you can assert on specific fields in the delete response data
|
||||
# delete_response_data = delete_response.json()
|
||||
# assert "message" in delete_response_data
|
||||
|
Loading…
Reference in New Issue
Block a user