-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from stuartmaxwell:update-djpress
Update-djpress
- Loading branch information
Showing
4 changed files
with
223 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import pytest | ||
|
||
from django.contrib.auth.models import User | ||
|
||
from djpress.models import Category, Post | ||
|
||
|
||
@pytest.fixture | ||
def user(): | ||
return User.objects.create_user( | ||
username="testuser", | ||
password="testpass", | ||
first_name="Test", | ||
last_name="User", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def category1(): | ||
return Category.objects.create(title="Test Category1", slug="test-category1") | ||
|
||
|
||
@pytest.fixture | ||
def category2(): | ||
return Category.objects.create(title="Test Category2", slug="test-category2") | ||
|
||
|
||
@pytest.fixture | ||
def category3(): | ||
category = Category.objects.create(title="Development", slug="dev") | ||
return category | ||
|
||
|
||
@pytest.fixture | ||
def test_post1(user, category1): | ||
post = Post.objects.create( | ||
title="Test Post1", | ||
slug="test-post1", | ||
content="This is test post 1.", | ||
author=user, | ||
status="published", | ||
post_type="post", | ||
) | ||
post.categories.set([category1]) | ||
|
||
return post | ||
|
||
|
||
@pytest.fixture | ||
def test_post2(user, category2): | ||
post = Post.objects.create( | ||
title="Test Post2", | ||
slug="test-post2", | ||
content="This is test post 2.", | ||
author=user, | ||
status="published", | ||
post_type="post", | ||
) | ||
post.categories.set([category2]) | ||
return post | ||
|
||
|
||
@pytest.fixture | ||
def test_post3(user, category1): | ||
post = Post.objects.create( | ||
title="Test Post3", | ||
slug="test-post3", | ||
content="This is test post 3.", | ||
author=user, | ||
status="published", | ||
post_type="post", | ||
) | ||
|
||
return post | ||
|
||
|
||
@pytest.fixture | ||
def test_long_post1(user, settings, category1): | ||
truncate_tag = settings.DJPRESS_SETTINGS["TRUNCATE_TAG"] | ||
post = Post.post_objects.create( | ||
title="Test Long Post1", | ||
slug="test-long-post1", | ||
content=f"This is the truncated content.\n\n{truncate_tag}\n\nThis is the rest of the post.", | ||
author=user, | ||
status="published", | ||
post_type="post", | ||
) | ||
post.categories.set([category1]) | ||
return post | ||
|
||
|
||
@pytest.fixture | ||
def test_page1(user): | ||
return Post.objects.create( | ||
title="Test Page1", | ||
slug="test-page1", | ||
content="This is test page 1.", | ||
author=user, | ||
status="published", | ||
post_type="page", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def test_page2(user): | ||
return Post.objects.create( | ||
title="Test Page2", | ||
slug="test-page2", | ||
content="This is test page 2.", | ||
author=user, | ||
status="published", | ||
post_type="page", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def test_page3(user): | ||
return Post.objects.create( | ||
title="Test Page3", | ||
slug="test-page3", | ||
content="This is test page 3.", | ||
author=user, | ||
status="published", | ||
post_type="page", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def test_page4(user): | ||
return Post.objects.create( | ||
title="Test Page4", | ||
slug="test-page4", | ||
content="This is test page 4.", | ||
author=user, | ||
status="published", | ||
post_type="page", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def test_page5(user): | ||
return Post.objects.create( | ||
title="Test Page5", | ||
slug="test-page5", | ||
content="This is test page 5.", | ||
author=user, | ||
status="published", | ||
post_type="page", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,70 @@ | ||
import pytest | ||
|
||
from django.http import HttpResponse | ||
from django.test import Client | ||
import pytest | ||
from django.urls import reverse | ||
from django.utils import timezone | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_index(client: Client) -> None: | ||
def test_index(client, test_post1) -> None: | ||
"""Test index view.""" | ||
url = "/" | ||
response: HttpResponse = client.get(url) | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_archives(client, test_post1) -> None: | ||
"""Test archives views.""" | ||
test_post1.date = timezone.make_aware(timezone.datetime(2024, 6, 1)) | ||
test_post1.save() | ||
|
||
url = "/2024/" | ||
response: HttpResponse = client.get(url) | ||
assert response.status_code == 200 | ||
assert "Test Post1" in str(response.content) | ||
|
||
url = "/2024/06/" | ||
response: HttpResponse = client.get(url) | ||
assert response.status_code == 200 | ||
assert "Test Post1" in str(response.content) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_single_post(client, test_post1) -> None: | ||
"""Test single post view.""" | ||
test_post1.date = timezone.make_aware(timezone.datetime(2024, 6, 1)) | ||
test_post1.save() | ||
|
||
url = "/2024/06/test-post1/" | ||
response: HttpResponse = client.get(url) | ||
assert response.status_code == 200 | ||
assert "Test Post1" in str(response.content) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_author_view(client, test_post1): | ||
"""Test author view.""" | ||
url = "/author/testuser/" | ||
response: HttpResponse = client.get(url) | ||
assert response.status_code == 200 | ||
assert "Test Post1" in str(response.content) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_categories_vew(client, test_post1): | ||
"""Test categories view.""" | ||
url = "/category/test-category1/" | ||
response: HttpResponse = client.get(url) | ||
assert response.status_code == 200 | ||
assert "Test Post1" in str(response.content) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_single_page(client, test_page1): | ||
"""Test single page view.""" | ||
url = "/test-page1/" | ||
response: HttpResponse = client.get(url) | ||
assert response.status_code == 200 | ||
assert "Test Page1" in str(response.content) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.