from pathlib import Path from django.conf import settings from django.contrib.auth.models import User from django.test import TestCase class PlayerPagePodcastsTests(TestCase): """The podcast tab is the app's podcast page (static/podcasts/, copied from diora-android) on a browser host (static/js/podcasts-web.js).""" def test_logged_in_page_loads_the_podcast_host(self): user = User.objects.create_user('pod', password='pw-for-tests-only') self.client.force_login(user) html = self.client.get('/').content.decode() self.assertIn('id="tab-podcasts"', html) self.assertIn('', html) self.assertIn('dpw-loading', html) # The old podcast tab and its player bar are gone. self.assertNotIn('podcast-toolbar', html) self.assertNotIn('podcast-seek-bar', html) self.assertNotIn('INITIAL_PODCAST_FEEDS', html) def test_logged_out_page_asks_to_log_in(self): html = self.client.get('/').content.decode() self.assertIn('to subscribe to podcasts.', html) self.assertNotIn('dpw-loading', html) def test_podcast_ui_files_are_there(self): static = Path(settings.BASE_DIR) / 'static' host = (static / 'js' / 'podcasts-web.js').read_text(encoding='utf-8') for name in ('native-podcast.js', 'podcast-ui.css', 'podcasts-web.css'): path = static / 'podcasts' / name self.assertTrue(path.exists(), name) if name != 'podcasts-web.css': self.assertIn('Copied from diora-android', path.read_text(encoding='utf-8')[:300]) self.assertIn('/static/podcasts/' + name, host) sw = (static / 'js' / 'sw.js').read_text(encoding='utf-8') for path in ('/static/js/podcasts-web.js', '/static/podcasts/native-podcast.js'): self.assertIn(path, sw)