fix blog announcements and update tests #21
|
@ -155,6 +155,7 @@ class Tag(admin.ModelAdmin):
|
|||
list_display = ("name",)
|
||||
search_fields = ["name"]
|
||||
|
||||
|
||||
@admin.register(models.Event)
|
||||
class Event(admin.ModelAdmin):
|
||||
"""display settings for conferences"""
|
||||
|
|
|
@ -132,13 +132,9 @@ class Command(BaseCommand):
|
|||
open_cfps = ""
|
||||
for instance in cfps:
|
||||
c_date = instance.closing_date
|
||||
title_string = (
|
||||
f"<h4><a href='{instance.event.url}'>{instance.event.name} - {instance.name}</a></h4>"
|
||||
)
|
||||
title_string = f"<h4><a href='{instance.event.url}'>{instance.event.name} - {instance.name}</a></h4>"
|
||||
dates_string = f"<p><strong>Closes:</strong><em>{c_date:%a} {c_date.day} {c_date:%B}</em></p>"
|
||||
description_string = (
|
||||
f"<p>{instance.details}</p><p style='margin-bottom:24px;'>{instance.event.description}</p>"
|
||||
)
|
||||
description_string = f"<p>{instance.details}</p><p style='margin-bottom:24px;'>{instance.event.description}</p>"
|
||||
|
||||
string_list = [title_string, dates_string, description_string]
|
||||
string = "".join(string_list)
|
||||
|
|
|
@ -79,8 +79,7 @@ class Blog(BlogData):
|
|||
author = ""
|
||||
|
||||
category = Category(self.category).label
|
||||
status = f"{self.title}{author} has been added to Aus GLAMR! \
|
||||
\n\nIt's about {category}\n\n{self.url}"
|
||||
status = f"{self.title}{author} has been added to Aus GLAMR! \n\nIt's about {category}\n\n{self.url}"
|
||||
|
||||
Announcement.objects.create(status=status)
|
||||
self.announced = True
|
||||
|
|
|
@ -15,10 +15,19 @@ class BlogTestCase(TestCase):
|
|||
def setUp(self):
|
||||
"""set up test blog"""
|
||||
self.blog = models.Blog.objects.create(
|
||||
title="mya awesome blog",
|
||||
title="my awesome blog",
|
||||
url="https://test.com",
|
||||
feed="https://test.com/feed.xml",
|
||||
category="LIB",
|
||||
author_name="Hugh",
|
||||
)
|
||||
|
||||
self.blog_no_author = models.Blog.objects.create(
|
||||
title="my awesome archives",
|
||||
url="https://test2.com",
|
||||
feed="https://test2.com/feed.xml",
|
||||
category="ARC",
|
||||
author_name="",
|
||||
)
|
||||
|
||||
def test_get_absolute_url(self):
|
||||
|
@ -46,6 +55,22 @@ class BlogTestCase(TestCase):
|
|||
self.blog.set_failing()
|
||||
self.assertEqual(self.blog.failing, True)
|
||||
|
||||
def test_announce_blog(self):
|
||||
"""test announcing the blog"""
|
||||
|
||||
self.blog.announce()
|
||||
status = f"my awesome blog by Hugh has been added to Aus GLAMR! \n\nIt's about Libraries\n\nhttps://test.com"
|
||||
announcement = models.Announcement.objects.first()
|
||||
self.assertEqual(status, announcement.status)
|
||||
|
||||
def test_announce_blog_no_author(self):
|
||||
"""test announcing the blog with a blank blog author name"""
|
||||
|
||||
self.blog_no_author.announce()
|
||||
status = f"my awesome archives has been added to Aus GLAMR! \n\nIt's about Archives\n\nhttps://test2.com"
|
||||
announcement = models.Announcement.objects.first()
|
||||
self.assertEqual(status, announcement.status)
|
||||
|
||||
def test_announce_article(self):
|
||||
"""announcing a blog article"""
|
||||
|
||||
|
@ -59,7 +84,7 @@ class BlogTestCase(TestCase):
|
|||
)
|
||||
|
||||
article.announce()
|
||||
status = f"My article (Hugh on mya awesome blog)\n\nhttps://example.blog/1"
|
||||
status = f"My article (Hugh on my awesome blog)\n\nhttps://example.blog/1"
|
||||
self.assertTrue(models.Announcement.objects.filter(status=status).exists())
|
||||
|
||||
|
||||
|
|
|
@ -70,7 +70,10 @@ class UtilityTests(TestCase):
|
|||
self.assertEqual(data["description"], "A short summary of my blog")
|
||||
|
||||
def test_get_blog_info_no_feed(self):
|
||||
"""test get blog info"""
|
||||
"""
|
||||
test get blog info
|
||||
note get_blog_info only checks <head>, not rss feed
|
||||
"""
|
||||
|
||||
with open(
|
||||
pathlib.Path(__file__).parent.joinpath("data/example.html"),
|
||||
|
@ -152,7 +155,7 @@ class UtilityTests(TestCase):
|
|||
data = utilities.get_blog_info("http://test.test")
|
||||
|
||||
self.assertEqual(data["title"], "My test website with an RSS feed")
|
||||
self.assertEqual(data["author_name"], "Hugh Rundle")
|
||||
self.assertEqual(data["author_name"], "")
|
||||
self.assertEqual(data["description"], "A short summary of my blog")
|
||||
|
||||
def test_get_blog_info_with_incomplete_head_and_partial_feed(self):
|
||||
|
@ -171,7 +174,7 @@ class UtilityTests(TestCase):
|
|||
data = utilities.get_blog_info("http://test.test")
|
||||
|
||||
self.assertEqual(data["title"], "My test website with an RSS feed")
|
||||
self.assertEqual(data["author_name"], None)
|
||||
self.assertEqual(data["author_name"], "")
|
||||
self.assertEqual(data["description"], None)
|
||||
|
||||
def test_get_webfinger_subscribe_uri(self):
|
||||
|
|
|
@ -222,6 +222,7 @@ class PublicTests(TestCase):
|
|||
form.data["from_email"] = "example@example.mail"
|
||||
form.data["subject"] = "Hello"
|
||||
form.data["message"] = "Hi there"
|
||||
form.data["bot_check"] = "books"
|
||||
|
||||
request = self.factory.post("contact/", form.data)
|
||||
request.user = AnonymousUser()
|
||||
|
@ -234,6 +235,24 @@ class PublicTests(TestCase):
|
|||
# Verify that the subject of the first message is correct.
|
||||
self.assertEqual(mail.outbox[0].subject, "Message via Aus GLAMR: Hello")
|
||||
|
||||
def test_contact_from_bot(self):
|
||||
"""post message"""
|
||||
|
||||
view = views.Contact.as_view()
|
||||
form = forms.ContactForm()
|
||||
form.data["from_email"] = "example@example.mail"
|
||||
form.data["subject"] = "Hello"
|
||||
form.data["message"] = "Hi there"
|
||||
form.data["bot_check"] = "i am a stupid bot"
|
||||
|
||||
request = self.factory.post("contact/", form.data)
|
||||
request.user = AnonymousUser()
|
||||
|
||||
view(request)
|
||||
|
||||
# Test that one message has been sent.
|
||||
self.assertEqual(len(mail.outbox), 0)
|
||||
|
||||
def test_search(self):
|
||||
"""post search query"""
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import re
|
|||
|
||||
from bs4 import BeautifulSoup
|
||||
import feedparser
|
||||
import logging
|
||||
import requests
|
||||
|
||||
from django.conf import settings
|
||||
|
@ -65,17 +66,21 @@ def get_blog_info(url):
|
|||
) # use the title from the feed
|
||||
|
||||
blog_info["description"] = description or blog_info.get("description", "")
|
||||
blog_info["author_name"] = blog_info.get("author", author)
|
||||
|
||||
else:
|
||||
return False # if there is no feed info we need to put the onus back on the user to fill in the data
|
||||
|
||||
normalised_author = ""
|
||||
if author:
|
||||
normalised_author = author.replace("(noreply@blogger.com)", "")
|
||||
normalised_author = blog_info["author_name"] or None
|
||||
if normalised_author:
|
||||
normalised_author = normalised_author.replace("(noreply@blogger.com)", "")
|
||||
if normalised_author.strip() == "Unknown":
|
||||
normalised_author = ""
|
||||
|
||||
blog_info["author_name"] = normalised_author
|
||||
else:
|
||||
normalised_author = ""
|
||||
|
||||
blog_info["author_name"] = normalised_author
|
||||
|
||||
return blog_info
|
||||
|
||||
|
|
Loading…
Reference in a new issue