def my_form_post(): """the view function which return the result page by using the input pass to the back end Arguments: forms submitted in ReChord_front.html Return: rendered result page 'ReChord_result.html' by call on helper functions """ # todo: Need to iterate multiple user submitted files # tab1 snippet search if request.form['submit'] == 'Search Snippet In Our Database': tree, _ = prepare_tree('database/Chopin.xml') return search_snippet(request.form['text'], tree) # tab1 snippet search using user submitted library elif request.form['submit'] == 'Upload and Search Your Snippet': filename = upload_file('base_file') tree, _ = prepare_tree(str('uploads/' + filename)) return search_snippet(request.form['text'], tree) # tab2 terms search elif request.form['submit'] == 'Search Parameter': tag = request.form['term'] para = request.form['parameter'] tree, _ = prepare_tree('database/Chopin.xml') return search_terms(tag, para, tree) return
def positive_test_get_attrib_from_element(): """Positive test for get_attrib_from_element""" tree, _ = prepare_tree('database/Chopin.xml') attrib_ls = get_attrib_from_element(tree, 'note', 'pname') assert len( attrib_ls ) != 0, "positive_test_get_attrib_from_element: no attributes found"
def positive_test_search(): """Positive test for search""" tree, _ = prepare_tree('database/Chopin.xml') inputXML = etree.parse('testinput.xml') input_root = inputXML.getroot() measure_match_list = search(input_root, tree) assert len(measure_match_list) != 0, "search: unsuccessful"
def code_submit(): form = SnipUpload(request.form) if request.method == 'POST': name = request.form['name'] if form.validate(): # Save the comment here. flash('Your snippet is submitted successfully') transform_xml(name) flash('Your input snippet:') flash(name) tree, root = prepare_tree('database/Chopin.xml') inputXML = etree.parse('upload.xml') input_root = inputXML.getroot() # print a list of matches to testinput.XML from Chopin.XML flash(search(input_root, tree)) # get a list of artic element that has a staccato articulation element_artic_list = find_artic(tree, 'stacc') # print("-" * 10, "artic elements that has a staccato articulation", "-" * 10) for element in element_artic_list: flash('Element address:') flash(element) flash("is in measure:") flash(get_measure(element)) flash('-------------------------------------') else: flash('All the form fields are required. ') return render_template('frontend_search_test.html', form=form)
def positive_test_check_element_match(): """positive test for seeing if all elements in a file match themselves""" _, root = prepare_tree('database/Chopin.xml') all_equal = True unequalelt = None for element in root_to_list(root): if not check_element_match(element, element): all_equal = False unequalelt = element assert all_equal, "check_element_match: Not all elements equal to themselves. Check Element with id " + unequalelt.attrib[ "xml:id"]
def my_form_post(): """the view function which return the result page by using the input pass to the back end Arguments: form submitted in ReChord_front.html Return: rendered result page 'ReChord_result.html' """ if request.form['submit'] == 'Search Snippet': snippet = request.form['text'] xml = BytesIO(snippet.encode()) tree, root = prepare_tree('database/Chopin.xml') inputXML = etree.parse(xml) input_root = inputXML.getroot() snippet_measure = search(input_root, tree) return render_template('ReChord_result.html', results=snippet_measure)
def positive_test_get_creator(): """Positive test for get_creator""" tree, _ = prepare_tree('database/Chopin.xml') creator_list = get_creator(tree) assert len(creator_list) != 0, "get_creator: creator (composer) not found"
def positive_test_find_expressive_term(): """Positive test for find_expressive_term""" _, root = prepare_tree('database/Chopin.xml') element_et_list = find_expressive_term(root, 'legatissimo') assert len( element_et_list) != 0, "find_expressive_term: legatissimo not found."
def positive_test_get_title(): """Positive test for get_title""" tree, _ = prepare_tree('database/Chopin.xml') title_list = get_title(tree) assert len(title_list) != 0, "get_title: title not found"
def positive_test_find_artic(): """Positive test for find_artic""" _, root = prepare_tree('database/Chopin.xml') element_artic_list = find_artic(root, 'stacc') assert len(element_artic_list) != 0, "find_artic: stacc not found"
def positive_test_text_box_search(): """positive test to make sure text box search method completes a search through a given mei file""" _, root = prepare_tree('database/test_files/Chopin.xml') assert len(text_box_search( root, "Expressive Terms", "legatissimo")) != 0, "cannot find legatissimo expressive term"
def positive_test_check_element_match(): """positive test for seeing if all elements in a file match themselves""" _, root = prepare_tree('database/test_files/Chopin.xml') for element in root_to_list(root): assert check_element_match(element, element), \ "check_element_match: element not equal to themselves; check Element with id " + element.attrib["xml:id"]
def positive_test_dictionary_search(): """Positive test for text_box_search dictionary functionality""" tree, _ = prepare_tree('database/Chopin.xml') assert text_box_search(tree, "Expressive Terms", 'cresc.') == text_box_search(tree, "Expressive Terms", 'crescendo'),\ "text_box_search : crescendo and cresc. returning different results"
def positive_test_search(): """Positive test for search""" tree, _ = prepare_tree('database/test_files/Chopin.xml') input_tree, _ = prepare_tree('database/test_files/testinput.xml') measure_match_list = search(input_tree, tree) assert measure_match_list, "search: unsuccessful"