Esempio n. 1
0
@author: mika oja
@author: yazan barhoush
"""
import unittest
import json
import flask

import medical_forum.resources as resources
import medical_forum.database_engine as database

# Default paths for .db and .sql files to create and populate the database.
DEFAULT_DB_PATH = 'db/medical_forum_data_test.db'
DEFAULT_SCHEMA = "db/medical_forum_data_schema.sql"
DEFAULT_DATA_DUMP = "db/medical_forum_data_dump.sql"

ENGINE = database.Engine(DEFAULT_DB_PATH)

MASONJSON = "application/vnd.mason+json"
JSON = "application/json"
HAL = "application/hal+json"

FORUM_MESSAGE_PROFILE = "/profiles/message-profile/"
ATOM_THREAD_PROFILE = "https://tools.ietf.org/html/rfc4685"

# Tell Flask that I am running it in testing mode.
resources.APP.config["TESTING"] = True
# Necessary for correct translation in url_for
resources.APP.config["SERVER_NAME"] = "localhost:5000"

# Database Engine utilized in our testing
resources.APP.config.update({"Engine": ENGINE})
Esempio n. 2
0
"""
Create API and APP objects
"""
from flask import Flask, g
from flask_restful import Api
from medical_forum import database_engine
from medical_forum.utils import RegexConverter

APP = Flask(__name__, static_folder="static", static_url_path="/.")
APP.debug = True
APP.config.update({"Engine": database_engine.Engine()})
API = Api(APP)


def add_regex_support_to_routes():
    """
    Add the Regex Converter so we can use regex expressions when we define the routes
    """
    APP.url_map.converters["regex"] = RegexConverter


add_regex_support_to_routes()


@APP.before_request
def connect_db():
    """
    Creates a database connection before the request is proccessed.

    The connection is stored in the application context variable flask.g .
    Hence it is accessible from the request object.
Esempio n. 3
0
# Tables content initial sizes
INITIAL_MESSAGES_COUNT = 19
INITIAL_USERS_COUNT = 25
INITIAL_USERS_PROFILE_COUNT = 25
INITIAL_DIAGNOSIS_COUNT = 10

# Tables names
USERS_TABLE = 'users'
USERS_PROFILE_TABLE = 'users_profile'
MESSAGES_TABLE = 'messages'
DIAGNOSIS_TABLE = 'diagnosis'


# Database file path to be used for testing only and create database instance
DB_PATH = 'db/medical_forum_data_test.db'
ENGINE = database_engine.Engine(DB_PATH)


@pytest.fixture
def execute_query(self, query, fetch_type):
    """
    This is a helper method to facilitate and be used by many methods.
    This method is used to handle the execution of queries and return the result of that query.
    :param self: to pass the context of the parent method.
    :param query: the query to execute.
    :param fetch_type: whether to return one or all results from the cursor instance
            after query execution.
    :return: Either one or all tuple of results.
    """
    # connection instance
    con = self.connection.con