예제 #1
0
파일: main_test.py 프로젝트: fdion/imhotep
def test_tools_merges_tool_results():
    m = mock.MagicMock()
    m.invoke.return_value = {'a': 1}
    m2 = mock.MagicMock()
    m2.invoke.return_value = {'b': 2}
    repo = Repository('name', 'location', [m, m2], None)
    retval = run_analysis(repo)

    assert 'a' in retval
    assert 'b' in retval
예제 #2
0
파일: main_test.py 프로젝트: fdion/imhotep
def test_tools_invoked_on_repo():
    m = mock.MagicMock()
    m.invoke.return_value = {}
    repo = Repository('name', 'location', [m], None)
    run_analysis(repo)
    assert m.invoke.called
    def post(self):
        try:
            data = request.get_json()
            app_link = data['appLink']
            mask = data['mask']
            color = data['color']
            font_ = data['font']
            maxwords = int(data['maxwords'])
            corpus = data['corpus']
            data_response = data['dataResponse']
            custom_blocked_words = []
            if len(data['words']):
                custom_blocked_words = data['words'].replace(" ",
                                                             "").split(",")
            unique_filename = str(uuid.uuid4())

            if app_link == '' and data_response is None:
                retJson = {
                    "type":
                    "error",
                    "message":
                    "empty link and you haven't got previous results to change the mask "
                }

                return jsonify(retJson)

            if color == 'default':
                color = None

            if font_ == 'default':
                font = None
            else:
                font = 'font/{}.ttf'.format(font_)
                if os.path.isfile(font):
                    pass
                else:
                    font = 'font/{}.ttc'.format(font_)

            if data_response is not None and app_link == '':
                change_mask = True
            else:
                change_mask = False

            if change_mask:
                search_results = data_response['search_results']
                for key, value in search_results.items():
                    if key == 'histogram_image':
                        continue
                    os.remove(value)

            final_words, search_results = run_analysis(
                app_link, unique_filename, mask, color, font, maxwords, corpus,
                custom_blocked_words, data_response, change_mask)

            retJson = {
                "type": "success",
                "final_words": final_words,
                "search_results": search_results,
                "message": "Relevant cards fetched successfully!"
            }

            return jsonify(retJson)

        except Exception as err:
            print("Error: ", err)
            retJson = {"type": "error", "message": str(err)}
            return jsonify(retJson)