Skip to content
Open
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
22 changes: 22 additions & 0 deletions server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ dependencies = [
"exa-py>=1.14.16",
]

[project.optional-dependencies]
dev = [
"pytest>=8.3.0",
"pytest-cov>=5.0.0",
"pytest-asyncio>=0.24.0",
]

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = [
"-v",
"--strict-markers",
"--tb=short",
]
filterwarnings = [
"ignore::DeprecationWarning",
"ignore::PendingDeprecationWarning",
]

[tool.ruff]
line-length = 120
target-version = "py312"
Expand Down
92 changes: 92 additions & 0 deletions server/tests/app/component/test_encrypt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========

import pytest

from app.component.encrypt import password_hash, password_verify


def test_hash_returns_string():
result = password_hash("test_password")
assert isinstance(result, str)
assert len(result) > 0


def test_hash_differs_from_plaintext():
plaintext = "my_secret_password"
hashed = password_hash(plaintext)
assert hashed != plaintext


def test_hash_produces_unique_results():
password = "same_password"
hash1 = password_hash(password)
hash2 = password_hash(password)
assert hash1 != hash2


def test_hash_bcrypt_format():
hashed = password_hash("test")
assert hashed.startswith("$2b$")


def test_hash_empty_password():
hashed = password_hash("")
assert isinstance(hashed, str)
assert len(hashed) > 0


def test_verify_correct_password():
password = "correct_password"
hashed = password_hash(password)
assert password_verify(password, hashed) is True


def test_verify_wrong_password():
hashed = password_hash("original_password")
assert password_verify("wrong_password", hashed) is False


def test_verify_none_hash():
assert password_verify("any_password", None) is False


def test_verify_empty_hash_raises():
with pytest.raises(Exception):
password_verify("password", "")


def test_verify_case_sensitive():
hashed = password_hash("Password123")
assert password_verify("Password123", hashed) is True
assert password_verify("password123", hashed) is False
assert password_verify("PASSWORD123", hashed) is False


def test_verify_special_chars():
special_password = "p@$$w0rd!#%^&*()"
hashed = password_hash(special_password)
assert password_verify(special_password, hashed) is True


def test_verify_unicode():
unicode_password = "密码🔐パスワード"
hashed = password_hash(unicode_password)
assert password_verify(unicode_password, hashed) is True


def test_verify_long_password():
long_password = "a" * 100
hashed = password_hash(long_password)
assert password_verify(long_password, hashed) is True
87 changes: 87 additions & 0 deletions server/tests/app/component/test_time_friendly.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========

from datetime import date, datetime

from app.component.time_friendly import monday_start_time, to_date


def test_to_date_iso():
result = to_date("2026-01-15")
assert result == date(2026, 1, 15)


def test_to_date_iso_datetime():
result = to_date("2026-03-20T14:30:00")
assert result == date(2026, 3, 20)


def test_to_date_custom_format():
result = to_date("15/01/2026", "DD/MM/YYYY")
assert result == date(2026, 1, 15)


def test_to_date_us_format():
result = to_date("01-15-2026", "MM-DD-YYYY")
assert result == date(2026, 1, 15)


def test_to_date_invalid():
result = to_date("not-a-date")
assert result is None


def test_to_date_empty():
result = to_date("")
assert result is None


def test_to_date_wrong_format():
result = to_date("2026-01-15", "DD/MM/YYYY")
assert result is None


def test_to_date_partial():
result = to_date("2026-01")
assert result is None or isinstance(result, date)


def test_monday_returns_datetime():
result = monday_start_time()
assert isinstance(result, datetime)


def test_monday_is_midnight():
result = monday_start_time()
assert result.hour == 0
assert result.minute == 0
assert result.second == 0
assert result.microsecond == 0


def test_monday_weekday():
result = monday_start_time()
assert result.weekday() == 0


def test_monday_not_future():
result = monday_start_time()
assert result <= datetime.now()


def test_monday_within_week():
result = monday_start_time()
now = datetime.now()
days_diff = (now - result).days
assert 0 <= days_diff <= 6
29 changes: 29 additions & 0 deletions server/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
"""Pytest configuration and shared fixtures for Eigent backend tests."""

import sys
from pathlib import Path

import pytest

# Add server directory to Python path so imports work correctly
server_dir = Path(__file__).parent.parent
sys.path.insert(0, str(server_dir))


@pytest.fixture(scope="session")
def server_root() -> Path:
"""Return the path to the server root directory."""
return server_dir