def get_documents_by_group_id(self, group_id: str) -> [Document]: """ Get document object by profile_id :param profile_id: :param all_view: :return: """ if not is_valid_mendeley_id(group_id): return None results = [] # Construct a file path relative to the project root path = get_relative_path('test', 'samples', 'documents', 'by_group_id', '%s.json' % group_id) # Check if path exists if not exists(path): return [] # If yes open and parse json with open(path, 'r', encoding="utf-8") as json_file: json_data = json.load(json_file) for json_doc in json_data: doc = get_document_from_json(json_doc) results.append(doc) return results
def get_group_members(self, group_id: str) -> [Member]: if not is_valid_mendeley_id(group_id): return [] # Construct a file path relative to the project root path = get_relative_path('test', 'samples', 'groups', '%s.json' % group_id) # Check if path exists if not exists(path): return [] # If yes open and parse json with open(path, 'r', encoding="utf-8") as json_file: json_data = json.load(json_file) return get_members_from_json(json_data)
def read_sql_statements(*path) -> [str]: """ Given a file path this method reads the sql file at that location, cleans the sql statements (whitespace/comments) and splits statements via semicolon. Subsequently all the empty statements are removed :param path: :return: """ sql_file_path = get_relative_path(*path) with open(sql_file_path, "r") as sql_statements_file: sql_statements_string = sql_statements_file.read() sql_statements_string = clean_sql(sql_statements_string) sql_statements = sql_statements_string.split(';') result = [stmt for stmt in sql_statements if stmt and not stmt.isspace()] return result
def read_sql_statements(*path) -> [str]: """ Given a file path this method reads the sql file at that location, cleans the sql statements (whitespace/comments) and splits statements via semicolon. Subsequently all the empty statements are removed :param path: :return: """ sql_file_path = get_relative_path(*path) with open(sql_file_path, "r") as sql_statements_file: sql_statements_string = sql_statements_file.read() sql_statements_string = clean_sql(sql_statements_string) sql_statements = sql_statements_string.split(';') result = [ stmt for stmt in sql_statements if stmt and not stmt.isspace() ] return result
def get_profile_by_id(self, profile_id: str) -> Profile: """ Get profile object by profile_id :param profile_id: :return: """ if not is_valid_mendeley_id(profile_id): return None # Construct a file path relative to the project root path = get_relative_path('test', 'samples', 'profiles', '%s.json' % profile_id) # Check if path exists if not exists(path): return None # If yes open and parse json with open(path, 'r', encoding="utf-8") as json_file: json_data = json.load(json_file) return get_profile_from_json(json_data)
from pprint import PrettyPrinter if len(sys.argv) >= 2: log.info("Welcome to the MendeleyCache runner") command = sys.argv[1] # Test runner if command == "tests": log.info("Disabling non-critical logs for better unittest output") # Disable logging for tests logging.disable(logging.CRITICAL) # Get project root path project_root = get_relative_path(".") # Prepare loader = TestLoader() runner = unittest.TextTestRunner(verbosity=2) # Create suites all = loader.discover(start_dir=project_root) # Run suites runner.run(all) elif command == "prepare": log.info("Preparing environment for gunicorn workers") # Read configuration configuration = ServiceConfiguration()
if len(sys.argv) >= 2: log.info("Welcome to the MendeleyCache runner") command = sys.argv[1] # Test runner if command == "tests": log.info("Disabling non-critical logs for better unittest output") # Disable logging for tests logging.disable(logging.CRITICAL) # Get project root path project_root = get_relative_path(".") # Prepare loader = TestLoader() runner = unittest.TextTestRunner(verbosity=2) # Create suites all = loader.discover(start_dir=project_root) # Run suites runner.run(all) elif command == "prepare": log.info("Preparing environment for gunicorn workers") # Read configuration configuration = ServiceConfiguration()