forked from silviolleite/django-pwa
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
447bf17
commit 376f6e4
Showing
7 changed files
with
158 additions
and
2 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,14 @@ | ||
import os | ||
import sys | ||
|
||
import django | ||
from django.conf import settings | ||
from django.test.utils import get_runner | ||
|
||
if __name__ == "__main__": | ||
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' | ||
django.setup() | ||
TestRunner = get_runner(settings) | ||
test_runner = TestRunner() | ||
failures = test_runner.run_tests(["tests"]) | ||
sys.exit(bool(failures)) |
Empty file.
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,36 @@ | ||
|
||
SECRET_KEY = 'fake-key' | ||
INSTALLED_APPS = [ | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
"pwa", | ||
] | ||
|
||
ROOT_URLCONF = 'pwa.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': 'mydatabase', | ||
} | ||
} |
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,21 @@ | ||
from django.test import TestCase | ||
from pwa import app_settings | ||
|
||
|
||
class AppSettingsTest(TestCase): | ||
def test_has_defined(self): | ||
"""Must have the attributes defined in app_settings.py""" | ||
attributes = [ | ||
'PWA_SERVICE_WORKER_PATH', | ||
'PWA_APP_NAME', | ||
'PWA_APP_DESCRIPTION', | ||
'PWA_APP_ROOT_URL', | ||
'PWA_APP_THEME_COLOR', | ||
'PWA_APP_BACKGROUND_COLOR', | ||
'PWA_APP_DISPLAY', | ||
'PWA_APP_START_URL', | ||
'PWA_APP_ICONS' | ||
] | ||
for attr in attributes: | ||
with self.subTest(): | ||
self.assertTrue(hasattr(app_settings, attr)) |
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,45 @@ | ||
from django.test import TestCase | ||
from django.template import Context, Template | ||
|
||
|
||
class CreateMetaTemplateTagTest(TestCase): | ||
def setUp(self): | ||
context = Context({}) | ||
template_to_render = Template( | ||
'{% load pwa %}' | ||
'{% progressive_web_app_meta %}' | ||
) | ||
self.rendered_template = template_to_render.render(context) | ||
|
||
def test_has_tags(self): | ||
"""Must contains the tags in HTML""" | ||
tags = [ | ||
'<link rel="apple-touch-icon" href="/" sizes="160x160">', | ||
'<link rel="manifest" href="/manifest.json">', | ||
'<meta name="theme-color" content="#000">', | ||
'<meta name="apple-mobile-web-app-capable" content="yes">', | ||
'<meta name="apple-mobile-web-app-title" content="MyApp">', | ||
'<meta name="apple-mobile-web-app-status-bar-style" content="default">' | ||
] | ||
for text in tags: | ||
with self.subTest(): | ||
self.assertInHTML(text, self.rendered_template) | ||
|
||
def test_has_serviceworker(self): | ||
"""Must have the script tag with serviceworker registration""" | ||
contents = [ | ||
'<script type="text/javascript">', | ||
"if ('serviceWorker' in navigator) {", | ||
"navigator.serviceWorker.register('/serviceworker.js', {", | ||
"scope: '.'", | ||
"}).then(function (registration) {", | ||
"console.log('django-progressive-web-app: ServiceWorker registration successful with scope: ', registration.scope);", | ||
"}, function (err) {", | ||
"console.log('django-progressive-web-app: ServiceWorker registration failed: ', err);", | ||
"});", | ||
"</script>" | ||
] | ||
|
||
for expected in contents: | ||
with self.subTest(): | ||
self.assertIn(expected, self.rendered_template) |
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,40 @@ | ||
from django.test import TestCase | ||
from django.shortcuts import resolve_url as r | ||
|
||
|
||
class ServiceWorkerTest(TestCase): | ||
def setUp(self): | ||
self.response = self.client.get(r('serviceworker')) | ||
|
||
def test_get(self): | ||
"""GET /serviceworker.js Should return status code 200""" | ||
self.assertEqual(200, self.response.status_code) | ||
|
||
|
||
class ManifestTest(TestCase): | ||
def setUp(self): | ||
self.response = self.client.get(r('manifest'), format='json') | ||
|
||
def test_get(self): | ||
"""GET /manifest.json Should return status code 200""" | ||
self.assertEqual(self.response.status_code, 200) | ||
|
||
def test_template(self): | ||
"""Must have the template manifest.json""" | ||
self.assertTemplateUsed(self.response, 'manifest.json') | ||
|
||
def test_manifest_contains(self): | ||
"""Must be the attributes to manitesf.json""" | ||
contents = [ | ||
'"name":', | ||
'"short_name":', | ||
'"description":', | ||
'"start_url":', | ||
'"display":', | ||
'"background_color":', | ||
'"theme_color":', | ||
'"icons":', | ||
] | ||
for expected in contents: | ||
with self.subTest(): | ||
self.assertContains(self.response, expected) |