2021-03-04 20:03:05 +01:00
|
|
|
import os
|
2020-12-27 20:00:41 +01:00
|
|
|
import uuid
|
|
|
|
|
2020-08-18 07:23:59 +02:00
|
|
|
import pytest
|
2021-01-05 17:59:58 +01:00
|
|
|
from django.core.management import call_command
|
2020-08-18 08:36:45 +02:00
|
|
|
from django.utils import timezone
|
2020-08-18 07:23:59 +02:00
|
|
|
|
2021-03-06 15:07:07 +01:00
|
|
|
from articles.models import Article, Tag, User
|
2020-08-18 07:23:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
@pytest.mark.django_db
|
2020-11-10 16:04:07 +01:00
|
|
|
def author() -> User:
|
2020-12-28 10:13:35 +01:00
|
|
|
return User.objects.create_user("gaugendre", is_staff=True, is_superuser=True)
|
2020-08-18 08:36:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
@pytest.mark.django_db
|
2021-03-06 15:07:07 +01:00
|
|
|
def tag() -> Tag:
|
|
|
|
return Tag.objects.create(name="This is a new tag", slug="this-new-tag")
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
@pytest.mark.django_db
|
|
|
|
def published_article(author: User, tag: Tag) -> Article:
|
|
|
|
article = Article.objects.create(
|
2020-08-24 23:49:35 +02:00
|
|
|
title="Some interesting article title",
|
2020-08-18 08:36:45 +02:00
|
|
|
status=Article.PUBLISHED,
|
|
|
|
author=author,
|
|
|
|
published_at=timezone.now(),
|
2020-08-18 10:05:09 +02:00
|
|
|
slug="some-article-slug",
|
2020-12-03 21:50:53 +01:00
|
|
|
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-08-18 08:36:45 +02:00
|
|
|
)
|
2021-03-06 15:07:07 +01:00
|
|
|
article.tags.set([tag])
|
|
|
|
return article
|
2020-08-18 08:36:45 +02:00
|
|
|
|
|
|
|
|
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)",
|
2020-12-27 20:00:41 +01:00
|
|
|
draft_key=uuid.uuid4(),
|
2020-12-03 21:15:48 +01:00
|
|
|
)
|
2021-01-05 17:59:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True, scope="session")
|
|
|
|
def collect_static():
|
|
|
|
call_command("collectstatic", "--no-input", "--clear")
|