Exemple #1
0
def test_query_and_push_task(mocked_post_le_search):
    with patch.object(Search, 'handle_response') as mocked_handle_response:
        search = Search(DummyService, conf_ex.DUMMY_SEARCH_CONFIG,
                        conf_ex.DUMMY_CONFIG)
        search.query_and_push_task()
        assert mocked_post_le_search.called
        assert mocked_handle_response.called
Exemple #2
0
def test_handle_cont_response(mocked_cont_final_resp):
    with patch.object(Search, 'process_final_response') as mocked_process_final_resp:
        search = Search(DummyService, conf_ex.DUMMY_SEARCH_CONFIG, conf_ex.DUMMY_CONFIG)
        httpretty.register_uri(httpretty.GET, req_ex.DEST_URL,
                               body={},
                               status=202)
        continuity_response = requests.get(req_ex.DEST_URL)
        search.handle_response(continuity_response)
        assert mocked_process_final_resp.called
Exemple #3
0
def test_process_final_response():
    with patch.object(DummyService, 'process') as mocked_process_method:
        search = Search(DummyService, conf_ex.DUMMY_SEARCH_CONFIG, conf_ex.DUMMY_CONFIG)
        httpretty.register_uri(httpretty.GET, req_ex.DEST_URL,
                               body=json.dumps({}),
                               status=200,
                               content_type='application/json')
        final_response = requests.get(req_ex.DEST_URL)
        search.process_final_response(final_response)
        assert mocked_process_method.called
Exemple #4
0
def test_process_final_response():
    with patch.object(DummyService, 'process') as mocked_process_method:
        search = Search(DummyService, conf_ex.DUMMY_SEARCH_CONFIG,
                        conf_ex.DUMMY_CONFIG)
        httpretty.register_uri(httpretty.GET,
                               req_ex.DEST_URL,
                               body=json.dumps({}),
                               status=200,
                               content_type='application/json')
        final_response = requests.get(req_ex.DEST_URL)
        search.process_final_response(final_response)
        assert mocked_process_method.called
Exemple #5
0
def test_handle_cont_response(mocked_cont_final_resp):
    with patch.object(Search,
                      'process_final_response') as mocked_process_final_resp:
        search = Search(DummyService, conf_ex.DUMMY_SEARCH_CONFIG,
                        conf_ex.DUMMY_CONFIG)
        httpretty.register_uri(httpretty.GET,
                               req_ex.DEST_URL,
                               body={},
                               status=202)
        continuity_response = requests.get(req_ex.DEST_URL)
        search.handle_response(continuity_response)
        assert mocked_process_final_resp.called
Exemple #6
0
def start_search_tasks():
    """
    Before everything, kill if there is any running search tasks. Then start the search tasks
    concurrently.

    """
    global SEARCH_TASKS
    logging.info(
        "(Re)populated config collections from config file. "
        "Cancelling previous loops and restarting them again with the new config."
    )

    for looping_task in SEARCH_TASKS:
        logging.info("Cancelling this loop: %r", looping_task)
        looping_task.stop()
    SEARCH_TASKS = []

    searches = CONFIG['Searches'].values()
    search_count = len(searches)
    logging.info("Search count: %d", search_count)
    reactor.suggestThreadPoolSize(search_count)
    try:
        for search in searches:
            search_obj = Search(
                SERVICE_CLASS_MAPPER.get(search['destination']['service']),
                search, CONFIG)
            do_search_concurrently(search_obj)
    except Exception as exception:
        logging.exception("Exception occurred while processing search. %s",
                          exception.message)
Exemple #7
0
def test_stop():
    with patch.object(task.LoopingCall, 'stop') as mocked_stop:
        search = Search(DummyService, conf_ex.DUMMY_SEARCH_CONFIG,
                        conf_ex.DUMMY_CONFIG)
        search.start()
        search.stop()
        assert mocked_stop.called
Exemple #8
0
def test_query_and_push_task(mocked_post_le_search):
    with patch.object(Search, 'handle_response') as mocked_handle_response:
        search = Search(DummyService, conf_ex.DUMMY_SEARCH_CONFIG, conf_ex.DUMMY_CONFIG)
        search.query_and_push_task()
        assert mocked_post_le_search.called
        assert mocked_handle_response.called
Exemple #9
0
def test_stop():
    with patch.object(task.LoopingCall, 'stop') as mocked_stop:
        search = Search(DummyService, conf_ex.DUMMY_SEARCH_CONFIG, conf_ex.DUMMY_CONFIG)
        search.start()
        search.stop()
        assert mocked_stop.called