Format
This commit is contained in:
parent
29908957e9
commit
522bd304e8
22 changed files with 151 additions and 485 deletions
|
|
@ -28,35 +28,19 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
def pytest_configure():
|
||||
pytest.BASIC_EXAMPLE_PATH = (
|
||||
Path(__file__).parent.absolute() / "data" / "basic_example.json"
|
||||
)
|
||||
pytest.COMPLEX_EXAMPLE_PATH = (
|
||||
Path(__file__).parent.absolute() / "data" / "complex_example.json"
|
||||
)
|
||||
pytest.OPENAPI_EXAMPLE_PATH = (
|
||||
Path(__file__).parent.absolute() / "data" / "Openapi.json"
|
||||
)
|
||||
pytest.GROUPED_CHAT_EXAMPLE_PATH = (
|
||||
Path(__file__).parent.absolute() / "data" / "grouped_chat.json"
|
||||
)
|
||||
pytest.ONE_GROUPED_CHAT_EXAMPLE_PATH = (
|
||||
Path(__file__).parent.absolute() / "data" / "one_group_chat.json"
|
||||
)
|
||||
pytest.VECTOR_STORE_GROUPED_EXAMPLE_PATH = (
|
||||
Path(__file__).parent.absolute() / "data" / "vector_store_grouped.json"
|
||||
)
|
||||
pytest.BASIC_EXAMPLE_PATH = Path(__file__).parent.absolute() / "data" / "basic_example.json"
|
||||
pytest.COMPLEX_EXAMPLE_PATH = Path(__file__).parent.absolute() / "data" / "complex_example.json"
|
||||
pytest.OPENAPI_EXAMPLE_PATH = Path(__file__).parent.absolute() / "data" / "Openapi.json"
|
||||
pytest.GROUPED_CHAT_EXAMPLE_PATH = Path(__file__).parent.absolute() / "data" / "grouped_chat.json"
|
||||
pytest.ONE_GROUPED_CHAT_EXAMPLE_PATH = Path(__file__).parent.absolute() / "data" / "one_group_chat.json"
|
||||
pytest.VECTOR_STORE_GROUPED_EXAMPLE_PATH = Path(__file__).parent.absolute() / "data" / "vector_store_grouped.json"
|
||||
|
||||
pytest.BASIC_CHAT_WITH_PROMPT_AND_HISTORY = (
|
||||
Path(__file__).parent.absolute() / "data" / "BasicChatWithPromptAndHistory.json"
|
||||
)
|
||||
pytest.CHAT_INPUT = Path(__file__).parent.absolute() / "data" / "ChatInputTest.json"
|
||||
pytest.TWO_OUTPUTS = (
|
||||
Path(__file__).parent.absolute() / "data" / "TwoOutputsTest.json"
|
||||
)
|
||||
pytest.VECTOR_STORE_PATH = (
|
||||
Path(__file__).parent.absolute() / "data" / "Vector_store.json"
|
||||
)
|
||||
pytest.TWO_OUTPUTS = Path(__file__).parent.absolute() / "data" / "TwoOutputsTest.json"
|
||||
pytest.VECTOR_STORE_PATH = Path(__file__).parent.absolute() / "data" / "Vector_store.json"
|
||||
pytest.CODE_WITH_SYNTAX_ERROR = """
|
||||
def get_text():
|
||||
retun "Hello World"
|
||||
|
|
@ -67,9 +51,7 @@ def get_text():
|
|||
def check_openai_api_key_in_environment_variables():
|
||||
import os
|
||||
|
||||
assert (
|
||||
os.environ.get("OPENAI_API_KEY") is not None
|
||||
), "OPENAI_API_KEY is not set in environment variables"
|
||||
assert os.environ.get("OPENAI_API_KEY") is not None, "OPENAI_API_KEY is not set in environment variables"
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
|
@ -83,9 +65,7 @@ async def async_client() -> AsyncGenerator:
|
|||
|
||||
@pytest.fixture(name="session")
|
||||
def session_fixture():
|
||||
engine = create_engine(
|
||||
"sqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool
|
||||
)
|
||||
engine = create_engine("sqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool)
|
||||
SQLModel.metadata.create_all(engine)
|
||||
with Session(engine) as session:
|
||||
yield session
|
||||
|
|
@ -121,9 +101,7 @@ def distributed_client_fixture(session: Session, monkeypatch, distributed_env):
|
|||
monkeypatch.setenv("LANGFLOW_AUTO_LOGIN", "false")
|
||||
# monkeypatch langflow.services.task.manager.USE_CELERY to True
|
||||
# monkeypatch.setattr(manager, "USE_CELERY", True)
|
||||
monkeypatch.setattr(
|
||||
celery_app, "celery_app", celery_app.make_celery("langflow", Config)
|
||||
)
|
||||
monkeypatch.setattr(celery_app, "celery_app", celery_app.make_celery("langflow", Config))
|
||||
|
||||
# def get_session_override():
|
||||
# return session
|
||||
|
|
@ -274,11 +252,7 @@ def active_user(client):
|
|||
is_superuser=False,
|
||||
)
|
||||
# check if user exists
|
||||
if (
|
||||
active_user := session.query(User)
|
||||
.filter(User.username == user.username)
|
||||
.first()
|
||||
):
|
||||
if active_user := session.query(User).filter(User.username == user.username).first():
|
||||
return active_user
|
||||
session.add(user)
|
||||
session.commit()
|
||||
|
|
@ -301,9 +275,7 @@ def flow(client, json_flow: str, active_user):
|
|||
from langflow.services.database.models.flow.model import FlowCreate
|
||||
|
||||
loaded_json = json.loads(json_flow)
|
||||
flow_data = FlowCreate(
|
||||
name="test_flow", data=loaded_json.get("data"), user_id=active_user.id
|
||||
)
|
||||
flow_data = FlowCreate(name="test_flow", data=loaded_json.get("data"), user_id=active_user.id)
|
||||
|
||||
flow = Flow.model_validate(flow_data)
|
||||
with session_getter(get_db_service()) as session:
|
||||
|
|
@ -327,9 +299,7 @@ def json_two_outputs():
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def added_flow_with_prompt_and_history(
|
||||
client, json_flow_with_prompt_and_history, logged_in_headers
|
||||
):
|
||||
def added_flow_with_prompt_and_history(client, json_flow_with_prompt_and_history, logged_in_headers):
|
||||
flow = orjson.loads(json_flow_with_prompt_and_history)
|
||||
data = flow["data"]
|
||||
flow = FlowCreate(name="Basic Chat", description="description", data=data)
|
||||
|
|
@ -369,9 +339,7 @@ def added_vector_store(client, json_vector_store, logged_in_headers):
|
|||
vector_store = orjson.loads(json_vector_store)
|
||||
data = vector_store["data"]
|
||||
vector_store = FlowCreate(name="Vector Store", description="description", data=data)
|
||||
response = client.post(
|
||||
"api/v1/flows/", json=vector_store.dict(), headers=logged_in_headers
|
||||
)
|
||||
response = client.post("api/v1/flows/", json=vector_store.dict(), headers=logged_in_headers)
|
||||
assert response.status_code == 201
|
||||
assert response.json()["name"] == vector_store.name
|
||||
assert response.json()["data"] == vector_store.data
|
||||
|
|
@ -389,11 +357,7 @@ def created_api_key(active_user):
|
|||
)
|
||||
db_manager = get_db_service()
|
||||
with session_getter(db_manager) as session:
|
||||
if (
|
||||
existing_api_key := session.query(ApiKey)
|
||||
.filter(ApiKey.api_key == api_key.api_key)
|
||||
.first()
|
||||
):
|
||||
if existing_api_key := session.query(ApiKey).filter(ApiKey.api_key == api_key.api_key).first():
|
||||
return existing_api_key
|
||||
session.add(api_key)
|
||||
session.commit()
|
||||
|
|
@ -405,9 +369,7 @@ def created_api_key(active_user):
|
|||
def get_starter_project(active_user):
|
||||
# once the client is created, we can get the starter project
|
||||
with session_getter(get_db_service()) as session:
|
||||
flow = session.exec(
|
||||
select(Flow).where(Flow.folder == STARTER_FOLDER_NAME)
|
||||
).first()
|
||||
flow = session.exec(select(Flow).where(Flow.folder == STARTER_FOLDER_NAME)).first()
|
||||
if not flow:
|
||||
raise ValueError("No starter project found")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue