From b894eb2477c9bc51c7905b10a119ab8454753a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 10 May 2016 10:47:01 +0200 Subject: [PATCH] Skip Algolia in unit tests. Unit tests hang when our internet connection dropped. --- pillar/application/utils/__init__.py | 17 ++++++++++++++++- pillar/application/utils/algolia.py | 8 +++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pillar/application/utils/__init__.py b/pillar/application/utils/__init__.py index 85917c66..968e743f 100644 --- a/pillar/application/utils/__init__.py +++ b/pillar/application/utils/__init__.py @@ -1,13 +1,15 @@ import copy import json import datetime +import functools +import logging import bson from eve import RFC1123_DATE_FORMAT from flask import current_app __all__ = ('remove_private_keys', 'PillarJSONEncoder') - +log = logging.getLogger(__name__) def remove_private_keys(document): """Removes any key that starts with an underscore, returns result as new @@ -52,3 +54,16 @@ def jsonify(mongo_doc, status=200, headers=None): mimetype='application/json', status=status, headers=headers) + + +def skip_when_testing(func): + """Decorator, skips the decorated function when app.config['TESTING']""" + + @functools.wraps(func) + def wrapper(*args, **kwargs): + if current_app.config['TESTING']: + log.debug('Skipping call to %s(...) due to TESTING', func.func_name) + return None + + return func(*args, **kwargs) + return wrapper diff --git a/pillar/application/utils/algolia.py b/pillar/application/utils/algolia.py index 473d788b..004fce3f 100644 --- a/pillar/application/utils/algolia.py +++ b/pillar/application/utils/algolia.py @@ -1,10 +1,16 @@ +import logging + from bson import ObjectId from flask import current_app + from application import algolia_index_users from application import algolia_index_nodes from application.modules.file_storage import generate_link +from . import skip_when_testing +log = logging.getLogger(__name__) +@skip_when_testing def algolia_index_user_save(user): # Define accepted roles accepted_roles = ['admin', 'subscriber', 'demo'] @@ -24,7 +30,7 @@ def algolia_index_user_save(user): 'email': user['email'] }) - +@skip_when_testing def algolia_index_node_save(node): accepted_node_types = ['asset', 'texture', 'group'] if node['node_type'] in accepted_node_types and algolia_index_nodes: