This repository has been archived on 2023-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
python-blog/articles/tests/conftest.py

57 lines
1.6 KiB
Python
Raw Normal View History

2020-08-18 07:23:59 +02:00
import pytest
from django.utils import timezone
2020-08-18 07:23:59 +02:00
from articles.models import Article, Page, User
2020-08-18 07:23:59 +02:00
@pytest.fixture()
@pytest.mark.django_db
def author() -> User:
2020-08-18 07:23:59 +02:00
return User.objects.create_user("gaugendre")
@pytest.fixture()
@pytest.mark.django_db
def published_article(author: User) -> Article:
return Article.objects.create(
2020-08-24 23:49:35 +02:00
title="Some interesting article title",
status=Article.PUBLISHED,
author=author,
published_at=timezone.now(),
2020-08-18 10:05:09 +02:00
slug="some-article-slug",
content=(
"## some article markdown\n\n"
"[an article link](https://article.com)\n"
"![an image](https://article.com)\n"
"![a referenced image][1]\n\n"
"[1]: https://example.com/image.png"
),
)
2020-12-03 21:15:48 +01:00
@pytest.fixture()
@pytest.mark.django_db
def unpublished_article(author: User) -> Article:
return Article.objects.create(
title="Some interesting article title, but sorry it is not public yet",
status=Article.DRAFT,
author=author,
published_at=None,
slug="some-draft-article-slug",
content="## some draft article markdown\n\n[a draft article link](https://article.com)",
)
@pytest.fixture()
@pytest.mark.django_db
def published_page(author: User) -> Page:
return Page.objects.create(
2020-08-24 23:49:35 +02:00
title="Some interesting page title",
status=Article.PUBLISHED,
author=author,
published_at=timezone.now(),
2020-08-18 10:05:09 +02:00
slug="some-page-slug",
content="## some page markdown\n\n[a page link](https://page.com)",
2020-11-26 11:31:33 +01:00
position=2,
)