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 testConvertRowEntiresToDictionary(self):
        #checks to see if an index can be made into a dict
        #where dict = {'composer': {score1: (html, boije_number, downloaded)}, {score2: ...}}
        index_to_check = 'c'
        link_to_check = boijeLink(index_to_check)
        soup = getIndexSoup(link_to_check)

        dictionary_of_values = convertIndexToDictionary(soup)
        carcassi = dictionary_of_values.get('Carcassi_M')

        #remember that, the return of convertIndexToDictionary returns a dictioniary of composers
        #the dictionary will look like
        # {'composer': {'score1': ['html', 'boije', Downloaded], 'score2': [...]}, 'composer2': {...}...}
        self.assertEqual(len(dictionary_of_values['Calegari_F']), 2)
        self.assertIn('Carcassi_M', dictionary_of_values)
        self.assertIn('anon', dictionary_of_values)
        self.assertIn('Coste_N', dictionary_of_values)      
        #now check to see if some scores are found
        self.assertIn('Op_1_3_Sonates', dictionary_of_values['Carcassi_M'])
        self.assertIn('Op_13_4_Potpourris_des_plus_jolis_Airs_de_operas_de_Rossini', dictionary_of_values['Carcassi_M'])
        #now check to see if two of the above match the actual values from boije
        self.assertNotEqual(0, carcassi)
        self.assertEqual("pdf/Boije%2074.pdf", carcassi.get('Op_1_3_Sonates')[0])
        self.assertEqual("74", carcassi.get('Op_1_3_Sonates')[1])
        self.assertEqual(False, carcassi.get('Op_1_3_Sonates')[2])
    def testBoijeLetterIndexReturns200(self):
        index_to_check = 'c'
        url_to_check = boijeLink(index_to_check)
        r = requests.get(url_to_check)

        status_code = r.status_code

        self.assertEqual('http://biblioteket.statensmusikverk.se/ebibliotek/boije/Boije_c.htm', url_to_check)
        self.assertEqual(status_code, 200)
    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 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 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 testRetrieveLetterIndexSoup(self):
        index_to_check = 'c'

        soup = getIndexSoup(boijeLink(index_to_check))

        self.assertIn(unicode('<title>Boijes samling C</title>'), '%s'%soup.title)