Fix read time when content is empty
This commit is contained in:
parent
a245f09c62
commit
766255f5ae
3 changed files with 17 additions and 2 deletions
|
@ -124,4 +124,7 @@ class Article(AdminUrlMixin, models.Model):
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def get_read_time(self):
|
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
|
||||||
|
|
|
@ -10,7 +10,7 @@ from articles.models import Article, User
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def author() -> User:
|
def author() -> User:
|
||||||
return User.objects.create_user("gaugendre")
|
return User.objects.create_user("gaugendre", is_staff=True, is_superuser=True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
|
|
12
articles/tests/test_admin.py
Normal file
12
articles/tests/test_admin.py
Normal 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
|
Reference in a new issue