import pytest from mock import patch from util.config.validators import ConfigValidationException from util.config.validators.validate_license import LicenseValidator from util.morecollections import AttrDict from util.license import License, QUAY_DEPLOYMENTS_ENTITLEMENT, QUAY_ENTITLEMENT from test.fixtures import * @pytest.mark.parametrize('deployments, allowed_deployments', [ (1, 1), (3, 3), (3, 2), (3, 1), ]) def test_too_many_storage_engines(deployments, allowed_deployments, app): def get_license(): decoded = { 'expirationDate': '2157-12-1', 'subscriptions': { 'someSubscription': { 'serviceEnd': '2157-12-1', 'durationPeriod': 'yearly', 'entitlements': { QUAY_ENTITLEMENT: 1, QUAY_DEPLOYMENTS_ENTITLEMENT: allowed_deployments, }, }, }, } return License(decoded) storage_configs = [(str(i), {}) for i in range(0, deployments)] with patch('app.config_provider.get_license', get_license): validator = LicenseValidator() if allowed_deployments < deployments: with pytest.raises(ConfigValidationException): validator.validate({ 'DISTRIBUTED_STORAGE_CONFIG': storage_configs, }, None, None) else: validator.validate({ 'DISTRIBUTED_STORAGE_CONFIG': storage_configs, }, None, None)