Skip to content

Commit

Permalink
Merge pull request #64 from ratsclub/main
Browse files Browse the repository at this point in the history
change feed urls to follow custom domain if exists
  • Loading branch information
sirodoht authored Jul 17, 2024
2 parents 0cd204a + 4d44ac1 commit b11e6a7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def is_published(self):

def get_absolute_url(self):
path = reverse("post_detail", kwargs={"slug": self.slug})
return f"//{self.owner.username}.{settings.CANONICAL_HOST}{path}"
return f"//{self.owner.blog_url}{path}"

def get_proper_url(self):
"""Returns custom domain URL if custom_domain exists, else subdomain URL."""
Expand Down
5 changes: 2 additions & 3 deletions main/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from datetime import date

from django.conf import settings
from django.test import TestCase
from django.urls import reverse

Expand Down Expand Up @@ -675,7 +674,7 @@ def test_posts_get(self):
"slug": "hello-world",
"body": "## Hey\n\nHey world.",
"published_at": "2020-01-01",
"url": f"{util.get_protocol()}//{self.user.username}.{settings.CANONICAL_HOST}/blog/hello-world/",
"url": f"{util.get_protocol()}//{self.user.blog_url}/blog/hello-world/",
},
post_list,
)
Expand All @@ -685,7 +684,7 @@ def test_posts_get(self):
"slug": "bye-world",
"body": "## Bye\n\nBye world.",
"published_at": "2020-09-14",
"url": f"{util.get_protocol()}//{self.user.username}.{settings.CANONICAL_HOST}/blog/bye-world/",
"url": f"{util.get_protocol()}//{self.user.blog_url}/blog/bye-world/",
},
post_list,
)
Expand Down
20 changes: 20 additions & 0 deletions main/tests/test_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ def test_rss_feed(self):
f"//{self.user.username}.{settings.CANONICAL_HOST}/blog/{self.data['slug']}/</link>",
)

def test_rss_feed_with_custom_domain(self):
self.user.custom_domain = "mataroa-blog.com"
self.user.save()

response = self.client.get(
reverse("rss_feed"),
HTTP_HOST=self.user.custom_domain,
)

self.assertEqual(response.status_code, 200)
self.assertEqual(response["Content-Type"], "application/rss+xml; charset=utf-8")
self.assertContains(response, self.data["title"])
self.assertContains(response, self.data["slug"])
self.assertContains(response, self.data["body"])
self.assertContains(
response,
f"//{self.user.custom_domain}/blog/{self.data['slug']}/</link>",
)



class RSSFeedDraftsTestCase(TestCase):
"""Tests draft posts do not appear in the RSS feed."""
Expand Down

0 comments on commit b11e6a7

Please sign in to comment.