Exemplo n.º 1
0
    def test_model_support_zipfile_no_zip_path(self):
        """
        Tests a few conditions of our App.support_zipfile() method to ensure that
        it returns False when the zip path isn't configured
        """
        # Should start out True
        self.assertEqual(App.support_zipfile(), True)

        # Return false when the configured path is blank
        self.prefs['exordium__zipfile_path'] = ''
        self.assertEqual(App.support_zipfile(), False)
Exemplo n.º 2
0
    def test_model_support_zipfile_no_zip_dir(self):
        """
        Tests a few conditions of our App.support_zipfile() method to ensure that
        it returns False when the zip dir doesn't exist.
        """
        # Should start out True
        self.assertEqual(App.support_zipfile(), True)

        # Should return False if we're configured but the zip dir doesn't
        # actually exist
        shutil.rmtree(self.zipfile_path)
        self.assertEqual(App.support_zipfile(), False)
Exemplo n.º 3
0
    def test_library_view_show_zipfile(self):
        """
        Test our library management view when we have zipfile configured.  Should
        show our zipfile info.  (The rest of the library management page is tested
        in ``LibraryViewTests``)
        """

        self.login()
        response = self.client.get(reverse('exordium:library'))
        self.assertEqual(response.status_code, 200)

        App.ensure_prefs()
        self.assertContains(response, 'Zipfile Support:</strong> Yes')
        self.assertNotContains(response, 'Zipfile Support:</strong> No')
        self.assertContains(response, App.prefs['exordium__zipfile_url'])
        self.assertContains(response, App.prefs['exordium__zipfile_path'])
Exemplo n.º 4
0
    def test_with_permission(self):
        """
        Test when we're logged in.
        """

        self.login()
        response = self.client.get(reverse('exordium:library'))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, reverse('exordium:library_update'))

        # We should show our library config, and not have zipfile info
        App.ensure_prefs()
        self.assertContains(response, App.prefs['exordium__base_path'])
        self.assertContains(response, App.prefs['exordium__media_url_html5'])
        self.assertContains(response, App.prefs['exordium__media_url_m3u'])
        self.assertNotContains(response, 'Zipfile Support:</strong> Yes')
        self.assertContains(response, 'Zipfile Support:</strong> No')
Exemplo n.º 5
0
    def test_ensure_various_artists_return_existing(self):
        """
        Test our App.ensure_various_artists() function and ensure that
        it returns an existing 'Various' artist if one exists.
        """
        App.ensure_various_artists()
        self.assertEqual(Artist.objects.count(), 1)
        ar = Artist.objects.get()
        ar_pk = ar.pk
        self.assertEqual(ar.name, 'Various')
        self.assertEqual(ar.various, True)

        self.assertEqual(App.ensure_various_artists(), False)
        ar = Artist.objects.get()
        self.assertEqual(ar.pk, ar_pk)
        self.assertEqual(ar.name, 'Various')
        self.assertEqual(ar.various, True)
Exemplo n.º 6
0
 def test_orig_exception(self):
     """
     Tests that our orig_exception attribute works as-expected
     """
     with self.assertRaises(App.AlbumZipfileError) as cm:
         try:
             a = int('a')
         except ValueError as e:
             raise App.AlbumZipfileError(e)
     self.assertEqual(type(cm.exception.orig_exception), type(ValueError()))
Exemplo n.º 7
0
 def test_ensure_various_artists_create_artist(self):
     """
     Test our App.ensure_various_artists() function and ensure that
     it creates a Various artist if needed.
     """
     self.assertEqual(Artist.objects.count(), 0)
     self.assertEqual(App.ensure_various_artists(), True)
     self.assertEqual(Artist.objects.count(), 1)
     ar = Artist.objects.get()
     self.assertEqual(ar.name, 'Various')
     self.assertEqual(ar.various, True)
Exemplo n.º 8
0
 def test_add_with_empty_to_add_list(self):
     """
     Test what happens when we run ``App.add()`` with an empty to_add
     list.  Calling this method with a list only happens inside
     ``App.update()``, and that method checks for an empty list before
     calling, so this should never actually happen in "real life,"
     but we'll check it anyway.
     """
     retlines = list(App.add([]))
     self.assertEqual(retlines, [])
     self.assertEqual(Artist.objects.count(), 0)
     self.assertEqual(Album.objects.count(), 0)
     self.assertEqual(Song.objects.count(), 0)
Exemplo n.º 9
0
    def test_miscellaneous_album_download_in_multiple_dirs(self):
        """
        Test to ensure that we can generate zipfiles for an album which is contained
        in more than one directory.  (Using a 'miscellaneous' album here but this'd
        work for any album which happens to do this)
        """
        self.add_mp3(artist='Artist',
                     title='Title 1',
                     filename='song1.mp3',
                     path='Artist/Tracks')
        self.add_mp3(artist='Artist',
                     title='Title 2',
                     filename='song2.mp3',
                     path='Artist/MoreTracks')
        self.run_add()

        self.assertEqual(Album.objects.count(), 1)
        album = Album.objects.get()

        self.assertEqual(Song.objects.count(), 2)

        response = self.client.get(
            reverse('exordium:albumdownload', args=(album.pk, )))
        self.assertEqual(response.status_code, 200)
        self.assertIn('filenames', response.context)
        self.assertIn('zip_file', response.context)
        self.assertIn('zip_url', response.context)
        self.assertEqual(
            sorted(response.context['filenames']),
            sorted(['Artist/Tracks/song1.mp3', 'Artist/MoreTracks/song2.mp3']))
        self.assertEqual(response.context['zip_file'],
                         'Artist_-_%s.zip' % (App.norm_filename(album.name)))
        self.assertContains(response, 'Artist/Tracks/song1.mp3<')
        self.assertContains(response, 'Artist/MoreTracks/song2.mp3<')
        self.assertContains(response, response.context['zip_file'])
        self.assertContains(response, response.context['zip_url'])
        self.assertContains(response, 'meta http-equiv')
        zip_file = os.path.join(self.zipfile_path,
                                response.context['zip_file'])
        self.assertEqual(os.path.exists(zip_file), True)

        with zipfile.ZipFile(zip_file, 'r') as zf:
            self.assertEqual(
                sorted(zf.namelist()),
                sorted(
                    ['Artist/Tracks/song1.mp3',
                     'Artist/MoreTracks/song2.mp3']))
Exemplo n.º 10
0
 def run_update_errors(self, errors_min=1, error=None):
     """
     Runs an ``add`` operation on our library, and expect to see at least
     one error.
     """
     return self.assertErrors(list(App.update()), errors_min, error=error)
Exemplo n.º 11
0
 def run_update(self):
     """
     Runs an ``update`` operation on our library, and checks for errors.
     """
     return self.assertNoErrors(list(App.update()))
Exemplo n.º 12
0
 def run_add(self):
     """
     Runs an ``add`` operation on our library, and checks for errors.
     """
     return self.assertNoErrors(list(App.add()))