Skip to content

Commit a64496c

Browse files
add extractors test
1 parent c6be71f commit a64496c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from unittest.mock import MagicMock, patch
2+
3+
from app.core.extractors import extract_text_and_save_to_db, perform_fixed_size_chunking
4+
5+
6+
def test_extract_text_and_save_chunks_to_db() -> None:
7+
fake_text = "abcdefghij"
8+
fake_s3_key = "some-s3-key"
9+
fake_doc_id = "123e4567-e89b-12d3-a456-426614174000"
10+
11+
mock_document = MagicMock()
12+
mock_document.id = fake_doc_id
13+
14+
with patch(
15+
"app.core.extractors.extract_text_from_s3_file", return_value=fake_text
16+
) as _, patch("app.core.extractors.Session") as session_class_mock, patch(
17+
"app.core.extractors.save_chunks_to_db"
18+
) as save_chunks_mock:
19+
session_instance = MagicMock()
20+
session_class_mock.return_value.__enter__.return_value = session_instance
21+
session_instance.exec.return_value.first.return_value = mock_document
22+
23+
# Run function
24+
extract_text_and_save_to_db(fake_s3_key, fake_doc_id)
25+
26+
# Check chunking worked
27+
expected_chunks = perform_fixed_size_chunking(fake_text)
28+
save_chunks_mock.assert_called_once_with(
29+
session_instance, fake_doc_id, expected_chunks
30+
)

0 commit comments

Comments
 (0)