def test_handle_backup_search_query(self):
     searchEngineMock = MagicMock(return_value='foo_')
     with patch('settings.Settings.getSetting', searchEngineMock):
         subject = QueryHandler(QueryParser('needs_search'))
         response = subject.handle_query(self.aliases)
         self.assertEqual(response.status_code, 302)
         self.assertEqual(response.location, 'foo_needs_search')
 def test_handle_script_query_with_params(self):
     scriptMock = MagicMock()
     getAttrMock = MagicMock(return_value=scriptMock)
     subject = QueryHandler(QueryParser('script arg1:a arg2:b'))
     with patch('query_handler.getattr', getAttrMock):
         response = subject.handle_query(self.aliases)
         scriptMock.assert_called_with(arg1='a', arg2='b')
Example #3
0
def scry_query():
    print "SCRY REQUEST RECEIVED"
    ip = flask.request.remote_addr
    if ip in IP_WHITELIST:
        query = QueryHandler(flask.request, flask.g)
        return query.resolve()
    else:
        return "This IP address (%s) is not on the queried SCRY orb's whitelist." % ip, 500
Example #4
0
    def __init__(self):
        super(Cpanel, self).__init__()
        # this is really magic!! dont you even think to change this!! I can see youu o_O!!
        helper.Helper.__init__(self)

        self.db = QueryHandler(self.db_name)
        self.cmdloop(self.hello_message)

        self.return_result('extend is working yet', 'blue', 'bold')
Example #5
0
def main():
    os.chdir(RELATIVE_PATH_TO_CORPUS)

    docs = os.listdir(os.getcwd())
    index = InvertedIndex(docs)
    index.build()

    QueryHandler(index).loop()
Example #6
0
def init_collection(route_config):
    ds_rules_file = route_config.get("domain_specific_rules", None)

    html_view = init_view(route_config, "query_html", J2HtmlCapturesView)

    server_cls = route_config.get("server_cls")

    query_handler = QueryHandler.init_from_config(route_config, ds_rules_file, html_view, server_cls)

    return query_handler
Example #7
0
def init_collection(route_config):
    ds_rules_file = route_config.get('domain_specific_rules', None)

    html_view = init_view(route_config, 'query_html', J2HtmlCapturesView)

    server_cls = route_config.get('server_cls')

    query_handler = QueryHandler.init_from_config(route_config, ds_rules_file,
                                                  html_view, server_cls)

    return query_handler
Example #8
0
def init_collection(route_config):
    ds_rules_file = route_config.get('domain_specific_rules', None)

    html_view = (J2HtmlCapturesView.create_template(
        route_config.get('query_html'), 'Captures Page'))

    server_cls = route_config.get('server_cls')

    query_handler = QueryHandler.init_from_config(route_config, ds_rules_file,
                                                  html_view, server_cls)

    return query_handler
Example #9
0
def query_handler_fix():
    corpus = import_utils.load_corpus()

    mdls = news_model.create_models_list_from_news(corpus)
    for model in mdls:
        import_utils.remove_tags(model)

    ind = nindexer.Indexer()
    ind.feed(mdls, force=True)

    dct = ind.create_dictionary(force=True)

    qh = QueryHandler(dct)
    return qh
Example #10
0
def init_collection(route_config):
    ds_rules_file = route_config.get('domain_specific_rules', None)

    html_view = (J2HtmlCapturesView.
                 create_template(route_config.get('query_html'),
                                 'Captures Page'))

    server_cls = route_config.get('server_cls')

    query_handler = QueryHandler.init_from_config(route_config,
                                                  ds_rules_file,
                                                  html_view,
                                                  server_cls)

    return query_handler
Example #11
0
class Cpanel(cmd.Cmd, helper.Helper):
    def __init__(self):
        super(Cpanel, self).__init__()
        # this is really magic!! dont you even think to change this!! I can see youu o_O!!
        helper.Helper.__init__(self)

        self.db = QueryHandler(self.db_name)
        self.cmdloop(self.hello_message)

        self.return_result('extend is working yet', 'blue', 'bold')

    def do_use_default(self, item):
        self.db.default()

    def emptyline(self):
        if self.lastcmd:
            return None

    def do_link(self, args):
        self.db.insert_link(args)

    def do_drop(self, table):
        self.db.drop(table)

    # def do_clean(self,table):
    # self.db.delete(table)

    def do_show(self, table):
        self.db.show(table)

    def do_use(self, table):
        self.db.table = table
        self.return_result(self.db.table, 'yellow')

    def do_exit(self, args):
        answer = input(self.exit_message)
        if answer == 'yes':
            self.return_result(self.exit)
            raise SystemExit
Example #12
0
class CompanyHandler:
    NAME = "name"
    MONTHLY_SALARY = "monthly_salary"
    YEARLY_BONUS = "yearly_bonus"
    POSITION = "position"

    def __init__(self, db_name):
        self.query_handler = QueryHandler(db_name)
        self.query_handler.start_up()

    def add_employee(self, name, salary, bonus, position):
        values = (name, salary, bonus, position)
        self.query_handler.insert_query(values)

    def list_employees(self):
        employees = self.query_handler.select_employees()
        for employee in employees:
            print("{} - {} - {}".format(employee[0], employee[1], employee[2]))

    def monthly_spending(self):
        total = self.query_handler.select_monthly_spending()
        print("The company is spending {} every month".format(total[0][0]))

    def yearly_spending(self):
        total = self.query_handler.select_yearly_spending()
        print("The company is spending {} every year".format(total))

    def delete_employee(self, id):
        self.query_handler.delete_query(id)

    def update_employee(self, id, name, salary, bonus, position):
        values = (name, salary, bonus, position, id)
        self.query_handler.update_query(values)
Example #13
0
def query_handler(database_create_table_query, database_handler_init):
    with patch.object(DatabaseHandler, '__init__', database_handler_init):
        temp_query_handler = QueryHandler()
        temp_query_handler.cur.execute(database_create_table_query)
        return temp_query_handler
Example #14
0
def load_from_api():
    temp_query_handler = QueryHandler()
    temp_json_loader = JsonLoader()
    temp_json_loader.load_movies_data(temp_query_handler.get_all_titles())
    temp_query_handler.update_movies(temp_json_loader.data)
 def test_handle_alias_query(self):
     subject = QueryHandler(QueryParser('foo'))
     response = subject.handle_query(self.aliases)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.location, 'bar')
Example #16
0
def get_route_for_alias(query):
    handler = QueryHandler(QueryParser(query))
    return handler.handle_query(aliases)
Example #17
0
from storage import ORM
from data_entry import DataEntry, DataEntryError
from query_handler import QueryHandler, QuerySyntaxError


class UserPromptInputError(Exception):
    pass


def retreiveInput(user_input):
    [name, age] = user_input.split(',')
    return name, age


orm = ORM()
queryHandler = QueryHandler(orm)
while True:
    try:
        user_input = input(
            "Enter the name of employee, age and address or press 0 to enter a query statement\n"
        )
        if ',' in user_input:
            entry = DataEntry(orm, user_input)
            entry.apply_input()
        elif user_input == '0':
            # Create statement parser object
            query = input("Please enter a query statement\n")
            queryHandler.apply_query(query)
            print(queryHandler.result)
            input("Press enter to exit")
            pass
Example #18
0
 def __init__(self, db_name):
     self.query_handler = QueryHandler(db_name)
     self.query_handler.start_up()
class CompanyHandler:
    NAME = "name"
    MONTHLY_SALARY = "monthly_salary"
    YEARLY_BONUS = "yearly_bonus"
    POSITION = "position"

    def __init__(self, db_name):
        self.query_handler = QueryHandler(db_name)
        self.query_handler.start_up()

    def add_employee(self, name, salary, bonus, position):
        values = (name, salary, bonus, position)
        self.query_handler.insert_query(values)

    def list_employees(self):
        employees = self.query_handler.select_employees()
        for employee in employees:
            print("{} - {} - {}".format(employee[0], employee[1], employee[2]))

    def monthly_spending(self):
        total = self.query_handler.select_monthly_spending()
        print("The company is spending {} every month".format(total[0][0]))

    def yearly_spending(self):
        total = self.query_handler.select_yearly_spending()
        print("The company is spending {} every year".format(total))

    def delete_employee(self, id):
        self.query_handler.delete_query(id)

    def update_employee(self, id, name, salary, bonus, position):
        values = (name, salary, bonus, position, id)
        self.query_handler.update_query(values)
 def __init__(self, db_name):
     self.query_handler = QueryHandler(db_name)
     self.query_handler.start_up()