Fix read time when content is empty

This commit is contained in:
Gabriel Augendre 2020-12-28 10:13:35 +01:00
parent a245f09c62
commit 766255f5ae
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
3 changed files with 17 additions and 2 deletions

View file

@ -124,4 +124,7 @@ class Article(AdminUrlMixin, models.Model):
self.save()
def get_read_time(self):
return readtime.of_html(self.get_formatted_content).minutes
content = self.get_formatted_content
if content:
return readtime.of_html(content).minutes
return 0

View file

@ -10,7 +10,7 @@ from articles.models import Article, User
@pytest.fixture()
@pytest.mark.django_db
def author() -> User:
return User.objects.create_user("gaugendre")
return User.objects.create_user("gaugendre", is_staff=True, is_superuser=True)
@pytest.fixture()

View file

@ -0,0 +1,12 @@
import pytest
from django.test import Client
from django.urls import reverse
from articles.models import User
@pytest.mark.django_db
def test_can_access_add_article(client: Client, author: User):
client.force_login(author)
res = client.get(reverse("admin:articles_article_add"))
assert res.status_code == 200