-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Link preview fix #1416
Merged
Merged
Link preview fix #1416
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
51933a1
Added page template to blog posts
edwoodward 9915424
Added page template to news app
edwoodward 7529811
Moved page template to blog folder
edwoodward 1eb2afe
Folder to match FE URL with page template
edwoodward 8995ba2
Removed folders that did not work and put page template under news
edwoodward 9c3ae51
middleware to create link preview
edwoodward 0738778
All bots working now
edwoodward 28584d2
Added ua_parser to base.txt
edwoodward 19f4c4d
Looked up correct object based on url path
edwoodward 08ff2cd
Home page working and wrote tests
edwoodward f60e873
Removed NewsArticle use of template since it is not needed
edwoodward 9ac780b
Cleaned up template HTML
edwoodward e9c6108
Improved HTML formatting
edwoodward File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,6 +1,16 @@ | ||
import datetime | ||
import json | ||
from .functions import remove_locked_links_detail, remove_locked_links_listing, build_document_url, build_image_url | ||
|
||
from django.test import TestCase, Client | ||
from django.core.files.uploadedfile import SimpleUploadedFile | ||
from wagtail.models import Page | ||
from pages.models import HomePage, WebinarPage | ||
from books.models import BookIndex, Book | ||
from news.models import NewsIndex, NewsArticle | ||
from snippets.models import Subject, BlogContentType, BlogCollection | ||
from wagtail.documents.models import Document | ||
|
||
|
||
class TestClass(object): | ||
pass | ||
|
@@ -79,3 +89,102 @@ def test_build_document_url_none(self): | |
|
||
def test_build_image_url_none(self): | ||
self.assertEqual(build_image_url(None), None) | ||
|
||
|
||
class TestOpenGraphMiddleware(TestCase): | ||
def setUp(self): | ||
self.client = Client(HTTP_USER_AGENT='twitterbot') | ||
self.root_page = Page.objects.get(title="Root") | ||
self.homepage = HomePage(title="Hello World", | ||
slug="openstax-homepage", | ||
seo_title='OpenStax Home', | ||
search_description='Home page for OpenStax' | ||
) | ||
self.root_page.add_child(instance=self.homepage) | ||
|
||
def test_home_page_link_preview(self): | ||
response = self.client.get('/') | ||
self.assertContains(response, 'og:image') | ||
|
||
|
||
def test_book_link_preview(self): | ||
test_image = SimpleUploadedFile(name='openstax.png', | ||
content=open("oxauth/static/images/openstax.png", 'rb').read()) | ||
self.test_doc = Document.objects.create(title='Test Doc', file=test_image) | ||
book_index = BookIndex(title="Book Index", | ||
page_description="Test", | ||
dev_standard_1_description="Test", | ||
dev_standard_2_description="Test", | ||
dev_standard_3_description="Test", | ||
dev_standard_4_description="Test", | ||
) | ||
# add book index to homepage | ||
self.homepage.add_child(instance=book_index) | ||
book = Book(title="Biology 2e", | ||
slug="biology-2e", | ||
cnx_id='031da8d3-b525-429c-80cf-6c8ed997733a', | ||
description="Test Book", | ||
cover=self.test_doc, | ||
title_image=self.test_doc, | ||
publish_date=datetime.date.today(), | ||
locale=self.root_page.locale, | ||
license_name='Creative Commons Attribution License', | ||
seo_title='Biology 2e', | ||
search_description='2nd edition of Biology' | ||
) | ||
book_index.add_child(instance=book) | ||
self.client = Client(HTTP_USER_AGENT='Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)') | ||
response = self.client.get('/details/books/biology-2e') | ||
self.assertContains(response, 'og:image') | ||
|
||
def test_blog_link_preview(self): | ||
self.news_index = NewsIndex(title="News Index") | ||
self.homepage.add_child(instance=self.news_index) | ||
self.math = Subject(name="Math", page_content="Math page content.", seo_title="Math SEO Title", | ||
search_description="Math page description.") | ||
self.math.save() | ||
math_id = self.math.id | ||
self.case_study = BlogContentType(content_type='Case Study') | ||
self.case_study.save() | ||
case_study_id = self.case_study.id | ||
self.learning = BlogCollection(name='Teaching and Learning', description='this is a collection') | ||
self.learning.save() | ||
learning_id = self.learning.id | ||
self.article = NewsArticle(title="Article 1", | ||
slug="article-1", | ||
date=datetime.date.today(), | ||
heading="Sample Article", | ||
subheading="Sample Subheading", | ||
author="OpenStax", | ||
seo_title='Test Article 1', | ||
search_description='Test Article 1 description', | ||
body=json.dumps( | ||
[ | ||
{"type": "paragraph", | ||
"value": "<p>This is the body of the post</p><p>This is the second paragraph</p>"} | ||
] | ||
), | ||
article_subjects=json.dumps( | ||
[ | ||
{'type': 'subject', 'value': [ | ||
{'type': 'item', 'value': {'subject': math_id, 'featured': False}}]} | ||
] | ||
), | ||
content_types=json.dumps( | ||
[ | ||
{'type': 'content_type', 'value': [ | ||
{'type': 'item', 'value': {'content_type': case_study_id}}]} | ||
] | ||
), | ||
collections=json.dumps( | ||
[ | ||
{'type': 'collection', 'value': [ | ||
{'type': 'item', 'value': {'collection': learning_id, 'featured': False, | ||
'popular': False}}]} | ||
] | ||
)) | ||
self.news_index.add_child(instance=self.article) | ||
self.client = Client(HTTP_USER_AGENT='facebookexternalhit/1.1') | ||
response = self.client.get('/blog/article-1') | ||
self.assertContains(response, 'og:image') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice job testing! |
||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would probably be worth at least making a card to align these two slugs on BE/FE