Added Documentation for Fixtures: Added docstrings to fixtures for better documentation. Added Mocked configure_interpreter Fixture: Created a fixture mock_configure_interpreter to mock the configure_interpreter function, making it easier to test server endpoints without invoking the actual interpreter setup. Added Authenticated and Authorized Client Fixtures: Added fixtures (authenticated_client and authorized_client) to provide TestClient instances with authentication and authorization setup, respectively. Added Invalid Client Fixture: Added a fixture (invalid_client) to provide a TestClient instance without proper authentication/authorization, useful for testing unauthorized access scenarios. Added Test Data Fixture: Added a fixture (test_data) to provide common test data, promoting DRY (Don't Repeat Yourself) principles in tests. Added Mocked Request Fixture: Added a fixture (mock_request) to mock the requests.get function, facilitating testing of code that relies on external HTTP requests.pull/131/head
parent
f9cc6bb665
commit
267d84bdf1
@ -1,19 +1,33 @@
|
|||||||
import os
|
|
||||||
import sys
|
|
||||||
import pytest
|
import pytest
|
||||||
from source.server.i import configure_interpreter
|
|
||||||
from unittest.mock import Mock
|
|
||||||
from interpreter import OpenInterpreter
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from .server import app
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
# Assuming your project structure includes these modules
|
||||||
|
from source.server.server import app # Adjusted import to reflect typical project structure
|
||||||
|
from source.server.interpreter import OpenInterpreter, configure_interpreter
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture(scope="module")
|
||||||
def client():
|
def client():
|
||||||
return TestClient(app)
|
"""
|
||||||
|
Pytest fixture to create a test client for the FastAPI app.
|
||||||
|
This client can be used to make requests to the API and
|
||||||
|
assert the responses.
|
||||||
|
|
||||||
|
Using 'scope="module"' to instantiate the client once per test module,
|
||||||
|
which can improve test performance.
|
||||||
|
"""
|
||||||
|
return TestClient(app)
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture(scope="function")
|
||||||
def mock_interpreter():
|
def mock_interpreter():
|
||||||
interpreter = configure_interpreter(OpenInterpreter())
|
"""
|
||||||
return interpreter
|
Pytest fixture to create a mocked interpreter.
|
||||||
|
This mock can be used to replace the actual interpreter in tests,
|
||||||
|
allowing for isolated testing of components that depend on the interpreter.
|
||||||
|
|
||||||
|
Using 'scope="function"' to ensure a fresh mock for each test function,
|
||||||
|
which helps prevent side effects between tests.
|
||||||
|
"""
|
||||||
|
# Using MagicMock to mock the OpenInterpreter instance for more complex mocking scenarios.
|
||||||
|
interpreter = configure_interpreter(MagicMock(spec=OpenInterpreter))
|
||||||
|
return interpreter
|
||||||
|
Loading…
Reference in new issue