ref: up
This commit is contained in:
40
fission-python/template/test/test_example.py
Normal file
40
fission-python/template/test/test_example.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""
|
||||
Example test file for Fission Python functions.
|
||||
|
||||
This demonstrates basic testing patterns.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
|
||||
def test_placeholder():
|
||||
"""Placeholder test - replace with your actual tests."""
|
||||
assert True
|
||||
|
||||
|
||||
# Example: Testing a function with mocked dependencies
|
||||
@patch("helpers.init_db_connection")
|
||||
def test_example_with_mock(mock_db):
|
||||
"""Example test showing how to mock database."""
|
||||
from examples.example_crud import create_item
|
||||
|
||||
# Setup mock
|
||||
mock_conn = MagicMock()
|
||||
mock_cursor = MagicMock()
|
||||
mock_db.return_value = mock_conn
|
||||
mock_conn.cursor.return_value = mock_cursor
|
||||
mock_cursor.fetchone.return_value = ("id-123", "Test Item", "active")
|
||||
|
||||
# Mock Flask request
|
||||
with patch("examples.example_crud.request") as mock_request:
|
||||
mock_request.get_json.return_value = {"name": "Test Item", "status": "active"}
|
||||
mock_request.view_args = {}
|
||||
|
||||
# Call function
|
||||
result = create_item({}, {})
|
||||
|
||||
# Assert
|
||||
assert result["name"] == "Test Item"
|
||||
mock_cursor.execute.assert_called_once()
|
||||
mock_conn.commit.assert_called_once()
|
||||
Reference in New Issue
Block a user