c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
111 lines
3.5 KiB
Python
111 lines
3.5 KiB
Python
import os
|
|
import uuid
|
|
import pytest
|
|
from unittest.mock import patch
|
|
|
|
with patch("dotenv.load_dotenv"):
|
|
os.environ["REQUIRE_AUTHENTICATION"] = "true"
|
|
os.environ["ENABLE_BACKEND_ACCESS_CONTROL"] = "false"
|
|
os.environ["HASH_API_KEY"] = "false"
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
RUN_ID = uuid.uuid4().hex[:8]
|
|
OWNER_EMAIL = f"agent-owner-{RUN_ID}@example.com"
|
|
OWNER_PASSWORD = "ownerpass123!"
|
|
AGENT_NAME = f"test-agent-{RUN_ID}"
|
|
|
|
|
|
class TestAgentEndpoints:
|
|
@pytest.fixture(scope="class")
|
|
def client(self):
|
|
from cognee.api.client import app
|
|
|
|
with TestClient(app) as client:
|
|
yield client
|
|
|
|
@pytest.fixture(scope="class")
|
|
def owner(self, client):
|
|
reg = client.post(
|
|
"/api/v1/auth/register",
|
|
json={"email": OWNER_EMAIL, "password": OWNER_PASSWORD},
|
|
)
|
|
assert reg.status_code in (200, 201)
|
|
owner_id = reg.json()["id"]
|
|
|
|
login = client.post(
|
|
"/api/v1/auth/login",
|
|
data={"username": OWNER_EMAIL, "password": OWNER_PASSWORD},
|
|
)
|
|
assert login.status_code == 200
|
|
return {"id": owner_id, "token": login.json()["access_token"]}
|
|
|
|
@pytest.fixture(scope="class")
|
|
def owner_token(self, owner):
|
|
return owner["token"]
|
|
|
|
@pytest.fixture(scope="class")
|
|
def agent(self, client, owner_token):
|
|
resp = client.post(
|
|
f"/api/v1/agents/create?name={AGENT_NAME}",
|
|
headers={"Authorization": f"Bearer {owner_token}"},
|
|
)
|
|
assert resp.status_code == 200
|
|
return resp.json()
|
|
|
|
def test_owner_login(self, client, owner):
|
|
client.post("/api/v1/auth/logout")
|
|
|
|
resp = client.post(
|
|
"/api/v1/auth/login",
|
|
data={"username": OWNER_EMAIL, "password": OWNER_PASSWORD},
|
|
)
|
|
assert resp.status_code == 200
|
|
assert "access_token" in resp.json()
|
|
|
|
def test_agent_cannot_login(self, client, owner, agent):
|
|
internal_email = f"{AGENT_NAME}+{owner['id']}@cognee.agent"
|
|
|
|
resp = client.post(
|
|
"/api/v1/auth/login",
|
|
data={"username": internal_email, "password": "anyguess"},
|
|
)
|
|
assert resp.status_code == 400
|
|
assert "API key" in resp.json()["detail"]
|
|
|
|
def test_agent_cannot_login_empty_password(self, client, owner, agent):
|
|
internal_email = f"{AGENT_NAME}+{owner['id']}@cognee.agent"
|
|
|
|
resp = client.post(
|
|
"/api/v1/auth/login",
|
|
data={"username": internal_email, "password": ""},
|
|
)
|
|
assert resp.status_code == 400
|
|
|
|
def test_agent_api_key_works(self, client, agent):
|
|
client.post("/api/v1/auth/logout")
|
|
|
|
resp = client.get(
|
|
"/api/v1/auth/me",
|
|
headers={"X-Api-Key": agent["agentApiKey"]},
|
|
)
|
|
assert resp.status_code == 200
|
|
|
|
def test_list_agents_returns_agent(self, client, owner_token, agent):
|
|
resp = client.get(
|
|
"/api/v1/agents/list",
|
|
headers={"Authorization": f"Bearer {owner_token}"},
|
|
)
|
|
assert resp.status_code == 200
|
|
agents = resp.json()
|
|
assert isinstance(agents, list)
|
|
agent_ids = {a["agentId"] for a in agents}
|
|
assert agent["agentId"] in agent_ids
|
|
|
|
def test_duplicate_agent_returns_409(self, client, owner_token, agent):
|
|
resp = client.post(
|
|
f"/api/v1/agents/create?name={AGENT_NAME}",
|
|
headers={"Authorization": f"Bearer {owner_token}"},
|
|
)
|
|
assert resp.status_code == 409
|