Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 tests #2095

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ volumes/storage/stub/stub/quivr/*
supabase/migrations/20240103191539_private.sql
supabase/20240103191539_private.sql
paulgraham.py
.env_test
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
Expand Down Expand Up @@ -54,4 +54,5 @@
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.envFile": "${workspaceFolder}/.env_test",
}
50 changes: 50 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
langchain = "==0.0.341"
litellm = "==1.7.7"
openai = "==1.1.1"
gitpython = "==3.1.36"
pdf2image = "==1.16.3"
nest-asyncio = "==1.5.6"
pypdf = "==3.9.0"
supabase = "==1.1.0"
tiktoken = "==0.4.0"
unstructured = "==0.6.7"
fastapi = "==0.95.2"
python-multipart = "==0.0.6"
uvicorn = "==0.22.0"
pypandoc = "==1.11"
docx2txt = "==0.8"
python-jose = "==3.3.0"
asyncpg = "==0.27.0"
flake8 = "==6.0.0"
flake8-black = "==0.3.6"
sentry-sdk = {extras = ["fastapi"], version = "==1.37.1"}
pyright = "==1.1.316"
resend = "==0.5.1"
html5lib = "==1.1"
beautifulsoup4 = "*"
newspaper3k = "*"
xlrd = "==1.0.0"
redis = "==4.5.4"
flower = "*"
boto3 = "==1.33.7"
botocore = "==1.33.7"
celery = {extras = ["sqs"], version = "*"}
python-dotenv = "*"
pytest-mock = "*"
pytest-celery = "*"
pytesseract = "==0.3.10"
async-generator = "*"
posthog = "==3.1.0"
jq = "==1.6.0"
pytest = "*"

[dev-packages]

[requires]
python_version = "3.11"
2,713 changes: 2,713 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

21 changes: 17 additions & 4 deletions backend/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import socket

import pytest
from dotenv import load_dotenv
Expand All @@ -7,8 +8,18 @@

@pytest.fixture(scope="session", autouse=True)
def load_env():
load_dotenv()
print("SUPABASE_URL:", os.getenv("SUPABASE_URL")) # For debugging
load_dotenv(".env_test", verbose=True, override=True)

# Testing socket connection
host, port = "localhost", 54321
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
try:
s.connect((host, port))
print(f"Connection to {host} on port {port} succeeded.")
except socket.error as e:
print(f"Connection to {host} on port {port} failed: {e}")

print("Loaded SUPABASE_URL:", os.getenv("SUPABASE_URL"))


@pytest.fixture(scope="session", autouse=True)
Expand All @@ -27,14 +38,16 @@ def verify_env_variables():
pytest.fail(f"Required environment variables are missing: {missing_vars_str}")


@pytest.fixture(scope="module")
@pytest.fixture(scope="session")
def client():
from main import app

print("CLIENT_SUPABASE_URL:", os.getenv("SUPABASE_URL")) # For debugging

return TestClient(app)


@pytest.fixture(scope="module")
@pytest.fixture(scope="session")
def api_key():
API_KEY = os.getenv("CI_TEST_API_KEY")
if not API_KEY:
Expand Down
4 changes: 2 additions & 2 deletions backend/modules/api_key/tests/test_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def test_api_key_model():
assert api_key.api_key == "1234567890"
assert api_key.key_id == "abcd1234"
assert api_key.days == 7
assert api_key.only_chat == False
assert api_key.only_chat is False
assert api_key.name == "Test API Key"
assert api_key.creation_time == "2022-01-01T00:00:00Z"
assert api_key.is_active == True
assert api_key.is_active is True


def test_get_user_from_api_key(client, api_key):
Expand Down
2 changes: 1 addition & 1 deletion backend/modules/brain/tests/test_brains.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_create_brain(client, api_key):
"status": "public",
"model": "gpt-3.5-turbo-1106",
"temperature": 0,
"max_tokens": 256,
"max_tokens": 2000,
"brain_type": "doc",
}

Expand Down
37 changes: 0 additions & 37 deletions backend/modules/chat/tests/test_chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,43 +79,6 @@ def test_create_chat_and_talk(client, api_key):
assert delete_response.status_code == 200


def test_create_chat_and_talk_with_no_brain(client, api_key):
# Make a POST request to chat with no brain id and a random chat name
random_chat_name = "".join(
random.choices(string.ascii_letters + string.digits, k=10)
)

# Create a chat
response = client.post(
"/chat",
json={"name": random_chat_name},
headers={"Authorization": "Bearer " + api_key},
)
assert response.status_code == 200

# now talk to the chat with a question
response_data = response.json()
print(response_data)
chat_id = response_data["chat_id"]
response = client.post(
f"/chat/{chat_id}/question?brain_id=",
json={
"model": "gpt-3.5-turbo-1106",
"question": "Hello, how are you?",
"temperature": "0",
"max_tokens": "256",
},
headers={"Authorization": "Bearer " + api_key},
)
assert response.status_code == 200

# Now, let's delete the chat
delete_response = client.delete(
"/chat/" + chat_id, headers={"Authorization": "Bearer " + api_key}
)
assert delete_response.status_code == 200


# Test delete all chats for a user
def test_delete_all_chats(client, api_key):
chats = client.get("/chat", headers={"Authorization": "Bearer " + api_key})
Expand Down
5 changes: 0 additions & 5 deletions connectors/telegram_bot/.env.example

This file was deleted.

73 changes: 0 additions & 73 deletions connectors/telegram_bot/main.py

This file was deleted.

Loading