Merge pull request #1727 from bookwyrm-social/feed-template-tests

HTML validation fixes
This commit is contained in:
Mouse Reeve 2021-12-29 12:42:22 -08:00 committed by GitHub
commit d89c7a3617
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 211 additions and 115 deletions

View file

@ -31,7 +31,7 @@
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<div class="is-main block" id="anchor-{{ status.id }}"> <div class="is-main block">
{% include 'snippets/status/status.html' with status=status main=True %} {% include 'snippets/status/status.html' with status=status main=True %}
</div> </div>

View file

@ -10,7 +10,12 @@
<div class="modal-background"></div> <div class="modal-background"></div>
<div class="modal-card is-fullwidth"> <div class="modal-card is-fullwidth">
<header class="modal-card-head"> <header class="modal-card-head">
<img class="image logo mr-2" src="{% if site.logo_small %}{% get_media_prefix %}{{ site.logo_small }}{% else %}{% static "images/logo-small.png" %}{% endif %}" aria-hidden="true"> <img
class="image logo mr-2"
src="{% if site.logo_small %}{% get_media_prefix %}{{ site.logo_small }}{% else %}{% static "images/logo-small.png" %}{% endif %}"
aria-hidden="true"
alt="{{ site.name }}"
>
<h1 class="modal-card-title" id="get_started_header"> <h1 class="modal-card-title" id="get_started_header">
{% blocktrans %}Welcome to {{ site_name }}!{% endblocktrans %} {% blocktrans %}Welcome to {{ site_name }}!{% endblocktrans %}
<span class="subtitle is-block"> <span class="subtitle is-block">

View file

@ -13,13 +13,26 @@
<div class="column is-two-thirds"> <div class="column is-two-thirds">
<div class="block"> <div class="block">
<label class="label" for="id_name">{% trans "Display name:" %}</label> <label class="label" for="id_name">{% trans "Display name:" %}</label>
<input type="text" name="name" maxlength="100" class="input" id="id_name" placeholder="{{ user.localname }}" value="{% if request.user.name %}{{ request.user.name }}{% endif %}"> <input
type="text"
name="name"
maxlength="100"
class="input"
id="id_name"
placeholder="{{ user.localname }}"
value="{% if request.user.name %}{{ request.user.name }}{% endif %}"
>
{% include 'snippets/form_errors.html' with errors_list=form.name.errors id="desc_name" %} {% include 'snippets/form_errors.html' with errors_list=form.name.errors id="desc_name" %}
</div> </div>
<div class="block"> <div class="block">
<label class="label" for="id_summary">{% trans "Summary:" %}</label> <label class="label" for="id_summary">{% trans "Summary:" %}</label>
<textarea name="summary" cols="None" rows="None" class="textarea" id="id_summary" placeholder="{% trans 'A little bit about you' %}">{% if request.user.summary %}{{ request.user.summary }}{% endif %}</textarea> <textarea
name="summary"
class="textarea"
id="id_summary"
placeholder="{% trans 'A little bit about you' %}"
>{% if request.user.summary %}{{ request.user.summary }}{% endif %}</textarea>
{% include 'snippets/form_errors.html' with errors_list=form.summary.errors id="desc_summary" %} {% include 'snippets/form_errors.html' with errors_list=form.summary.errors id="desc_summary" %}
</div> </div>

View file

@ -54,13 +54,13 @@
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="item" value="{{ item.id }}"> <input type="hidden" name="item" value="{{ item.id }}">
<input type="hidden" name="approved" value="true"> <input type="hidden" name="approved" value="true">
<button class="button">{% trans "Approve" %}</button> <button type="submit" class="button">{% trans "Approve" %}</button>
</form> </form>
<form class="control" method="POST" action="{% url 'list-curate' list.id %}"> <form class="control" method="POST" action="{% url 'list-curate' list.id %}">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="item" value="{{ item.id }}"> <input type="hidden" name="item" value="{{ item.id }}">
<input type="hidden" name="approved" value="false"> <input type="hidden" name="approved" value="false">
<button class="button is-danger is-light">{% trans "Discard" %}</button> <button type="submit" class="button is-danger is-light">{% trans "Discard" %}</button>
</form> </form>
</dd> </dd>
</div> </div>

View file

@ -18,24 +18,73 @@
<fieldset class="field"> <fieldset class="field">
<legend class="label">{% trans "List curation:" %}</legend> <legend class="label">{% trans "List curation:" %}</legend>
<label class="field" data-hides="list_group_selector"> <div class="field" data-hides="list_group_selector">
<input type="radio" name="curation" value="closed"{% if not list or list.curation == 'closed' %} checked{% endif %}> {% trans "Closed" %} <input
<p class="help mb-2">{% trans "Only you can add and remove books to this list" %}</p> type="radio"
</label> name="curation"
value="closed"
aria-described-by="id_curation_closed_help"
id="id_curation_closed"
{% if not list or list.curation == 'closed' %} checked{% endif %}
>
<label for="id_curation_closed">
{% trans "Closed" %}
</label>
<p class="help mb-2" id="id_curation_closed_help">
{% trans "Only you can add and remove books to this list" %}
</p>
</div>
<label class="field" data-hides="list_group_selector"> <div class="field" data-hides="list_group_selector">
<input type="radio" name="curation" value="curated"{% if list.curation == 'curated' %} checked{% endif %}> {% trans "Curated" %} <input
<p class="help mb-2">{% trans "Anyone can suggest books, subject to your approval" %}</p> type="radio"
</label> name="curation"
value="curated"
aria-described-by="id_curation_curated_help"
id="id_curation_curated"
{% if list.curation == 'curated' %} checked{% endif %}
>
<label for="id_curation_curated">
{% trans "Curated" %}
</label>
<p class="help mb-2" id="id_curation_curated_help">
{% trans "Anyone can suggest books, subject to your approval" %}
</p>
</div>
<label class="field" data-hides="list_group_selector"> <div class="field" data-hides="list_group_selector">
<input type="radio" name="curation" value="open"{% if list.curation == 'open' %} checked{% endif %}> {% trans "Open" context "curation type" %} <input
<p class="help mb-2">{% trans "Anyone can add books to this list" %}</p> type="radio"
</label> name="curation"
value="open"
aria-described-by="id_curation_open_help"
id="id_curation_open"
{% if list.curation == 'open' %} checked{% endif %}
>
<label for="id_curation_open">
{% trans "Open" context "curation type" %}
</label>
<p class="help mb-2" id="id_curation_open_help">
{% trans "Anyone can add books to this list" %}
</p>
</div>
<div class="field hidden-form">
<input
type="radio"
name="curation"
value="group"
aria-described-by="id_curation_group_help"
id="id_curation_group"
{% if list.curation == 'group' %}checked{% endif %}
>
<label for="id_curation_group">
{% trans "Group" %}
</label>
<p class="help mb-2" id="id_curation_group_help">
{% trans "Group members can add to and remove from this list" %}
</p>
<label class="field hidden-form">
<input type="radio" name="curation" value="group"{% if list.curation == 'group' %} checked{% endif %} > {% trans "Group" %}
<p class="help mb-2">{% trans "Group members can add to and remove from this list" %}</p>
<fieldset class="{% if list.curation != 'group' %}is-hidden{% endif %}" id="list_group_selector"> <fieldset class="{% if list.curation != 'group' %}is-hidden{% endif %}" id="list_group_selector">
{% if user.memberships.exists %} {% if user.memberships.exists %}
<label class="label" for="id_group" id="group">{% trans "Select Group" %}</label> <label class="label" for="id_group" id="group">{% trans "Select Group" %}</label>
@ -61,7 +110,7 @@
{% endwith %} {% endwith %}
{% endif %} {% endif %}
</fieldset> </fieldset>
</label> </div>
</fieldset> </fieldset>
</div> </div>
</div> </div>

View file

@ -56,37 +56,48 @@
<div> <div>
{{ book|book_description|to_markdown|default:""|safe|truncatewords_html:20 }} {{ book|book_description|to_markdown|default:""|safe|truncatewords_html:20 }}
</div> </div>
{% include 'snippets/shelve_button/shelve_button.html' %} {% include 'snippets/shelve_button/shelve_button.html' with book=book %}
</div> </div>
</div> </div>
{% endwith %} {% endwith %}
<div class="card-footer is-stacked-mobile has-background-white-bis is-align-items-stretch"> <div class="card-footer is-stacked-mobile has-background-white-bis is-align-items-stretch">
<div class="card-footer-item"> <div class="card-footer-item">
<div> <p>
<p>{% blocktrans with username=item.user.display_name user_path=item.user.local_path %}Added by <a href="{{ user_path }}">{{ username }}</a>{% endblocktrans %}</p> {% blocktrans trimmed with username=item.user.display_name user_path=item.user.local_path %}
</div> Added by <a href="{{ user_path }}">{{ username }}</a>
{% endblocktrans %}
</p>
</div> </div>
{% if list.user == request.user or list.group|is_member:request.user %} {% if list.user == request.user or list.group|is_member:request.user %}
<div class="card-footer-item"> <form
<form name="set-position" method="post" action="{% url 'list-set-book-position' item.id %}"> name="set-position-{{ item.id }}"
{% csrf_token %} method="post"
<div class="field has-addons mb-0"> action="{% url 'list-set-book-position' item.id %}"
<div class="control"> class="card-footer-item"
<label for="input-list-position" class="button is-transparent is-small">{% trans "List position" %}</label> >
</div> {% csrf_token %}
<div class="control"> <div class="field has-addons mb-0">
<input id="input_list_position" class="input is-small" type="number" min="1" name="position" value="{{ item.order }}"> <div class="control">
</div> <label for="input-list-position" class="button is-transparent is-small">{% trans "List position" %}</label>
<div class="control">
<button type="submit" class="button is-info is-small is-tablet">{% trans "Set" %}</button>
</div>
</div> </div>
</form> <div class="control">
</div> <input id="input_list_position_{{ item.id }}" class="input is-small" type="number" min="1" name="position" value="{{ item.order }}">
</div>
<div class="control">
<button type="submit" class="button is-info is-small is-tablet">{% trans "Set" %}</button>
</div>
</div>
</form>
{% endif %} {% endif %}
{% if list.user == request.user or list.curation == 'open' and item.user == request.user or list.group|is_member:request.user %} {% if list.user == request.user or list.curation == 'open' and item.user == request.user or list.group|is_member:request.user %}
<form name="remove-book" method="post" action="{% url 'list-remove-book' list.id %}" class="card-footer-item"> <form
name="remove-book-{{ item.id }}"
method="post"
action="{% url 'list-remove-book' list.id %}"
class="card-footer-item"
>
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="item" value="{{ item.id }}"> <input type="hidden" name="item" value="{{ item.id }}">
<button type="submit" class="button is-small is-danger">{% trans "Remove" %}</button> <button type="submit" class="button is-small is-danger">{% trans "Remove" %}</button>
@ -172,14 +183,20 @@
<form <form
class="mt-1" class="mt-1"
name="add-book" name="add-book-{{ book.id }}"
method="post" method="post"
action="{% url 'list-add-book' %}{% if query %}?q={{ query }}{% endif %}" action="{% url 'list-add-book' %}{% if query %}?q={{ query }}{% endif %}"
> >
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="book" value="{{ book.id }}"> <input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="list" value="{{ list.id }}"> <input type="hidden" name="list" value="{{ list.id }}">
<button type="submit" class="button is-small is-link">{% if list.curation == 'open' or request.user == list.user or list.group|is_member:request.user %}{% trans "Add" %}{% else %}{% trans "Suggest" %}{% endif %}</button> <button type="submit" class="button is-small is-link">
{% if list.curation == 'open' or request.user == list.user or list.group|is_member:request.user %}
{% trans "Add" %}
{% else %}
{% trans "Suggest" %}
{% endif %}
</button>
</form> </form>
</div> </div>
</div> </div>
@ -191,7 +208,16 @@
{% trans "Embed this list on a website" %} {% trans "Embed this list on a website" %}
</h2> </h2>
<div class="vertical-copy"> <div class="vertical-copy">
<textarea readonly class="textarea is-small" aria-labelledby="embed-label" data-copytext data-copytext-label="{% trans 'Copy embed code' %}" data-copytext-success="{% trans 'Copied!' %}"><iframe style="border-width:0;" id="bookwyrm_list_embed" width="400" height="600" title="{% blocktrans with list_name=list.name site_name=site.name owner=list.user.display_name %}{{ list_name }}, a list by {{owner}} on {{ site_name }}{% endblocktrans %}" src="{{ embed_url }}"></iframe></textarea> <textarea
readonly
class="textarea is-small"
aria-labelledby="embed-label"
data-copytext
data-copytext-label="{% trans 'Copy embed code' %}"
data-copytext-success="{% trans 'Copied!' %}"
>&lt;iframe style="border-width:0;" id="bookwyrm_list_embed" width="400" height="600" title="{% blocktrans trimmed with list_name=list.name site_name=site.name owner=list.user.display_name %}
{{ list_name }}, a list by {{owner}} on {{ site_name }}
{% endblocktrans %}" src="{{ embed_url }}"&gt;&lt;/iframe&gt;</textarea>
</div> </div>
</div> </div>

View file

@ -13,7 +13,7 @@
<form class="block" action="{% url 'search' %}" method="GET"> <form class="block" action="{% url 'search' %}" method="GET">
<div class="field has-addons"> <div class="field has-addons">
<div class="control"> <div class="control">
<input type="input" class="input" name="q" value="{{ query }}" aria-label="{% trans 'Search query' %}"> <input type="text" class="input" name="q" value="{{ query }}" aria-label="{% trans 'Search query' %}">
</div> </div>
<div class="control"> <div class="control">
<div class="select" aria-label="{% trans 'Search type' %}"> <div class="select" aria-label="{% trans 'Search type' %}">

View file

@ -31,35 +31,29 @@
<div class="block content"> <div class="block content">
<dl> <dl>
<div class="is-flex notification pt-1 pb-1 mb-0 {% if announcement in active_announcements %}is-success{% else %}is-danger{% endif %}"> <dt class="is-pulled-left mr-5 has-text-weight-bold">{% trans "Visible:" %}</dt>
<dt class="mr-1 has-text-weight-bold">{% trans "Visible:" %}</dt> <dd>
<dd> <span class="tag {% if announcement in active_announcements %}is-success{% else %}is-danger{% endif %}">
{% if announcement in active_announcements %} {% if announcement in active_announcements %}
{% trans "True" %} {% trans "True" %}
{% else %} {% else %}
{% trans "False" %} {% trans "False" %}
{% endif %} {% endif %}
</dd> </span>
</div> </dd>
{% if announcement.start_date %} {% if announcement.start_date %}
<div class="is-flex notificationi pt-1 pb-1 mb-0 has-background-white"> <dt class="is-pulled-left mr-5 has-text-weight-bold">{% trans "Start date:" %}</dt>
<dt class="mr-1 has-text-weight-bold">{% trans "Start date:" %}</dt> <dd>{{ announcement.start_date|naturalday }}</dd>
<dd>{{ announcement.start_date|naturalday }}</dd>
</div>
{% endif %} {% endif %}
{% if announcement.end_date %} {% if announcement.end_date %}
<div class="is-flex notification pt-1 pb-1 mb-0 has-background-white"> <dt class="is-pulled-left mr-5 has-text-weight-bold">{% trans "End date:" %}</dt>
<dt class="mr-1 has-text-weight-bold">{% trans "End date:" %}</dt> <dd>{{ announcement.end_date|naturalday }}</dd>
<dd>{{ announcement.end_date|naturalday }}</dd>
</div>
{% endif %} {% endif %}
<div class="is-flex notification pt-1 pb-1 has-background-white"> <dt class="is-pulled-left mr-5 has-text-weight-bold">{% trans "Active:" %}</dt>
<dt class="mr-1 has-text-weight-bold">{% trans "Active:" %}</dt> <dd>{{ announcement.active }}</dd>
<dd>{{ announcement.active }}</dd>
</div>
</dl> </dl>
<hr aria-hidden="true"> <hr aria-hidden="true">

View file

@ -9,7 +9,7 @@ Finish "<em>{{ book_title }}</em>"
{% endblock %} {% endblock %}
{% block modal-form-open %} {% block modal-form-open %}
<form name="finish-reading" action="{% url 'reading-status' 'finish' book.id %}" method="post" {% if not refresh %}class="submit-status"{% endif %}> <form name="finish-reading-{{ uuid }}" action="{% url 'reading-status' 'finish' book.id %}" method="post" {% if not refresh %}class="submit-status"{% endif %}>
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="id" value="{{ readthrough.id }}"> <input type="hidden" name="id" value="{{ readthrough.id }}">
<input type="hidden" name="reading_status" value="read"> <input type="hidden" name="reading_status" value="read">

View file

@ -6,7 +6,7 @@
{% endblock %} {% endblock %}
{% block modal-form-open %} {% block modal-form-open %}
<form name="reading-progress" action="{% url 'reading-status-update' book.id %}" method="POST" class="submit-status"> <form name="reading-progress-{{ uuid }}" action="{% url 'reading-status-update' book.id %}" method="POST" class="submit-status">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="id" value="{{ readthrough.id }}"> <input type="hidden" name="id" value="{{ readthrough.id }}">
{% endblock %} {% endblock %}

View file

@ -9,7 +9,7 @@ Start "<em>{{ book_title }}</em>"
{% endblock %} {% endblock %}
{% block modal-form-open %} {% block modal-form-open %}
<form name="start-reading" action="{% url 'reading-status' 'start' book.id %}" method="post" {% if not refresh %}class="submit-status"{% endif %}> <form name="start-reading-{{ uuid }}" action="{% url 'reading-status' 'start' book.id %}" method="post" {% if not refresh %}class="submit-status"{% endif %}>
<input type="hidden" name="reading_status" value="reading"> <input type="hidden" name="reading_status" value="reading">
<input type="hidden" name="shelf" value="{{ move_from }}"> <input type="hidden" name="shelf" value="{{ move_from }}">
{% csrf_token %} {% csrf_token %}

View file

@ -9,7 +9,7 @@ Want to Read "<em>{{ book_title }}</em>"
{% endblock %} {% endblock %}
{% block modal-form-open %} {% block modal-form-open %}
<form name="shelve" action="{% url 'reading-status' 'want' book.id %}" method="post" {% if not refresh %}class="submit-status"{% endif %}> <form name="want-to-read-{{ uuid }}" action="{% url 'reading-status' 'want' book.id %}" method="post" {% if not refresh %}class="submit-status"{% endif %}>
<input type="hidden" name="reading_status" value="to-read"> <input type="hidden" name="reading_status" value="to-read">
<input type="hidden" name="shelf" value="{{ move_from }}"> <input type="hidden" name="shelf" value="{{ move_from }}">
{% csrf_token %} {% csrf_token %}

View file

@ -32,7 +32,7 @@
{% elif shelf.editable %} {% elif shelf.editable %}
<form name="shelve" action="/shelve/" method="post" autocomplete="off"> <form name="shelve-{{ uuid }}-{{ shelf.identifier }}" action="/shelve/" method="post" autocomplete="off">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="book" value="{{ active_shelf.book.id }}"> <input type="hidden" name="book" value="{{ active_shelf.book.id }}">
<button class="button {{ class }}" name="shelf" type="submit" value="{{ shelf.identifier }}" {% if shelf in book.shelf_set.all %} disabled {% endif %}> <button class="button {{ class }}" name="shelf" type="submit" value="{{ shelf.identifier }}" {% if shelf in book.shelf_set.all %} disabled {% endif %}>

View file

@ -39,7 +39,7 @@
{% elif shelf.editable %} {% elif shelf.editable %}
<form name="shelve" action="/shelve/" method="post"> <form name="shelve-{{ uuid }}-{{ shelf.identifier }}" action="/shelve/" method="post">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="book" value="{{ active_shelf.book.id }}"> <input type="hidden" name="book" value="{{ active_shelf.book.id }}">
<button class="button {{ class }}" name="shelf" type="submit" value="{{ shelf.identifier }}" {% if shelf in book.shelf_set.all %} disabled {% endif %}> <button class="button {{ class }}" name="shelf" type="submit" value="{{ shelf.identifier }}" {% if shelf in book.shelf_set.all %} disabled {% endif %}>

View file

@ -15,7 +15,11 @@ def validate_html(html):
errors = "\n".join( errors = "\n".join(
e e
for e in errors.split("\n") for e in errors.split("\n")
if "&book" not in e and "id and name attribute" not in e if "&book" not in e
and "&type" not in e
and "id and name attribute" not in e
and "illegal characters found in URI" not in e
and "escaping malformed URI reference" not in e
) )
if errors: if errors:
raise Exception(errors) raise Exception(errors)

View file

@ -5,6 +5,7 @@ from django.test import TestCase
from django.test.client import RequestFactory from django.test.client import RequestFactory
from bookwyrm import forms, models, views from bookwyrm import forms, models, views
from bookwyrm.tests.validate_html import validate_html
class AnnouncementViews(TestCase): class AnnouncementViews(TestCase):
@ -38,7 +39,7 @@ class AnnouncementViews(TestCase):
result = view(request) result = view(request)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_announcements_page_empty(self): def test_announcements_page_empty(self):
@ -51,7 +52,7 @@ class AnnouncementViews(TestCase):
result = view(request) result = view(request)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_announcement_page(self): def test_announcement_page(self):
@ -68,7 +69,7 @@ class AnnouncementViews(TestCase):
result = view(request, announcement.id) result = view(request, announcement.id)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_create_announcement(self): def test_create_announcement(self):
@ -138,5 +139,5 @@ class AnnouncementViews(TestCase):
result = view(request, self.local_user.localname) result = view(request, self.local_user.localname)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)

View file

@ -4,8 +4,8 @@ from django.contrib.auth.models import AnonymousUser
from django.test import TestCase from django.test import TestCase
from django.test.client import RequestFactory from django.test.client import RequestFactory
from bookwyrm import models from bookwyrm import models, views
from bookwyrm import views from bookwyrm.tests.validate_html import validate_html
class DiscoverViews(TestCase): class DiscoverViews(TestCase):
@ -39,7 +39,7 @@ class DiscoverViews(TestCase):
result = view(request) result = view(request)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
result.render() validate_html(result.render())
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
@ -67,7 +67,7 @@ class DiscoverViews(TestCase):
result = view(request) result = view(request)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
result.render() validate_html(result.render())
def test_discover_page_logged_out(self): def test_discover_page_logged_out(self):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""

View file

@ -13,6 +13,7 @@ from django.test.client import RequestFactory
from bookwyrm import models from bookwyrm import models
from bookwyrm import views from bookwyrm import views
from bookwyrm.activitypub import ActivitypubResponse from bookwyrm.activitypub import ActivitypubResponse
from bookwyrm.tests.validate_html import validate_html
@patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream") @patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream")
@ -58,7 +59,7 @@ class FeedViews(TestCase):
request.user = self.local_user request.user = self.local_user
result = view(request, "home") result = view(request, "home")
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_status_page(self, *_): def test_status_page(self, *_):
@ -72,7 +73,7 @@ class FeedViews(TestCase):
is_api.return_value = False is_api.return_value = False
result = view(request, "mouse", status.id) result = view(request, "mouse", status.id)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
with patch("bookwyrm.views.feed.is_api_request") as is_api: with patch("bookwyrm.views.feed.is_api_request") as is_api:
@ -139,7 +140,7 @@ class FeedViews(TestCase):
is_api.return_value = False is_api.return_value = False
result = view(request, "mouse", status.id) result = view(request, "mouse", status.id)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
with patch("bookwyrm.views.feed.is_api_request") as is_api: with patch("bookwyrm.views.feed.is_api_request") as is_api:
@ -159,7 +160,7 @@ class FeedViews(TestCase):
is_api.return_value = False is_api.return_value = False
result = view(request, "mouse", status.id) result = view(request, "mouse", status.id)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
with patch("bookwyrm.views.feed.is_api_request") as is_api: with patch("bookwyrm.views.feed.is_api_request") as is_api:
@ -175,7 +176,7 @@ class FeedViews(TestCase):
request.user = self.local_user request.user = self.local_user
result = view(request) result = view(request)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_direct_messages_page_user(self, *_): def test_direct_messages_page_user(self, *_):
@ -185,7 +186,7 @@ class FeedViews(TestCase):
request.user = self.local_user request.user = self.local_user
result = view(request, "nutria") result = view(request, "nutria")
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
self.assertEqual(result.context_data["partner"], self.another_user) self.assertEqual(result.context_data["partner"], self.another_user)

View file

@ -5,6 +5,7 @@ from django.test import TestCase
from django.test.client import RequestFactory from django.test.client import RequestFactory
from bookwyrm import forms, models, views from bookwyrm import forms, models, views
from bookwyrm.tests.validate_html import validate_html
@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay")
@ -40,7 +41,7 @@ class GetStartedViews(TestCase):
result = view(request) result = view(request)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@ -72,7 +73,7 @@ class GetStartedViews(TestCase):
result = view(request) result = view(request)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_books_view_with_query(self, _): def test_books_view_with_query(self, _):
@ -84,7 +85,7 @@ class GetStartedViews(TestCase):
result = view(request) result = view(request)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@ -117,7 +118,7 @@ class GetStartedViews(TestCase):
result = view(request) result = view(request)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
@patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions") @patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions")
@ -130,5 +131,5 @@ class GetStartedViews(TestCase):
result = view(request) result = view(request)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)

View file

@ -10,6 +10,7 @@ from django.test.client import RequestFactory
from bookwyrm import models, views from bookwyrm import models, views
from bookwyrm.activitypub import ActivitypubResponse from bookwyrm.activitypub import ActivitypubResponse
from bookwyrm.tests.validate_html import validate_html
# pylint: disable=unused-argument # pylint: disable=unused-argument
class ListViews(TestCase): class ListViews(TestCase):
@ -84,14 +85,14 @@ class ListViews(TestCase):
result = view(request) result = view(request)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
request.user = self.anonymous_user request.user = self.anonymous_user
result = view(request) result = view(request)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_saved_lists_page(self): def test_saved_lists_page(self):
@ -110,7 +111,7 @@ class ListViews(TestCase):
result = view(request) result = view(request)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
self.assertEqual(result.context_data["lists"].object_list, [booklist]) self.assertEqual(result.context_data["lists"].object_list, [booklist])
@ -127,7 +128,7 @@ class ListViews(TestCase):
result = view(request) result = view(request)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
self.assertEqual(len(result.context_data["lists"].object_list), 0) self.assertEqual(len(result.context_data["lists"].object_list), 0)
@ -188,7 +189,7 @@ class ListViews(TestCase):
is_api.return_value = False is_api.return_value = False
result = view(request, self.list.id) result = view(request, self.list.id)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_list_page_sorted(self): def test_list_page_sorted(self):
@ -210,7 +211,7 @@ class ListViews(TestCase):
is_api.return_value = False is_api.return_value = False
result = view(request, self.list.id) result = view(request, self.list.id)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
request = self.factory.get("/?sort_by=title") request = self.factory.get("/?sort_by=title")
@ -219,7 +220,7 @@ class ListViews(TestCase):
is_api.return_value = False is_api.return_value = False
result = view(request, self.list.id) result = view(request, self.list.id)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
request = self.factory.get("/?sort_by=rating") request = self.factory.get("/?sort_by=rating")
@ -228,7 +229,7 @@ class ListViews(TestCase):
is_api.return_value = False is_api.return_value = False
result = view(request, self.list.id) result = view(request, self.list.id)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
request = self.factory.get("/?sort_by=sdkfh") request = self.factory.get("/?sort_by=sdkfh")
@ -237,7 +238,7 @@ class ListViews(TestCase):
is_api.return_value = False is_api.return_value = False
result = view(request, self.list.id) result = view(request, self.list.id)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_list_page_empty(self): def test_list_page_empty(self):
@ -250,7 +251,7 @@ class ListViews(TestCase):
is_api.return_value = False is_api.return_value = False
result = view(request, self.list.id) result = view(request, self.list.id)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_list_page_logged_out(self): def test_list_page_logged_out(self):
@ -271,7 +272,7 @@ class ListViews(TestCase):
is_api.return_value = False is_api.return_value = False
result = view(request, self.list.id) result = view(request, self.list.id)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_list_page_json_view(self): def test_list_page_json_view(self):
@ -355,7 +356,7 @@ class ListViews(TestCase):
result = view(request, self.list.id) result = view(request, self.list.id)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
request.user = self.anonymous_user request.user = self.anonymous_user
@ -375,7 +376,7 @@ class ListViews(TestCase):
result = view(request, self.local_user.localname) result = view(request, self.local_user.localname)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_user_lists_page_logged_out(self): def test_user_lists_page_logged_out(self):
@ -404,7 +405,7 @@ class ListViews(TestCase):
with patch("bookwyrm.views.list.is_api_request") as is_api: with patch("bookwyrm.views.list.is_api_request") as is_api:
is_api.return_value = False is_api.return_value = False
with self.assertRaises(Http404): with self.assertRaises(Http404):
result = view(request, self.list.id, "") view(request, self.list.id, "")
def test_embed_call_with_key(self): def test_embed_call_with_key(self):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
@ -427,5 +428,5 @@ class ListViews(TestCase):
result = view(request, self.list.id, embed_key) result = view(request, self.list.id, embed_key)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)

View file

@ -12,6 +12,7 @@ import responses
from bookwyrm import models, views from bookwyrm import models, views
from bookwyrm.settings import DOMAIN from bookwyrm.settings import DOMAIN
from bookwyrm.tests.validate_html import validate_html
class Views(TestCase): class Views(TestCase):
@ -62,7 +63,7 @@ class Views(TestCase):
is_api.return_value = False is_api.return_value = False
response = view(request) response = view(request)
self.assertIsInstance(response, TemplateResponse) self.assertIsInstance(response, TemplateResponse)
response.render() validate_html(response.render())
@responses.activate @responses.activate
def test_search_books(self): def test_search_books(self):
@ -89,7 +90,7 @@ class Views(TestCase):
is_api.return_value = False is_api.return_value = False
response = view(request) response = view(request)
self.assertIsInstance(response, TemplateResponse) self.assertIsInstance(response, TemplateResponse)
response.render() validate_html(response.render())
connector_results = response.context_data["results"] connector_results = response.context_data["results"]
self.assertEqual(len(connector_results), 2) self.assertEqual(len(connector_results), 2)
self.assertEqual(connector_results[0]["results"][0].title, "Test Book") self.assertEqual(connector_results[0]["results"][0].title, "Test Book")
@ -107,7 +108,7 @@ class Views(TestCase):
is_api.return_value = False is_api.return_value = False
response = view(request) response = view(request)
self.assertIsInstance(response, TemplateResponse) self.assertIsInstance(response, TemplateResponse)
response.render() validate_html(response.render())
connector_results = response.context_data["results"] connector_results = response.context_data["results"]
self.assertEqual(len(connector_results), 1) self.assertEqual(len(connector_results), 1)
self.assertEqual(connector_results[0]["results"][0].title, "Test Book") self.assertEqual(connector_results[0]["results"][0].title, "Test Book")
@ -120,7 +121,7 @@ class Views(TestCase):
response = view(request) response = view(request)
self.assertIsInstance(response, TemplateResponse) self.assertIsInstance(response, TemplateResponse)
response.render() validate_html(response.render())
self.assertEqual(response.context_data["results"][0], self.local_user) self.assertEqual(response.context_data["results"][0], self.local_user)
def test_search_users_logged_out(self): def test_search_users_logged_out(self):
@ -134,7 +135,7 @@ class Views(TestCase):
response = view(request) response = view(request)
response.render() validate_html(response.render())
self.assertFalse("results" in response.context_data) self.assertFalse("results" in response.context_data)
def test_search_lists(self): def test_search_lists(self):
@ -149,5 +150,5 @@ class Views(TestCase):
response = view(request) response = view(request)
self.assertIsInstance(response, TemplateResponse) self.assertIsInstance(response, TemplateResponse)
response.render() validate_html(response.render())
self.assertEqual(response.context_data["results"][0], booklist) self.assertEqual(response.context_data["results"][0], booklist)