Exemplo n.º 1
0
def test_load_dir_questions(tmpdir):
    dir = tmpdir.mkdir("questions")
    dir.join(TEST_QUESTION_NAME + ".json").write(json.dumps(TEST_QUESTION_DICT))
    loaded = _load_questions_from_dir(question_dir=dir.strpath)
    assert list(loaded.keys()) == [TEST_QUESTION_NAME]

    # test fault tolerance to bad questions
    dir.join("badq.json").write('{')
    loaded = _load_questions_from_dir(question_dir=dir.strpath)
    assert list(loaded.keys()) == [TEST_QUESTION_NAME]
Exemplo n.º 2
0
def _bf_init_or_add_analysis(analysisName, questionDirectory, newAnalysis):
    from pybatfish.question.question import _load_questions_from_dir
    _check_network()
    questions = _load_questions_from_dir(questionDirectory)
    analysis = {
        question_name: question_class(question_name=question_name)
        for question_name, question_class in six.iteritems(questions)
    }
    with tempfile.NamedTemporaryFile() as tempFile:
        with open(tempFile.name, 'w') as analysisFile:
            json.dump(analysis, analysisFile, indent=2, sort_keys=True,
                      cls=BfJsonEncoder)
        json_data = workhelper.get_data_configure_analysis(
            bf_session, newAnalysis, analysisName, tempFile.name, None)
        json_response = resthelper.get_json_response(
            bf_session, CoordConsts.SVC_RSC_CONFIGURE_ANALYSIS, json_data)
    return json_response