41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
|
|
"""
|
||
|
|
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()
|