2021-04-09 02:31:49 -07:00
|
|
|
from django.test import TestCase
|
|
|
|
from django.urls import reverse
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from audio.models import Feed, Episode
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
|
|
|
|
def set_up():
|
|
|
|
user_a = User.objects.create(username='user_a')
|
|
|
|
user_a.set_password('password_user_a')
|
|
|
|
user_a.save()
|
|
|
|
user_b = User.objects.create(username='user_b')
|
|
|
|
user_b.set_password('password_user_b')
|
|
|
|
user_b.save()
|
|
|
|
feed_a = Feed.objects.create(user=user_a, title='Caesar-Pompey Civil War')
|
2021-04-11 15:03:56 -07:00
|
|
|
feed_b = Feed.objects.create(
|
|
|
|
user=user_a, title="Caesar's De Bello Gallico & Other Commentaries"
|
|
|
|
)
|
2021-04-09 02:31:49 -07:00
|
|
|
feed_c = Feed.objects.create(user=user_b, title="Short Stories Mark Twain")
|
2021-04-11 15:03:56 -07:00
|
|
|
Episode.objects.create(
|
|
|
|
user=user_a, feed=feed_a, title="Caesar-Pompey Civil War Book I",
|
|
|
|
pub_date=datetime.today() - timedelta(days=8)
|
|
|
|
)
|
|
|
|
Episode.objects.create(
|
|
|
|
user=user_a, feed=feed_a, title="Caesar-Pompey Civil War Book II",
|
|
|
|
pub_date=datetime.today() - timedelta(days=7)
|
|
|
|
)
|
|
|
|
Episode.objects.create(
|
|
|
|
user=user_a, feed=feed_b,
|
|
|
|
title="De Bello Gallico & Other Commentaries Book I",
|
|
|
|
pub_date=datetime.today() - timedelta(days=6)
|
|
|
|
)
|
|
|
|
Episode.objects.create(
|
|
|
|
user=user_a, feed=feed_b, title="De Bello Gallico & Other Commentaries Book II",
|
|
|
|
pub_date=datetime.today() - timedelta(days=5)
|
|
|
|
)
|
|
|
|
Episode.objects.create(
|
|
|
|
user=user_b, feed=feed_c, title="Mark Twain On Girls",
|
|
|
|
pub_date=datetime.today() - timedelta(days=4)
|
|
|
|
)
|
|
|
|
Episode.objects.create(
|
|
|
|
user=user_b, feed=feed_c, title="Mark Twain The Bee",
|
|
|
|
pub_date=datetime.today() - timedelta(days=3)
|
|
|
|
)
|
2021-04-09 02:31:49 -07:00
|
|
|
|
|
|
|
|
2021-04-11 15:03:56 -07:00
|
|
|
class TestViewsTestCase(TestCase):
|
2021-04-09 02:31:49 -07:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
set_up()
|
|
|
|
|
|
|
|
def test_home_view(self):
|
|
|
|
response = self.client.get(reverse('audio:home'))
|
|
|
|
self.assertEquals(response.status_code, 200)
|
|
|
|
self.assertTemplateUsed(response, 'audio/index.html')
|
2021-04-18 15:13:58 -07:00
|
|
|
self.assertEquals(response.request['PATH_INFO'], '/')
|
2021-04-09 02:31:49 -07:00
|
|
|
|
|
|
|
def test_feed_view(self):
|
|
|
|
feed_a = Feed.objects.get(title="Short Stories Mark Twain")
|
|
|
|
kw_args = {'pk': feed_a.pk, 'slug': feed_a.slug}
|
|
|
|
response = self.client.get(reverse('audio:feed', kwargs=kw_args))
|
|
|
|
self.assertEquals(response.status_code, 200)
|
|
|
|
self.assertTemplateUsed(response, 'audio/index.html')
|
2021-04-18 15:13:58 -07:00
|
|
|
self.assertEquals(
|
|
|
|
response.request['PATH_INFO'],
|
|
|
|
f'/feed/{feed_a.pk}/{feed_a.slug}'
|
|
|
|
)
|
2021-04-09 02:31:49 -07:00
|
|
|
|
|
|
|
def test_episode_view(self):
|
|
|
|
episode_a = Episode.objects.get(title='Mark Twain The Bee')
|
|
|
|
kw_args = {'pk': episode_a.pk, 'slug': episode_a.slug}
|
|
|
|
response = self.client.get(reverse('audio:episode', kwargs=kw_args))
|
|
|
|
self.assertEquals(response.status_code, 200)
|
|
|
|
self.assertTemplateUsed(response, 'audio/index.html')
|
2021-04-18 15:13:58 -07:00
|
|
|
self.assertEquals(
|
|
|
|
response.request['PATH_INFO'],
|
|
|
|
f'/episode/{episode_a.pk}/{episode_a.slug}'
|
|
|
|
)
|
2021-04-09 02:31:49 -07:00
|
|
|
|
|
|
|
def test_feeds_view(self):
|
|
|
|
response = self.client.get(reverse('audio:feeds'))
|
|
|
|
self.assertEquals(response.status_code, 200)
|
|
|
|
self.assertTemplateUsed(response, 'audio/feeds.html')
|
2021-04-18 15:13:58 -07:00
|
|
|
self.assertEquals(response.request['PATH_INFO'], '/feeds/')
|