diora-web/gpodder/tests.py

37 lines
2 KiB
Python
Raw Permalink Normal View History

import base64
import json
from django.contrib.auth.models import User
from django.test import TestCase
from podcasts.models import EpisodeProgress, PodcastEpisode, PodcastFeed
class EpisodeActionTests(TestCase):
"""Play positions from a gPodder client (AntennaPod sync) land on the user's own episode."""
def setUp(self):
self.alice = User.objects.create_user(username='alice', password='pw12345678')
bob = User.objects.create_user(username='bob', password='pw12345678')
url = 'https://example.org/feed'
audio = 'https://example.org/e1.mp3'
# Bob subscribed first: his copy of the episode has the lower id.
bobs_feed = PodcastFeed.objects.create(user=bob, rss_url=url, title='Feed')
self.bobs_ep = PodcastEpisode.objects.create(feed=bobs_feed, guid='e1', title='E1', audio_url=audio,
duration_seconds=1000)
alices_feed = PodcastFeed.objects.create(user=self.alice, rss_url=url, title='Feed')
self.alices_ep = PodcastEpisode.objects.create(feed=alices_feed, guid='e1', title='E1', audio_url=audio,
duration_seconds=1000)
self.auth = 'Basic ' + base64.b64encode(b'alice:pw12345678').decode()
def test_position_goes_to_own_episode(self):
actions = [{'podcast': 'https://example.org/feed', 'episode': 'https://example.org/e1.mp3',
'action': 'play', 'position': 300, 'total': 1000}]
r = self.client.post('/api/2/episodes/alice.json', json.dumps(actions), content_type='application/json',
HTTP_AUTHORIZATION=self.auth)
self.assertEqual(r.status_code, 200, r.content)
progress = EpisodeProgress.objects.get(user=self.alice)
self.assertEqual(progress.episode, self.alices_ep)
self.assertEqual(progress.position_seconds, 300)
self.assertFalse(EpisodeProgress.objects.filter(episode=self.bobs_ep).exists())