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 #197 from sanoma/195-media-assets
Added support for media assets in Views and default templates
- Loading branch information
Showing
12 changed files
with
31,591 additions
and
64 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
Large diffs are not rendered by default.
Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,5 +1,4 @@ | ||
--process-dependency-links | ||
-e . | ||
-r test.txt | ||
|
||
pypandoc==1.4 | ||
django>=1.8.12,<1.11 |
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,67 @@ | ||
import pytest | ||
|
||
from django.forms import Form | ||
|
||
from arctic.generics import View | ||
|
||
|
||
class FormWithAssets(Form): | ||
class Media: | ||
css = { | ||
'all': ('form-common.css', 'view-common.css') | ||
} | ||
js = ('form1-1.js', 'form-common.js') | ||
|
||
|
||
class AnotherFormWithAssets(Form): | ||
class Media: | ||
css = { | ||
'all': ('form-common.css', 'form2.css') | ||
} | ||
js = ('form2-1.js', 'form-common.js') | ||
|
||
|
||
class ViewWithAssets(View): | ||
class Media: | ||
css = { | ||
'all': ('view.css', 'view-common.css') | ||
} | ||
js = ('view.js',) | ||
|
||
|
||
class ViewWithAssetsAndForms(ViewWithAssets): | ||
form1 = FormWithAssets | ||
form2 = AnotherFormWithAssets | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestViewAssets(object): | ||
""" | ||
Test media assets in views, including eventual form assets. | ||
""" | ||
|
||
def test_view_with_assets(self): | ||
view = ViewWithAssets() | ||
response = """<link href="/static/view.css" type="text/css" media="all" rel="stylesheet" /> | ||
<link href="/static/view-common.css" type="text/css" media="all" rel="stylesheet" /> | ||
<script type="text/javascript" src="/static/view.js"></script>""" # noqa | ||
|
||
assert str(view.media) == response | ||
|
||
def test_view_with_assets_and_forms(self): | ||
view = ViewWithAssetsAndForms() | ||
response = """<link href="/static/view.css" type="text/css" media="all" rel="stylesheet" /> | ||
<link href="/static/view-common.css" type="text/css" media="all" rel="stylesheet" /> | ||
<link href="/static/form-common.css" type="text/css" media="all" rel="stylesheet" /> | ||
<link href="/static/form2.css" type="text/css" media="all" rel="stylesheet" /> | ||
<script type="text/javascript" src="/static/view.js"></script> | ||
<script type="text/javascript" src="/static/form1-1.js"></script> | ||
<script type="text/javascript" src="/static/form-common.js"></script> | ||
<script type="text/javascript" src="/static/form2-1.js"></script>""" # noqa | ||
|
||
assert str(view.media) == response | ||
|
||
def test_view_without_assets(self): | ||
view = View() | ||
|
||
assert str(view.media) == '' |