def testBoijeDirectoryCreated(self):
        self.created_path = getOrCreateBoijeFolder(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME)
        
        created_path_exists = os.path.exists(self.created_path)

        self.assertTrue(created_path_exists)
        self.assertEqual(self.path, self.created_path)
    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)
    def testJsonFileExistsSoCreateShouldFail(self):
        json_file_name = 'boije_collection_test.json'
        create_boije_directory = getOrCreateBoijeFolder(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME)
        create_json_file = createJsonFile(json_file_name, create_boije_directory)

        create_json_file_again = createJsonFile(json_file_name, create_boije_directory)

        self.assertEqual(0, create_json_file_again) 
    def testCreateIndexFile(self):
        json_file_name = 'boije_collection_test.json'
        create_boije_directory = getOrCreateBoijeFolder(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME)
        #this test will check to see if a function exists to create a json index file
        file_path = os.path.join(self.directory_path, json_file_name)
        #file returns path or 0
        json_file_created = createJsonFile(json_file_name, create_boije_directory)

        self.assertEqual(file_path, json_file_created)
    def testStoreScore(self):
        downloaded_score = getScorePDF(self.html)
        create_boije_folder = getOrCreateBoijeFolder(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME)
        create_composer_folder = getOrCreateComposerFolder(create_boije_folder, self.composer)
        downloaded_score = getScorePDF(self.html)
        path_to_score_should_be = os.path.join(create_composer_folder, '%s.pdf'%self.score_name)

        #The output of saveScorePDF will be a tuple (SUCCESS_CODE, PATH_TO_DOWNLOADED_SCORE)
        saving_score_to_folder = saveScorePDF(downloaded_score, self.score_name, create_composer_folder)
        truth_of_score, path_of_score = saving_score_to_folder

        self.assertTrue(truth_of_score)
        self.assertEqual(path_of_score, path_to_score_should_be)
        
        ##now we can test the getScorePath function, this function should return true
        returned_truth_of_get_score_path = getScorePath(self.composer, self.score_name, create_boije_folder)
        self.assertTrue(returned_truth_of_get_score_path)

        returned_false_of_get_score_path = getScorePath(self.composer, self.not_real_score, create_boije_folder)
        self.assertFalse(returned_false_of_get_score_path)
    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)
    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)
 def setUp(self):
     self.directory_path = getOrCreateBoijeFolder(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME)