Ejemplo n.º 1
0
    def testDownloadScore_tryDownloadAgain_ResultsInError(self):
                        
        index_to_check = 'c'
        create_boije_directory = getOrCreateBoijeFolder(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME)
        composer = 'Carcassi_M'
        score = 'Op_1_3_Sonates'
        json_file_name = 'boije_collection_test.json'
        json_file_path = createJsonFile(json_file_name, create_boije_directory)
        link_to_check = boijeLink(index_to_check)
        soup = getIndexSoup(link_to_check)
        dictionary_of_values = convertIndexToDictionary(soup)
        dictionary_to_json = convertIndexToJson(dictionary_of_values, json_file_path)
        convert_json_to_dict = convertJsonToDict(json_file_path)
        score_dictionary = copy.deepcopy(convert_json_to_dict) 
        score_attributes = convert_json_to_dict = score_dictionary.get(composer).get(score)

        download_file = downloadAndSaveScore(create_boije_directory, composer, score, score_attributes)

        self.assertTrue(download_file)
        #now to save json file and reload it.
        score_dictionary[composer][score][2] = download_file
        convert_dict_to_json = updateJsonFile(score_dictionary, json_file_path)
        convert_json_to_dict_again = convertJsonToDict(json_file_path)

        score_dictionary = copy.deepcopy(convert_json_to_dict_again)
        score_attributes = score_dictionary.get(composer).get(score)


        download_file = downloadAndSaveScore(create_boije_directory, composer, score,  score_attributes)

        self.assertTrue(download_file)
Ejemplo n.º 2
0
    def testReadJsonFile_modifyAnd_SaveIt(self):
        index_to_check = 'c'
        create_boije_directory = getOrCreateBoijeFolder(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME)
        composer = 'Carcassi_M'
        score = 'Op_1_3_Sonates'
        json_file_name = 'boije_collection_test.json'
        json_file_path = createJsonFile(json_file_name, create_boije_directory)
        link_to_check = boijeLink(index_to_check)
        soup = getIndexSoup(link_to_check)
        dictionary_of_values = convertIndexToDictionary(soup)
        dictionary_to_json = convertIndexToJson(dictionary_of_values, json_file_path)
        convert_json_to_dict = convertJsonToDict(json_file_path)

        score_dictionary = copy.deepcopy(convert_json_to_dict)
        #make a function that wraps a try/except block
        #this function will need to copy the dictionary, and depending on whether 
        #a download succeeds.  It will update the 'downloaded' field from the dict
        #it will then return the dict
        carcassi = score_dictionary.get(composer)
        score_attributes = carcassi.get(score)
        html = score_attributes[0]
        
        self.assertFalse(score_attributes[2])

        #it will be better if this updating function takes in score attributes

        downloaded_file = downloadAndSaveScore(create_boije_directory, composer, score, score_attributes)
        
        self.assertTrue(downloaded_file)
        #set score_dictionary value to True
        score_dictionary[composer][score][2] = downloaded_file
        self.assertTrue(score_dictionary.get(composer).get(score)[0])
        
        self.assertNotEqual(score_dictionary[composer][score][2], convert_json_to_dict[composer][score][2])

        convert_dict_to_json = updateJsonFile(score_dictionary, json_file_path)
        convert_json_to_dict_again = convertJsonToDict(json_file_path)

        self.assertEqual(convert_json_to_dict_again, score_dictionary)
Ejemplo n.º 3
0
    def testSaveIndexToJSONAndReadIt(self):
       #checks to see if an index that is converted to a dict can be written into a file with json format
        index_to_check = 'c'
        create_boije_directory = getOrCreateBoijeFolder(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME)
        json_file_name = 'boije_collection_test.json'
        json_file_path = createJsonFile(json_file_name, create_boije_directory)
        link_to_check = boijeLink(index_to_check)
        soup = getIndexSoup(link_to_check)
        dictionary_of_values = convertIndexToDictionary(soup)
        #Our function will use a try/except block, that will will return a 1 or a 0 depending on success/failure
        dictionary_to_json = convertIndexToJson(dictionary_of_values, json_file_path)
        
        self.assertEqual(1, dictionary_to_json)
        json_file_size = os.path.getsize(json_file_path)
        json_file_exists = os.path.exists(json_file_path)
        self.assertTrue(json_file_exists)
        self.assertGreater(json_file_size, 0)
        
        
        #now we have a file that has something written to it.
        #We must  now check to see if when we read it, it will equate to dictionary_of_values

        convert_json_to_dict = convertJsonToDict(json_file_path)
        self.assertEqual(convert_json_to_dict, dictionary_of_values)