mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 01:06:23 +02:00
refactor: remove redundant and low-value tests, enforce connector_id and created_by_id constraints
This commit is contained in:
parent
5b616eac5a
commit
af22fa7c88
6 changed files with 110 additions and 49 deletions
|
|
@ -5,19 +5,45 @@ from app.db import DocumentType
|
|||
from app.indexing_pipeline.connector_document import ConnectorDocument
|
||||
|
||||
|
||||
def test_valid_document_created_with_defaults():
|
||||
def test_valid_document_created_with_required_fields():
|
||||
doc = ConnectorDocument(
|
||||
title="Task",
|
||||
source_markdown="## Task\n\nSome content.",
|
||||
unique_id="task-1",
|
||||
document_type=DocumentType.CLICKUP_CONNECTOR,
|
||||
search_space_id=1,
|
||||
connector_id=42,
|
||||
created_by_id="00000000-0000-0000-0000-000000000001",
|
||||
)
|
||||
assert doc.should_summarize is True
|
||||
assert doc.should_use_code_chunker is False
|
||||
assert doc.metadata == {}
|
||||
assert doc.connector_id is None
|
||||
assert doc.created_by_id is None
|
||||
assert doc.connector_id == 42
|
||||
assert doc.created_by_id == "00000000-0000-0000-0000-000000000001"
|
||||
|
||||
|
||||
def test_omitting_connector_id_raises():
|
||||
with pytest.raises(ValidationError):
|
||||
ConnectorDocument(
|
||||
title="Task",
|
||||
source_markdown="## Content",
|
||||
unique_id="task-1",
|
||||
document_type=DocumentType.CLICKUP_CONNECTOR,
|
||||
search_space_id=1,
|
||||
created_by_id="00000000-0000-0000-0000-000000000001",
|
||||
)
|
||||
|
||||
|
||||
def test_omitting_created_by_id_raises():
|
||||
with pytest.raises(ValidationError):
|
||||
ConnectorDocument(
|
||||
title="Task",
|
||||
source_markdown="## Content",
|
||||
unique_id="task-1",
|
||||
document_type=DocumentType.CLICKUP_CONNECTOR,
|
||||
search_space_id=1,
|
||||
connector_id=42,
|
||||
)
|
||||
|
||||
|
||||
def test_empty_source_markdown_raises():
|
||||
|
|
@ -42,30 +68,6 @@ def test_whitespace_only_source_markdown_raises():
|
|||
)
|
||||
|
||||
|
||||
def test_should_summarize_false_accepted():
|
||||
doc = ConnectorDocument(
|
||||
title="Message",
|
||||
source_markdown="Hello world.",
|
||||
unique_id="msg-1",
|
||||
document_type=DocumentType.SLACK_CONNECTOR,
|
||||
search_space_id=1,
|
||||
should_summarize=False,
|
||||
)
|
||||
assert doc.should_summarize is False
|
||||
|
||||
|
||||
def test_should_use_code_chunker_accepted():
|
||||
doc = ConnectorDocument(
|
||||
title="Repository",
|
||||
source_markdown="def hello():\n pass",
|
||||
unique_id="repo-1",
|
||||
document_type=DocumentType.GITHUB_CONNECTOR,
|
||||
search_space_id=1,
|
||||
should_use_code_chunker=True,
|
||||
)
|
||||
assert doc.should_use_code_chunker is True
|
||||
|
||||
|
||||
def test_empty_title_raises():
|
||||
with pytest.raises(ValidationError):
|
||||
ConnectorDocument(
|
||||
|
|
@ -77,6 +79,45 @@ def test_empty_title_raises():
|
|||
)
|
||||
|
||||
|
||||
def test_empty_created_by_id_raises():
|
||||
with pytest.raises(ValidationError):
|
||||
ConnectorDocument(
|
||||
title="Task",
|
||||
source_markdown="## Content",
|
||||
unique_id="task-1",
|
||||
document_type=DocumentType.CLICKUP_CONNECTOR,
|
||||
search_space_id=1,
|
||||
connector_id=42,
|
||||
created_by_id="",
|
||||
)
|
||||
|
||||
|
||||
def test_zero_connector_id_raises():
|
||||
with pytest.raises(ValidationError):
|
||||
ConnectorDocument(
|
||||
title="Task",
|
||||
source_markdown="## Content",
|
||||
unique_id="task-1",
|
||||
document_type=DocumentType.CLICKUP_CONNECTOR,
|
||||
search_space_id=1,
|
||||
connector_id=0,
|
||||
created_by_id="00000000-0000-0000-0000-000000000001",
|
||||
)
|
||||
|
||||
|
||||
def test_zero_search_space_id_raises():
|
||||
with pytest.raises(ValidationError):
|
||||
ConnectorDocument(
|
||||
title="Task",
|
||||
source_markdown="## Content",
|
||||
unique_id="task-1",
|
||||
document_type=DocumentType.CLICKUP_CONNECTOR,
|
||||
search_space_id=0,
|
||||
connector_id=42,
|
||||
created_by_id="00000000-0000-0000-0000-000000000001",
|
||||
)
|
||||
|
||||
|
||||
def test_empty_unique_id_raises():
|
||||
with pytest.raises(ValidationError):
|
||||
ConnectorDocument(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue