Files
@ 956f8c6fdaad
Branch filter:
Location: website/conservancy/usethesource/tests.py - annotation
956f8c6fdaad
2.1 KiB
text/x-python
podjango: Add "Podcast" model to support multiple podcasts
Each Cast (episode) can belong to one or more Podcast, allowing episodes to be
shared between podcasts. This enables us introductory episodes to be delivered
in their own feed, but also included in the main "The Corresponding Source"
feed.
This required adding an additional `podcast_slug` argument to most views. The
date archive views were dropped because they're not linked to from anywhere.
Added a `podcasts` view as an index of all available Podcasts.
Each Cast (episode) can belong to one or more Podcast, allowing episodes to be
shared between podcasts. This enables us introductory episodes to be delivered
in their own feed, but also included in the main "The Corresponding Source"
feed.
This required adding an additional `podcast_slug` argument to most views. The
date archive views were dropped because they're not linked to from anywhere.
Added a `podcasts` view as an index of all available Podcasts.
cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 3cccc3bdd90e cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 3cccc3bdd90e 3cccc3bdd90e 3cccc3bdd90e 3cccc3bdd90e 3cccc3bdd90e 3cccc3bdd90e 3cccc3bdd90e 3cccc3bdd90e 3cccc3bdd90e 3cccc3bdd90e 3cccc3bdd90e cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 cadd69061f18 | import datetime
import re
from django.contrib.auth.models import User
import pytest
from . import models
from .emails import make_candidate_email, make_comment_email
from .models import Candidate, Comment
def make_candidate(save=False, **kwargs):
defaults = {
'name': 'Test Candidate',
'slug': 'test',
'vendor': 'test vendor',
'device': 'test device',
'release_date': datetime.datetime(2000, 1, 1, tzinfo=datetime.timezone.utc)
}
merged = defaults | kwargs
obj = Candidate(**merged)
if save:
obj.save()
return obj
def test_message_id():
assert re.match(r'<.+@.+>', models.gen_message_id())
@pytest.mark.django_db
def test_candidate_email():
user = User.objects.create(first_name='Test', last_name='User')
candidate = make_candidate(name='Test Candidate', save=True)
email = make_candidate_email(candidate, user)
assert 'Message-ID' in email.extra_headers
assert email.subject == 'Test Candidate'
assert 'Test Candidate' in email.body
assert 'Test User' in email.body
@pytest.mark.django_db
def test_comment_knows_comment_its_replying_to():
user = User.objects.create()
candidate = make_candidate(name='Test Candidate', save=True)
first_comment = Comment.objects.create(user=user, candidate=candidate)
second_comment = Comment.objects.create(user=user, candidate=candidate)
assert second_comment._find_previous_comment() == first_comment
assert second_comment.in_reply_to() == first_comment.email_message_id
@pytest.mark.django_db
def test_comment_email():
user = User.objects.create(first_name='Test', last_name='User')
candidate = make_candidate(name='Test Candidate', save=True)
models.Comment.objects.create(candidate=candidate, user=user)
second_comment = models.Comment.objects.create(
candidate=candidate,
user=user,
message='Test message',
)
email = make_comment_email(second_comment)
assert 'Message-ID' in email.extra_headers
assert 'In-Reply-To' in email.extra_headers
assert email.subject == 'Re: Test Candidate'
assert 'Test message' in email.body
assert 'Test User' in email.body
|