This document describes the comprehensive testing framework for the Apstra MCP Server blueprint creation functionality, including automatic cleanup mechanisms to prevent test blueprint accumulation.
tests/
├── __init__.py # Test package initialization
├── test_config.py # Test configuration and constants
├── test_unit.py # Unit tests with mocked dependencies
├── test_functional.py # Functional tests against real server
├── test_cleanup.py # Standalone cleanup utility
└── run_tests.py # Test runner with auto-cleanup
- Mock-based testing - No real server calls
- Tests all blueprint creation functions with mocked responses
- Fast execution, no cleanup required
- Coverage:
- Authentication success/failure
- Template retrieval
- Datacenter blueprint creation
- Freeform blueprint creation
- Blueprint deletion
- Blueprint listing
- Real server integration - Tests against 10.87.2.74
- End-to-end blueprint lifecycle testing
- Automatic cleanup at multiple levels
- Coverage:
- Real authentication
- Real blueprint creation
- Real blueprint deletion
- End-to-end lifecycle
def tearDown(self):
"""Clean up after each test"""
if hasattr(self, 'test_blueprints_created') and self.test_blueprints_created:
for bp_id in self.test_blueprints_created:
delete_blueprint(bp_id, self.test_server)@classmethod
def tearDownClass(cls):
"""Clean up created blueprints after all tests"""
# Clean up tracked blueprints + scan for additional test blueprintsAutomatically removes blueprints containing:
test-*demo-*e2e-test*unittest-*functional-*
The test runner performs cleanup before and after test execution.
# Run all tests with cleanup
python test.py run
# Run specific test types
python test.py unit
python test.py functional
# Manual cleanup
python test.py clean
# Run demo
python test.py demo# All tests with automatic cleanup
python tests/run_tests.py
# Unit tests only
python -m unittest tests.test_unit -v
# Functional tests only
python -m unittest tests.test_functional -v
# Manual cleanup
python tests/test_cleanup.py- Scans all blueprints on server
- Identifies test blueprints by naming patterns
- Safe - only removes blueprints with test keywords
python tests/test_cleanup.py --pattern "specific-pattern"python tests/test_cleanup.py --forceTEST_SERVER = "10.87.2.74"
TEST_USERNAME = "admin"
TEST_PASSWORD = "Apstramarvis@123"- Test blueprints use timestamped names
- Pattern:
test-{type}-{timestamp} - Examples:
test-datacenter-1751648231,e2e-test-1751648173
- Authentication Check - Tests skip if server unreachable
- Blueprint Tracking - Multiple tracking mechanisms for cleanup
- Pattern Matching - Only removes blueprints with test keywords
- Error Handling - Graceful failure if cleanup fails
- Verification - Post-cleanup verification of removal
- Unit Tests: Should always pass (mocked)
- Functional Tests:
- ✅ Datacenter blueprint creation: PASS
⚠️ Freeform blueprint creation: SKIP (version dependent)- ✅ Authentication, templates, deletion: PASS
✓ Deleted tracked blueprint {id}
✓ All test blueprints successfully removed!
✓ Post-test cleanup completed successfully
- Run manual cleanup:
python test.py clean - Check server connectivity
- Verify authentication credentials
- Use force cleanup for specific patterns
# List all blueprints to identify test ones
python -c "from apstra_core import get_bp; print(get_bp())"
# Force cleanup specific pattern
python tests/test_cleanup.py --pattern "test-"- Network timeout: Increase timeout in test_config.py
- Authentication failure: Check credentials in test_config.py
- Blueprint stuck: May need manual deletion via GUI
- Always run cleanup after manual testing
- Use timestamped names for any manual test blueprints
- Include test keywords in blueprint names for auto-cleanup
- Run pre-test cleanup before important test sessions
- Monitor server state regularly to prevent accumulation
The test suite is designed for automated environments:
- Automatic pre/post cleanup
- Clear success/failure indicators
- Safe cleanup patterns
- No manual intervention required
# CI/CD friendly command
python tests/run_tests.py && echo "Tests completed with cleanup"