Skip to content

Commit f2e3d59

Browse files
committed
📦 NEW: Test
1 parent 8af084f commit f2e3d59

16 files changed

+2006
-1486
lines changed

pyproject.toml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,4 @@ line_length = 88
5353
[tool.pytest.ini_options]
5454
testpaths = ["tests"]
5555
python_files = "test_*.py"
56-
addopts = "-v"
57-
58-
[tool.mypy]
59-
python_version = "3.7"
60-
disallow_untyped_defs = true
61-
disallow_incomplete_defs = true
62-
check_untyped_defs = true
63-
disallow_untyped_decorators = true
64-
no_implicit_optional = true
65-
strict_optional = true
66-
warn_redundant_casts = true
67-
warn_unused_ignores = true
68-
warn_return_any = true
69-
warn_unused_configs = true
56+
addopts = "-v"

requirements-dev.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
pytest>=7.0.0
33
pytest-asyncio>=0.21.0
44
pytest-cov>=3.0.0
5+
responses>=0.23.0
56
black>=22.1.0
67
isort>=5.10.1
7-
mypy>=0.950
88
build>=0.8.0
9-
twine>=4.0.1
109
python-dotenv>=0.19.0

setup.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/conftest.py

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
"""
2+
Shared test configuration and fixtures for Langbase SDK tests.
3+
"""
4+
5+
import json
6+
7+
import pytest
8+
import responses
9+
10+
11+
@pytest.fixture
12+
def base_url():
13+
"""Base URL for the Langbase API."""
14+
return "https://api.langbase.com"
15+
16+
17+
@pytest.fixture
18+
def api_key():
19+
"""Test API key."""
20+
return "test-api-key"
21+
22+
23+
@pytest.fixture
24+
def langbase_client(api_key, base_url):
25+
"""Langbase client instance for testing."""
26+
from langbase import Langbase
27+
28+
return Langbase(api_key=api_key, base_url=base_url)
29+
30+
31+
@pytest.fixture
32+
def mock_responses():
33+
"""Common mock response patterns."""
34+
return {
35+
# Pipes responses
36+
"pipe_list": [
37+
{"name": "test-pipe", "description": "Test pipe", "status": "deployed"},
38+
{"name": "another-pipe", "description": "Another pipe", "status": "draft"},
39+
],
40+
"pipe_create": {
41+
"name": "new-pipe",
42+
"api_key": "pipe-api-key",
43+
"description": "A test pipe",
44+
"status": "draft",
45+
},
46+
"pipe_run": {
47+
"completion": "Hello, world!",
48+
"usage": {"prompt_tokens": 5, "completion_tokens": 3, "total_tokens": 8},
49+
},
50+
"pipe_run_stream": {
51+
"completion": "Hello, world!",
52+
"usage": {"prompt_tokens": 5, "completion_tokens": 3, "total_tokens": 8},
53+
},
54+
# Memory responses
55+
"memory_list": [
56+
{"name": "test-memory", "description": "Test memory", "documents": 5},
57+
{"name": "another-memory", "description": "Another memory", "documents": 2},
58+
],
59+
"memory_create": {
60+
"name": "new-memory",
61+
"description": "A test memory",
62+
"embedding_model": "openai:text-embedding-ada-002",
63+
},
64+
"memory_delete": {"success": True},
65+
"memory_retrieve": [
66+
{"text": "Test content", "similarity": 0.95, "metadata": {}},
67+
{"text": "Another content", "similarity": 0.85, "metadata": {}},
68+
],
69+
# Memory documents responses
70+
"memory_docs_list": [
71+
{"name": "doc1.txt", "size": 1024, "status": "processed"},
72+
{"name": "doc2.pdf", "size": 2048, "status": "processing"},
73+
],
74+
"memory_docs_delete": {"success": True},
75+
"memory_docs_upload_signed_url": {"signedUrl": "https://upload-url.com"},
76+
"memory_docs_embeddings_retry": {"success": True},
77+
# Tools responses
78+
"tools_web_search": [
79+
{
80+
"url": "https://example.com",
81+
"title": "Example",
82+
"content": "Example content",
83+
},
84+
{"url": "https://test.com", "title": "Test", "content": "Test content"},
85+
],
86+
"tools_crawl": [
87+
{"url": "https://example.com", "content": "Page content", "metadata": {}}
88+
],
89+
# Threads responses
90+
"threads_create": {"id": "thread_123", "object": "thread", "metadata": {}},
91+
"threads_update": {
92+
"id": "thread_123",
93+
"object": "thread",
94+
"metadata": {"updated": True},
95+
},
96+
"threads_get": {"id": "thread_123", "object": "thread", "metadata": {}},
97+
"threads_delete": {"deleted": True, "id": "thread_123"},
98+
"threads_append": [
99+
{"id": "msg_1", "role": "user", "content": "Hello"},
100+
{"id": "msg_2", "role": "assistant", "content": "Hi there!"},
101+
],
102+
"threads_messages_list": [
103+
{
104+
"id": "msg_1",
105+
"role": "user",
106+
"content": "Hello",
107+
"created_at": 1234567890,
108+
}
109+
],
110+
# Utilities responses
111+
"embed": [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]],
112+
"chunker": ["First chunk", "Second chunk", "Third chunk"],
113+
"parser": {"content": "Parsed document content", "metadata": {}},
114+
"agent_run": {
115+
"choices": [{"message": {"content": "Agent response"}}],
116+
"usage": {"total_tokens": 100},
117+
},
118+
# Error responses
119+
"error_400": {"error": "Bad request", "message": "Invalid parameters"},
120+
"error_401": {"error": "Unauthorized", "message": "Invalid API key"},
121+
"error_404": {"error": "Not found", "message": "Resource not found"},
122+
"error_500": {
123+
"error": "Internal server error",
124+
"message": "Something went wrong",
125+
},
126+
}
127+
128+
129+
@pytest.fixture
130+
def stream_chunks():
131+
"""Sample streaming response chunks."""
132+
return [
133+
b'data: {"chunk": "Hello"}\n\n',
134+
b'data: {"chunk": " world"}\n\n',
135+
b'data: {"chunk": "!"}\n\n',
136+
b"data: [DONE]\n\n",
137+
]
138+
139+
140+
@pytest.fixture
141+
def upload_file_content():
142+
"""Sample file content for upload tests."""
143+
return b"This is test document content for upload testing."
144+
145+
146+
def create_stream_response(chunks):
147+
"""Helper function to create streaming response."""
148+
149+
def stream_generator():
150+
for chunk in chunks:
151+
yield chunk
152+
153+
return stream_generator()

0 commit comments

Comments
 (0)