Files
Text-Texture-Generator-for-…/tests/e2e/test_free_version_e2e.py
2025-10-10 14:41:18 +02:00

605 lines
20 KiB
Python

"""
E2E Tests for Free Version Feature Restrictions
These tests specify the expected behavior when VERSION_TYPE="free".
They validate that free version users:
1. Can use basic features (text generation, preview)
2. CANNOT access PRO features (shaders, presets, overlays, normal maps)
3. Have REDUCED limits (max_texture_size=1024, max_concurrent=1)
4. See UI locks/badges on PRO features
TESTING STRATEGY:
- Tests detect current VERSION_TYPE from running addon
- If VERSION_TYPE="full": tests SKIP (documented as specification)
- If VERSION_TYPE="free": tests RUN and validate restrictions
- Tests use NO MOCKS - only real Blender bpy API operations
EXPECTED BEHAVIOR (FREE VERSION):
- ENABLED_FEATURES = ["basic", "preview"] only
- BLOCKED: shader_generation, normal_maps, image_overlays, presets, advanced
- LIMITS: max_texture_size=1024, max_concurrent_operations=1
- UI: Shows "🔒 PRO" badges on locked features
"""
import json
import pytest
from pathlib import Path
import tarfile
import io
pytestmark = pytest.mark.e2e
def get_version_type(blender_container, addon_package):
"""Detect VERSION_TYPE from running addon."""
script_content = """
import bpy
import sys
import json
# Enable addon
try:
bpy.ops.preferences.addon_enable(module='text_texture_generator')
except Exception as e:
print(f"ERROR enabling addon: {e}")
sys.exit(1)
# Import constants
try:
from text_texture_generator.utils.constants import VERSION_TYPE, ENABLED_FEATURES
result = {
'version_type': VERSION_TYPE,
'enabled_features': ENABLED_FEATURES
}
print('RESULT:', json.dumps(result))
except Exception as e:
print(f"ERROR importing constants: {e}")
sys.exit(1)
"""
# Create tar with script
tar_stream = io.BytesIO()
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
script_info = tarfile.TarInfo(name='detect_version.py')
script_bytes = script_content.encode('utf-8')
script_info.size = len(script_bytes)
tar.addfile(script_info, io.BytesIO(script_bytes))
tar_stream.seek(0)
blender_container.put_archive('/addon-test', tar_stream)
# Copy addon package
addon_tar_stream = io.BytesIO()
with tarfile.open(fileobj=addon_tar_stream, mode='w') as tar:
addon_info = tarfile.TarInfo(name='text_texture_generator.zip')
addon_info.size = addon_package.stat().st_size
with open(addon_package, 'rb') as f:
tar.addfile(addon_info, f)
addon_tar_stream.seek(0)
blender_container.put_archive('/addon-test', addon_tar_stream)
# Install addon
install_cmd = [
"/usr/local/bin/run_blender.sh",
"--background",
"--python-expr",
(
"import bpy; "
"bpy.ops.preferences.addon_install(filepath='/addon-test/text_texture_generator.zip'); "
"bpy.ops.preferences.addon_enable(module='text_texture_generator'); "
"bpy.ops.wm.save_userpref()"
)
]
install_result = blender_container.exec_run(install_cmd, workdir="/addon-test")
assert install_result.exit_code == 0, f"Addon install failed: {install_result.output.decode()}"
# Run detection script
test_cmd = [
"/usr/local/bin/run_blender.sh",
"--background",
"--python",
"/addon-test/detect_version.py"
]
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
output = test_result.output.decode('utf-8', errors='replace')
# Parse version info
for line in output.split('\n'):
if 'RESULT:' in line:
data = json.loads(line.split('RESULT:')[1].strip())
return data['version_type'], data['enabled_features']
pytest.fail(f"Could not detect VERSION_TYPE from addon output:\n{output}")
def test_free_version_basic_features_work(blender_container, addon_package):
"""
SPECIFICATION: Free version MUST allow basic text-to-texture generation.
Expected behavior (VERSION_TYPE="free"):
- Text input works
- Material creation works
- Preview generation works
- "basic" feature is enabled
Current state (VERSION_TYPE="full"):
- Test SKIPS (marked as specification for future)
"""
version_type, enabled_features = get_version_type(blender_container, addon_package)
if version_type == "full":
pytest.skip("Test requires VERSION_TYPE='free' - currently 'full' (specification test)")
# Test basic generation works
script_content = """
import bpy
import sys
# Addon already enabled by get_version_type
# Verify basic feature enabled
from text_texture_generator.utils.constants import ENABLED_FEATURES
assert "basic" in ENABLED_FEATURES, f"'basic' not in ENABLED_FEATURES: {ENABLED_FEATURES}"
# Create test object
bpy.ops.mesh.primitive_cube_add()
obj = bpy.context.active_object
# Try basic generation
props = bpy.context.scene.ttg_props
props.text_input = "Free Version Test"
props.texture_size = 512 # Within free limit
try:
bpy.ops.ttg.generate_texture()
mat = obj.active_material
assert mat is not None, "Material not created"
print("SUCCESS: Basic generation works in free version")
except Exception as e:
print(f"FAIL: Basic generation failed: {e}")
sys.exit(1)
"""
tar_stream = io.BytesIO()
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
script_info = tarfile.TarInfo(name='test_basic.py')
script_bytes = script_content.encode('utf-8')
script_info.size = len(script_bytes)
tar.addfile(script_info, io.BytesIO(script_bytes))
tar_stream.seek(0)
blender_container.put_archive('/addon-test', tar_stream)
test_cmd = [
"/usr/local/bin/run_blender.sh",
"--background",
"--python",
"/addon-test/test_basic.py"
]
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
output = test_result.output.decode('utf-8', errors='replace')
assert test_result.exit_code == 0, f"Basic generation failed:\n{output}"
assert "SUCCESS: Basic generation works" in output
def test_free_version_blocks_shader_generation(blender_container, addon_package):
"""
SPECIFICATION: Free version MUST block shader generation feature.
Expected behavior (VERSION_TYPE="free"):
- "shader_generation" NOT in ENABLED_FEATURES
- Shader properties unavailable or restricted
- UI shows "🔒 PRO" badge
Current state (VERSION_TYPE="full"):
- Test SKIPS (shader_generation is available)
"""
version_type, enabled_features = get_version_type(blender_container, addon_package)
if version_type == "full":
pytest.skip("Test requires VERSION_TYPE='free' - currently 'full' (specification test)")
script_content = """
import bpy
import sys
# Verify shader_generation NOT enabled
from text_texture_generator.utils.constants import ENABLED_FEATURES
if "shader_generation" in ENABLED_FEATURES:
print(f"FAIL: shader_generation should NOT be in ENABLED_FEATURES for free version")
sys.exit(1)
print("SUCCESS: Shader generation properly blocked")
"""
tar_stream = io.BytesIO()
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
script_info = tarfile.TarInfo(name='test_shader.py')
script_bytes = script_content.encode('utf-8')
script_info.size = len(script_bytes)
tar.addfile(script_info, io.BytesIO(script_bytes))
tar_stream.seek(0)
blender_container.put_archive('/addon-test', tar_stream)
test_cmd = [
"/usr/local/bin/run_blender.sh",
"--background",
"--python",
"/addon-test/test_shader.py"
]
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
output = test_result.output.decode('utf-8', errors='replace')
assert test_result.exit_code == 0, f"Shader block test failed:\n{output}"
assert "SUCCESS: Shader generation properly blocked" in output
def test_free_version_blocks_presets(blender_container, addon_package):
"""
SPECIFICATION: Free version MUST block preset save/load functionality.
Expected behavior (VERSION_TYPE="free"):
- "presets" NOT in ENABLED_FEATURES
- Preset operators unavailable
- UI shows "🔒 PRO" on preset buttons
Current state (VERSION_TYPE="full"):
- Test SKIPS (presets are available)
"""
version_type, enabled_features = get_version_type(blender_container, addon_package)
if version_type == "full":
pytest.skip("Test requires VERSION_TYPE='free' - currently 'full' (specification test)")
script_content = """
import bpy
import sys
# Verify presets NOT enabled
from text_texture_generator.utils.constants import ENABLED_FEATURES
if "presets" in ENABLED_FEATURES:
print(f"FAIL: presets should NOT be in ENABLED_FEATURES for free version")
sys.exit(1)
print("SUCCESS: Preset functionality properly blocked")
"""
tar_stream = io.BytesIO()
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
script_info = tarfile.TarInfo(name='test_presets.py')
script_bytes = script_content.encode('utf-8')
script_info.size = len(script_bytes)
tar.addfile(script_info, io.BytesIO(script_bytes))
tar_stream.seek(0)
blender_container.put_archive('/addon-test', tar_stream)
test_cmd = [
"/usr/local/bin/run_blender.sh",
"--background",
"--python",
"/addon-test/test_presets.py"
]
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
output = test_result.output.decode('utf-8', errors='replace')
assert test_result.exit_code == 0, f"Preset block test failed:\n{output}"
assert "SUCCESS: Preset functionality properly blocked" in output
def test_free_version_blocks_image_overlays(blender_container, addon_package):
"""
SPECIFICATION: Free version MUST block image overlay functionality.
Expected behavior (VERSION_TYPE="free"):
- "image_overlays" NOT in ENABLED_FEATURES
- Overlay controls unavailable
- UI shows "🔒 PRO" on overlay controls
Current state (VERSION_TYPE="full"):
- Test SKIPS (overlays are available)
"""
version_type, enabled_features = get_version_type(blender_container, addon_package)
if version_type == "full":
pytest.skip("Test requires VERSION_TYPE='free' - currently 'full' (specification test)")
script_content = """
import bpy
import sys
# Verify image_overlays NOT enabled
from text_texture_generator.utils.constants import ENABLED_FEATURES
if "image_overlays" in ENABLED_FEATURES:
print(f"FAIL: image_overlays should NOT be in ENABLED_FEATURES for free version")
sys.exit(1)
print("SUCCESS: Image overlay properly blocked")
"""
tar_stream = io.BytesIO()
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
script_info = tarfile.TarInfo(name='test_overlays.py')
script_bytes = script_content.encode('utf-8')
script_info.size = len(script_bytes)
tar.addfile(script_info, io.BytesIO(script_bytes))
tar_stream.seek(0)
blender_container.put_archive('/addon-test', tar_stream)
test_cmd = [
"/usr/local/bin/run_blender.sh",
"--background",
"--python",
"/addon-test/test_overlays.py"
]
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
output = test_result.output.decode('utf-8', errors='replace')
assert test_result.exit_code == 0, f"Overlay block test failed:\n{output}"
def test_free_version_blocks_text_fitting(blender_container, addon_package):
"""
SPECIFICATION: Free version MUST block text fitting functionality.
Expected behavior (VERSION_TYPE="free"):
- "text_fitting" NOT in ENABLED_FEATURES
- has_text_fitting() returns False
- Text fitting controls unavailable
- UI shows "🔒 PRO" on text fitting controls
Current state (VERSION_TYPE="full"):
- Test SKIPS (text_fitting is available)
"""
version_type, enabled_features = get_version_type(blender_container, addon_package)
if version_type == "full":
pytest.skip("Test requires VERSION_TYPE='free' - currently 'full' (specification test)")
script_content = """
import bpy
import sys
# Verify text_fitting NOT enabled
from text_texture_generator.utils.constants import ENABLED_FEATURES, has_text_fitting
if "text_fitting" in ENABLED_FEATURES:
print(f"FAIL: text_fitting should NOT be in ENABLED_FEATURES for free version")
sys.exit(1)
# Verify has_text_fitting() returns False
if has_text_fitting():
print(f"FAIL: has_text_fitting() should return False for free version")
sys.exit(1)
print("SUCCESS: Text fitting properly blocked")
"""
tar_stream = io.BytesIO()
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
script_info = tarfile.TarInfo(name='test_text_fitting.py')
script_bytes = script_content.encode('utf-8')
script_info.size = len(script_bytes)
tar.addfile(script_info, io.BytesIO(script_bytes))
tar_stream.seek(0)
blender_container.put_archive('/addon-test', tar_stream)
test_cmd = [
"/usr/local/bin/run_blender.sh",
"--background",
"--python",
"/addon-test/test_text_fitting.py"
]
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
output = test_result.output.decode('utf-8', errors='replace')
assert test_result.exit_code == 0, f"Text fitting block test failed:\n{output}"
assert "SUCCESS: Text fitting properly blocked" in output
def test_free_version_texture_size_limited(blender_container, addon_package):
"""
SPECIFICATION: Free version MUST limit max_texture_size to 1024px (not 4096px).
Expected behavior (VERSION_TYPE="free"):
- get_version_limits()['max_texture_size'] == 1024
- Attempting 4096px should fail or clamp to 1024
- UI should disable/hide 2048+ size options
Current state (VERSION_TYPE="full"):
- Test SKIPS (max_texture_size is 4096)
**CRITICAL BUG**: get_version_limits() currently returns same values for both versions!
"""
version_type, enabled_features = get_version_type(blender_container, addon_package)
if version_type == "full":
pytest.skip("Test requires VERSION_TYPE='free' - currently 'full' (specification test)")
script_content = """
import bpy
import sys
# Check version limits
from text_texture_generator.utils.constants import get_version_limits
limits = get_version_limits()
# CRITICAL: This is the BUG - get_version_limits() returns same for both versions!
max_size = limits.get('max_texture_size', 4096)
if max_size != 1024:
print(f"FAIL: max_texture_size should be 1024 for free version, got {max_size}")
sys.exit(1)
print(f"SUCCESS: Texture size properly limited to {max_size}px")
"""
tar_stream = io.BytesIO()
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
script_info = tarfile.TarInfo(name='test_size.py')
script_bytes = script_content.encode('utf-8')
script_info.size = len(script_bytes)
tar.addfile(script_info, io.BytesIO(script_bytes))
tar_stream.seek(0)
blender_container.put_archive('/addon-test', tar_stream)
test_cmd = [
"/usr/local/bin/run_blender.sh",
"--background",
"--python",
"/addon-test/test_size.py"
]
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
output = test_result.output.decode('utf-8', errors='replace')
# This test WILL FAIL because get_version_limits() has the bug
assert test_result.exit_code == 0, f"Size limit test failed:\n{output}"
assert "SUCCESS: Texture size properly limited to 1024px" in output
def test_free_version_ui_shows_pro_locks(blender_container, addon_package):
"""
SPECIFICATION: Free version UI MUST show correct feature flags.
Expected behavior (VERSION_TYPE="free"):
- has_feature() returns False for locked features
- has_feature() returns True for basic/preview only
- UI can check these flags to show "🔒 PRO" badges
Current state (VERSION_TYPE="full"):
- Test SKIPS (all features unlocked)
"""
version_type, enabled_features = get_version_type(blender_container, addon_package)
if version_type == "full":
pytest.skip("Test requires VERSION_TYPE='free' - currently 'full' (specification test)")
script_content = """
import bpy
import sys
# Check feature flags
from text_texture_generator.utils.constants import has_feature
# Verify locked features return False
locked_features = ["shader_generation", "presets", "image_overlays", "normal_maps"]
failed = []
for feature in locked_features:
if has_feature(feature):
failed.append(feature)
if failed:
print(f"FAIL: These features should be locked but aren't: {failed}")
sys.exit(1)
# Verify enabled features return True
enabled_features = ["basic", "preview"]
not_enabled = []
for feature in enabled_features:
if not has_feature(feature):
not_enabled.append(feature)
if not_enabled:
print(f"FAIL: These features should be enabled but aren't: {not_enabled}")
sys.exit(1)
print("SUCCESS: Feature flags correctly configured for free version")
"""
tar_stream = io.BytesIO()
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
script_info = tarfile.TarInfo(name='test_flags.py')
script_bytes = script_content.encode('utf-8')
script_info.size = len(script_bytes)
tar.addfile(script_info, io.BytesIO(script_bytes))
tar_stream.seek(0)
blender_container.put_archive('/addon-test', tar_stream)
test_cmd = [
"/usr/local/bin/run_blender.sh",
"--background",
"--python",
"/addon-test/test_flags.py"
]
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
output = test_result.output.decode('utf-8', errors='replace')
assert test_result.exit_code == 0, f"Feature flags test failed:\n{output}"
assert "SUCCESS: Feature flags correctly configured" in output
def test_free_version_concurrent_operations_limited(blender_container, addon_package):
"""
SPECIFICATION: Free version MUST limit max_concurrent_operations to 1 (not 4).
Expected behavior (VERSION_TYPE="free"):
- get_version_limits()['max_concurrent_operations'] == 1
- Cannot queue multiple operations simultaneously
Current state (VERSION_TYPE="full"):
- Test SKIPS (max_concurrent is 4)
**CRITICAL BUG**: get_version_limits() currently returns same values for both versions!
"""
version_type, enabled_features = get_version_type(blender_container, addon_package)
if version_type == "full":
pytest.skip("Test requires VERSION_TYPE='free' - currently 'full' (specification test)")
script_content = """
import bpy
import sys
# Check version limits
from text_texture_generator.utils.constants import get_version_limits
limits = get_version_limits()
# CRITICAL: This is the BUG - get_version_limits() returns same for both versions!
max_concurrent = limits.get('max_concurrent_operations', 4)
if max_concurrent != 1:
print(f"FAIL: max_concurrent_operations should be 1 for free version, got {max_concurrent}")
sys.exit(1)
print(f"SUCCESS: max_concurrent_operations correctly limited to {max_concurrent}")
"""
tar_stream = io.BytesIO()
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
script_info = tarfile.TarInfo(name='test_concurrent.py')
script_bytes = script_content.encode('utf-8')
script_info.size = len(script_bytes)
tar.addfile(script_info, io.BytesIO(script_bytes))
tar_stream.seek(0)
blender_container.put_archive('/addon-test', tar_stream)
test_cmd = [
"/usr/local/bin/run_blender.sh",
"--background",
"--python",
"/addon-test/test_concurrent.py"
]
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
output = test_result.output.decode('utf-8', errors='replace')
# This test WILL FAIL because get_version_limits() has the bug
assert test_result.exit_code == 0, f"Concurrent limit test failed:\n{output}"
assert "SUCCESS: max_concurrent_operations correctly limited to 1" in output