Commit 6155c19a authored by Sascha Herzinger's avatar Sascha Herzinger

more passing unit tests...

parent c9cbef74
......@@ -39,7 +39,7 @@ class ETLHandler(metaclass=abc.ABCMeta):
raise NotImplementedError()
def __init__(self, server, auth):
if not isinstance(server, str) or len(server) < 10:
if not isinstance(server, str) or not server:
error = ("{} is not a valid server url.".format(server))
logger.error(error)
raise ValueError(error)
......
......@@ -19,7 +19,7 @@ class RedisSession(CallbackDict, SessionMixin):
'data_tasks': [],
'analytic_tasks': [],
'subsets': [],
'state_access': []
'state_access': {}
}
def on_update(self):
......
......@@ -70,6 +70,7 @@ def request_state_access(state_id: UUID) -> Tuple[Response, int]:
logger.debug("Received POST request on /state/<uuid:state_id>.")
wait = request.args.get('wait') == '1'
payload = request.get_json(force=True)
state_id = str(state_id)
value = redis.get('state:{}'.format(state_id))
if not value:
error = "Could not find state associated with id {}".format(state_id)
......@@ -79,14 +80,17 @@ def request_state_access(state_id: UUID) -> Tuple[Response, int]:
matches = re.findall('\$.+?\$', value)
for match in matches:
task_id, _ = AnalyticTask.parse_value(match)
if redis.get('data:{}'.format(task_id)) is None:
value = redis.get('data:{}'.format(task_id))
if value is None:
error = "The state with id {} exists, but one or more of the " \
"associated data task ids are missing. Hence this state " \
"is lost forever because access can no longer be " \
"associated data task ids are missing. Hence this saved " \
"state is lost forever because access can no longer be " \
"verified. Deleting state..."
logger.error(error)
redis.delete('data:{}'.format(task_id))
redis.delete('state:{}'.format(state_id))
return jsonify({'error': error}), 403
data_state = json.loads(value)
descriptors.append(data_state['meta']['descriptor'])
etl_handler = ETLHandler.factory(handler=payload['handler'],
server=payload['server'],
auth=payload['auth'])
......
......@@ -6,5 +6,4 @@ addopts =
--color=yes
--verbose
--capture=no
--cov=fractalis
testpaths = tests
......@@ -74,28 +74,31 @@ class TestState:
def test_error_if_task_id_is_no_etl_id(self, test_client):
uuid = str(uuid4())
redis.set('state:{}'.format(uuid), 'foo')
redis.set('state:{}'.format(uuid), '$123$')
rv = test_client.post('/state/{}'.format(uuid), data=flask.json.dumps(
{'handler': '', 'server': '', 'auth': {'token': ''}}))
body = flask.json.loads(rv.get_data())
assert 400 == rv.status_code, body
assert 403 == rv.status_code, body
assert 'error' in body
assert 'data task ids are missing' in body['error']
assert not redis.exists('state:{}'.format(uuid))
def test_202_create_valid_state_if_valid_conditions(self, test_client):
uuid = str(uuid4())
redis.set(name='data:{}'.format(uuid),
value=json.dumps({'meta': {'descriptor': 'foo'}}))
redis.set(name='data:123',
value=json.dumps(
{'meta': {'descriptor': {'data_type': 'default'}}}))
redis.set(name='state:{}'.format(uuid), value='$123$')
rv = test_client.post(
'/state/{}'.format(uuid), data=flask.json.dumps(
{'handler': '', 'server': '', 'auth': {'token': ''}}))
{'handler': 'test', 'server': 'foo', 'auth': {'token': ''}}))
body = flask.json.loads(rv.get_data())
assert 202 == rv.status_code, body
assert not body
with test_client.session_transaction() as sess:
assert sess['data_tasks']
assert sess['state_access']
assert sess['data_tasks'] == sess['state_access']
assert sess['data_tasks'] == sess['state_access'][uuid]
assert [UUID(uuid) for uuid in sess['data_tasks']]
def test_404_if_get_non_existing_state(self, test_client):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment