2015-07-24 18:52:19 +00:00
|
|
|
import json
|
2016-10-11 19:16:28 +00:00
|
|
|
import io
|
2015-07-24 18:52:19 +00:00
|
|
|
|
|
|
|
from util.config.provider.baseprovider import BaseProvider
|
|
|
|
|
2016-05-23 21:10:03 +00:00
|
|
|
REAL_FILES = ['test/data/signing-private.gpg', 'test/data/signing-public.gpg']
|
|
|
|
|
2016-10-18 15:44:13 +00:00
|
|
|
class TestLicense(object):
|
|
|
|
@property
|
|
|
|
def subscription(self):
|
|
|
|
return {}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_expired(self):
|
|
|
|
return False
|
|
|
|
|
|
|
|
def validate(self, config):
|
|
|
|
pass
|
|
|
|
|
2015-07-24 18:52:19 +00:00
|
|
|
class TestConfigProvider(BaseProvider):
|
|
|
|
""" Implementation of the config provider for testing. Everything is kept in-memory instead on
|
|
|
|
the real file system. """
|
|
|
|
def __init__(self):
|
2016-02-11 09:04:37 +00:00
|
|
|
self.clear()
|
|
|
|
|
|
|
|
def clear(self):
|
2015-07-24 18:52:19 +00:00
|
|
|
self.files = {}
|
2016-02-11 09:04:37 +00:00
|
|
|
self._config = {}
|
2015-07-24 18:52:19 +00:00
|
|
|
|
2015-07-27 15:17:44 +00:00
|
|
|
@property
|
|
|
|
def provider_id(self):
|
|
|
|
return 'test'
|
|
|
|
|
2015-07-24 18:52:19 +00:00
|
|
|
def update_app_config(self, app_config):
|
|
|
|
self._config = app_config
|
|
|
|
|
2015-07-27 15:17:44 +00:00
|
|
|
def get_config(self):
|
2015-07-24 18:52:19 +00:00
|
|
|
if not 'config.yaml' in self.files:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return json.loads(self.files.get('config.yaml', '{}'))
|
|
|
|
|
2015-07-27 15:17:44 +00:00
|
|
|
def save_config(self, config_obj):
|
2015-07-24 18:52:19 +00:00
|
|
|
self.files['config.yaml'] = json.dumps(config_obj)
|
|
|
|
|
2015-07-27 15:17:44 +00:00
|
|
|
def config_exists(self):
|
2015-07-24 18:52:19 +00:00
|
|
|
return 'config.yaml' in self.files
|
|
|
|
|
|
|
|
def volume_exists(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def volume_file_exists(self, filename):
|
2016-05-23 21:10:03 +00:00
|
|
|
if filename in REAL_FILES:
|
|
|
|
return True
|
|
|
|
|
2015-07-24 18:52:19 +00:00
|
|
|
return filename in self.files
|
|
|
|
|
|
|
|
def save_volume_file(self, filename, flask_file):
|
|
|
|
self.files[filename] = ''
|
|
|
|
|
2015-12-08 20:00:50 +00:00
|
|
|
def write_volume_file(self, filename, contents):
|
|
|
|
self.files[filename] = contents
|
|
|
|
|
2015-07-24 18:52:19 +00:00
|
|
|
def get_volume_file(self, filename, mode='r'):
|
2016-05-23 21:10:03 +00:00
|
|
|
if filename in REAL_FILES:
|
|
|
|
return open(filename, mode=mode)
|
|
|
|
|
2016-10-11 19:16:28 +00:00
|
|
|
return io.BytesIO(self.files[filename])
|
2015-07-24 18:52:19 +00:00
|
|
|
|
|
|
|
def requires_restart(self, app_config):
|
|
|
|
return False
|
|
|
|
|
2016-10-18 15:44:13 +00:00
|
|
|
def get_license(self):
|
|
|
|
return TestLicense()
|
|
|
|
|
2015-07-24 18:52:19 +00:00
|
|
|
def reset_for_test(self):
|
|
|
|
self._config['SUPER_USERS'] = ['devtable']
|
|
|
|
self.files = {}
|