refactor: Simplify repository classes by inheriting from BaseRepository and removing redundant methods
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user