-
Notifications
You must be signed in to change notification settings - Fork 2
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 #39 from thepubclub/fix/issue-36-38
- Loading branch information
Showing
2 changed files
with
95 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
from wagtail.models import Page | ||
|
||
from tests.testapp.models import QRCodePage | ||
from wagtail_qrcode.models import QRCodeMixin | ||
from wagtail_qrcode.wagtail_hooks import ( | ||
delete_document, | ||
generate_qr_code, | ||
|
@@ -32,13 +33,28 @@ def test_generate_qr_code(self): | |
|
||
generate_qr_code(request, test_page) | ||
|
||
rev = test_page.save_revision() | ||
rev.publish() | ||
|
||
self.assertEqual(test_page.qr_code_svg[:4], "<svg") | ||
self.assertEqual(test_page.qr_code_eps.id, 1) | ||
self.assertEqual(test_page.qr_code_usage, 0) | ||
|
||
rev = test_page.save_revision() | ||
def test_send_qr_code_email(self): | ||
request = RequestFactory().get("/") | ||
page = QRCodePage(title="Test Page") | ||
|
||
root_page = Page.objects.get(id=1) | ||
home_page = root_page.get_children().first() | ||
home_page.add_child(instance=page) | ||
|
||
rev = page.save_revision() | ||
rev.publish() | ||
|
||
test_page = QRCodePage.objects.get(id=page.id) | ||
|
||
generate_qr_code(request, test_page) | ||
|
||
send_qr_code_email( | ||
test_page, | ||
email="[email protected]", | ||
|
@@ -55,5 +71,68 @@ def test_generate_qr_code(self): | |
mail.outbox[0].attachments[0][0], "qr-code-{}.eps".format(test_page.id) | ||
) | ||
|
||
def test_is_qrcode_instance(self): | ||
# not inherit from QRCodeMixin | ||
page = Page(title="Test Page") | ||
|
||
home_page = Page.objects.get(id=1) | ||
home_page.add_child(instance=page) | ||
|
||
rev = page.save_revision() | ||
rev.publish() | ||
|
||
test_page = Page.objects.get(id=page.id) | ||
|
||
self.assertNotIsInstance(test_page, QRCodeMixin) | ||
|
||
# inherit from QRCodeMixin | ||
qr_code_page = QRCodePage(title="Test Page") | ||
|
||
home_page.add_child(instance=qr_code_page) | ||
|
||
rev = qr_code_page.save_revision() | ||
rev.publish() | ||
|
||
test_qr_code_page = QRCodePage.objects.get(id=qr_code_page.id) | ||
|
||
self.assertIsInstance(test_qr_code_page, QRCodeMixin) | ||
|
||
def test_delete_document(self): | ||
request = RequestFactory().get("/") | ||
page = QRCodePage(title="Test Page") | ||
|
||
root_page = Page.objects.get(id=1) | ||
home_page = root_page.get_children().first() | ||
home_page.add_child(instance=page) | ||
|
||
rev = page.save_revision() | ||
rev.publish() | ||
|
||
test_page = QRCodePage.objects.get(id=page.id) | ||
|
||
generate_qr_code(request, test_page) | ||
|
||
self.assertEqual(test_page.qr_code_eps.id, 1) | ||
|
||
delete_document(request, test_page) | ||
|
||
self.assertEqual(get_document_model().objects.count(), 0) | ||
|
||
def test_delete_document_not_qrcode_page(self): | ||
request = RequestFactory().get("/") | ||
page = Page(title="Test Page") | ||
|
||
root_page = Page.objects.get(id=1) | ||
home_page = root_page.get_children().first() | ||
home_page.add_child(instance=page) | ||
|
||
rev = page.save_revision() | ||
rev.publish() | ||
|
||
test_page = Page.objects.get(id=page.id) | ||
|
||
result = delete_document(request, test_page) | ||
|
||
# really should be None as the page does not inherit from QRCodeMixin | ||
# and the function doesn't return anything | ||
self.assertEqual(result, None) |
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