def testGetScoreByBoijeNumber(self): score_1 = "Boije 1.pdf" score_2 = "Boije 2.pdf" boije_directory, json_file_path = boijeCollectionInit( DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME) scores_dictionary = dictionaryInit(json_file_path) time.sleep(5) ##sleep score_1_number = getBoijeNumber(score_1) score_2_number = getBoijeNumber(score_2) # make sure a duplicate folder is not within the directory self.assertFalse(os.path.exists( "./boije_test_directory/boije_test_directory")) self.assertEqual("1", score_1_number) self.assertEqual("2", score_2_number) composer_1, score_1_name = getScoreNameWithBoijeNumber(scores_dictionary, score_1_number) composer_2, score_2_name = getScoreNameWithBoijeNumber(scores_dictionary, score_2_number) self.assertEqual(composer_1, "Aguado_D") self.assertEqual(score_1_name, "Op_1_Douze_valses") self.assertEqual(composer_2, "Aguado_D") self.assertEqual(score_2_name, "Op_2_Trois_rondos_brillants")
def testDictionaryDoesNotLoadFromEmptyJson(self): indices = getBoijeLetterIndices() dictionary_should_be = consolidateIndicesToDictionary(indices) boije_directory, json_file_path = boijeCollectionInit(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME) returned_dictionary = dictionaryInit(json_file_path) self.assertEqual(returned_dictionary, dictionary_should_be)
def testInitSequenceCreatesJsonFile(self): json_file_path = os.path.join(self.directory_path, JSON_FILE_NAME) boije_directory = self.directory_path returned_boije_directory, returned_json_file_path = boijeCollectionInit(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME) self.assertEqual(json_file_path, returned_json_file_path) self.assertEqual(boije_directory, returned_boije_directory)
def testDictionaryLoadsFromJson(self): index_to_check = 'c' boije_directory, json_file_path = boijeCollectionInit(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME) link_to_check = boijeLink(index_to_check) convert_index_to_dictionary = convertIndexToDictionary(getIndexSoup(link_to_check)) write_to_json_file = updateJsonFile(convert_index_to_dictionary, json_file_path) returned_dictionary = dictionaryInit(json_file_path) self.assertEqual(convert_index_to_dictionary, returned_dictionary)
def testLoggingFileCreated(self): ''' Function that will create a logging file. Test existence of logging file. ''' boije_directory, json_file_path = boijeCollectionInit(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME) logging_file_name, path_to_logger = loggingInit(boije_directory) ##print logging_file_name, path_to_logger logger_exists = os.path.exists(path_to_logger) self.assertTrue(logger_exists)
def testScoreDownloader(self): index_to_check = 'c' boije_directory, json_file_path = boijeCollectionInit(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME) link_to_check = boijeLink(index_to_check) convert_index_to_dictionary = convertIndexToDictionary(getIndexSoup(link_to_check)) copy_of_dict = copy.deepcopy(convert_index_to_dictionary) ##lets check some composers composer_1 = 'Carcassi_M' composer_2 = 'anon' composer_3 = 'Cottin_A' carcassi_score_1 = convertScoreName('Op. 1. 3 Sonates.') carcassi_score_2 = convertScoreName('Op. 15. Tra la la. Air Varié …') carcassi_score_3 = convertScoreName('Op. 2. Trois Rondo Pour Guitare ou Lyre ...') anon_score_1 = convertScoreName('CHITARRISTA Moderna Pezzi Favoriti ...') anon_score_2 = convertScoreName('CIEBRA’s Hand-book for the Guitar ...') cottin_score_1 = convertScoreName('Ballade circassienne ...') cottin_score_2 = convertScoreName('Habanera.') ##### check paths, let's just make functions that check for paths path_to_carcassi_folder = os.path.join(self.directory_path, composer_1) path_to_anon_folder = os.path.join(self.directory_path, composer_2) path_to_cottin_folder = os.path.join(self.directory_path, composer_3) returned_dictionary = scoreDownloader(copy_of_dict, boije_directory, json_file_path) #throughout the download process, the dictionary returned by downloaded should be different #There should be some truth values self.assertNotEqual(convert_index_to_dictionary, returned_dictionary) self.assertTrue(returned_dictionary.get(composer_1).get(carcassi_score_1)[2]) self.assertTrue(returned_dictionary.get(composer_2).get(anon_score_1)[2]) ## ## Now the file paths should exist. carcassi_score_1_exists = getScorePath(composer_1, carcassi_score_1, boije_directory) carcassi_score_2_exists = getScorePath(composer_1, carcassi_score_2, boije_directory) carcassi_score_3_exists = getScorePath(composer_1, carcassi_score_3, boije_directory) anon_score_1_exists = getScorePath(composer_2, anon_score_1, boije_directory) anon_score_2_exists = getScorePath(composer_2, anon_score_2, boije_directory) cottin_score_1_exists = getScorePath(composer_3, cottin_score_1, boije_directory) cottin_score_2_exists = getScorePath(composer_3, cottin_score_2, boije_directory) self.assertTrue(carcassi_score_1_exists) self.assertTrue(carcassi_score_2_exists) self.assertTrue(carcassi_score_3_exists) self.assertTrue(anon_score_1_exists) self.assertTrue(anon_score_2_exists) self.assertTrue(cottin_score_1_exists) self.assertTrue(cottin_score_2_exists)
def testRenameExistingFiles(self): composer = "Aguado_D" boije_directory, json_file_path = boijeCollectionInit(DESTINATION_DIRECTORY, BOIJE_DIRECTORY_NAME) score_1_name = "Op_1_Douze_valses" score_2_name = "Op_2_Trois_rondos_brillants" renameBoijeFiles(boije_directory, json_file_path) score_1_renamed = os.path.exists( os.path.join(boije_directory, "%s/%s.pdf"%(composer, score_1_name)) ) score_2_renamed = os.path.exists( os.path.join(boije_directory, "%s/%s.pdf"%(composer, score_2_name)) ) #os.rename self.assertTrue(score_1_renamed) self.assertTrue(score_2_renamed) read_json_file_dict = convertJsonToDict(json_file_path) self.assertTrue(read_json_file_dict.get(composer).get(score_1_name)[2]) self.assertTrue(read_json_file_dict.get(composer).get(score_1_name)[2])