refactor: Simplify repository classes by inheriting from BaseRepository and removing redundant methods

This commit is contained in:
JSC
2025-07-31 21:32:46 +02:00
parent c63997f591
commit 3405d817d5
8 changed files with 55 additions and 293 deletions

View File

@@ -39,24 +39,24 @@ class TestExtractionRepository:
}
# Mock the session operations
mock_extraction = Extraction(**extraction_data, id=1)
extraction_repo.session.add = Mock()
extraction_repo.session.commit = AsyncMock()
extraction_repo.session.refresh = AsyncMock()
# Mock the Extraction constructor to return our mock
with pytest.MonkeyPatch().context() as m:
m.setattr(
"app.repositories.extraction.Extraction",
lambda **kwargs: mock_extraction,
)
result = await extraction_repo.create(extraction_data)
result = await extraction_repo.create(extraction_data)
assert result == mock_extraction
extraction_repo.session.add.assert_called_once()
extraction_repo.session.commit.assert_called_once()
extraction_repo.session.refresh.assert_called_once_with(mock_extraction)
# Verify the result has the expected attributes
assert result.url == extraction_data["url"]
assert result.user_id == extraction_data["user_id"]
assert result.service == extraction_data["service"]
assert result.service_id == extraction_data["service_id"]
assert result.title == extraction_data["title"]
assert result.status == extraction_data["status"]
# Verify session methods were called
extraction_repo.session.add.assert_called_once()
extraction_repo.session.commit.assert_called_once()
extraction_repo.session.refresh.assert_called_once()
@pytest.mark.asyncio
async def test_get_by_service_and_id(self, extraction_repo):