-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ckan#4850] fix tests to match pytest style
- Loading branch information
Showing
15 changed files
with
182 additions
and
0 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
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,41 @@ | ||
# encoding: utf-8 | ||
|
||
from six import text_type | ||
import ckan.plugins as p | ||
|
||
ignore_empty = p.toolkit.get_validator('ignore_empty') | ||
|
||
DEFAULT_AUDIO_FORMATS = 'wav ogg mp3' | ||
|
||
|
||
class AudioView(p.SingletonPlugin): | ||
'''This plugin makes views of audio resources, using an <audio> tag''' | ||
|
||
p.implements(p.IConfigurer, inherit=True) | ||
p.implements(p.IResourceView, inherit=True) | ||
|
||
def update_config(self, config): | ||
p.toolkit.add_template_directory(config, 'theme/templates') | ||
self.formats = config.get( | ||
'ckan.preview.audio_formats', | ||
DEFAULT_AUDIO_FORMATS).split() | ||
|
||
def info(self): | ||
return {'name': 'audio_view', | ||
'title': p.toolkit._('Audio'), | ||
'icon': 'file-audio-o', | ||
'schema': {'audio_url': [ignore_empty, text_type]}, | ||
'iframed': False, | ||
'always_available': True, | ||
'default_title': p.toolkit._('Audio'), | ||
} | ||
|
||
def can_view(self, data_dict): | ||
return (data_dict['resource'].get('format', '').lower() | ||
in self.formats) | ||
|
||
def view_template(self, context, data_dict): | ||
return 'audio_view.html' | ||
|
||
def form_template(self, context, data_dict): | ||
return 'audio_form.html' |
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,30 @@ | ||
# encoding: utf-8 | ||
|
||
from ckan.lib.helpers import url_for | ||
from ckan.tests import factories | ||
|
||
import ckan.plugins as p | ||
|
||
import pytest | ||
|
||
@pytest.mark.ckan_config('ckan.views.default_views', '') | ||
@pytest.mark.ckan_config("ckan.plugins", "audio_view") | ||
@pytest.mark.usefixtures("clean_db", "with_plugins") | ||
def test_view_shown_on_resource_page_with_audio_url(app): | ||
|
||
dataset = factories.Dataset() | ||
|
||
resource = factories.Resource(package_id=dataset['id'], | ||
format='wav') | ||
|
||
resource_view = factories.ResourceView( | ||
resource_id=resource['id'], | ||
view_type='audio_view', | ||
audio_url='http://example.wav') | ||
|
||
url = url_for('resource.read', | ||
id=dataset['name'], resource_id=resource['id']) | ||
|
||
response = app.get(url) | ||
|
||
assert resource_view['audio_url'] in response |
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,3 @@ | ||
{% import 'macros/form.html' as form %} | ||
|
||
{{ form.input('audio_url', id='field-audio_url', label=_('Audio url'), placeholder=_('eg. http://example.com/audio.mp3 (if blank uses resource url)'), value=data.audio_url, error=errors.audio_url, classes=['control-full', 'control-large']) }} |
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,9 @@ | ||
{% set res_url = resource_view.get('audio_url') or resource.get('url') %} | ||
|
||
<audio style="margin:auto; max-height:100%; display:block; min-width: 100%;" | ||
controls src="{{ resource_view.audio_url or resource.get('url') }}"> | ||
{% trans %} | ||
Your browser does not support the <code>audio</code> element. | ||
But don't worry, you can <a href="{{ res_url }}" alt="video url">download it</a>. | ||
{% endtrans %} | ||
</audio> |
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,42 @@ | ||
# encoding: utf-8 | ||
|
||
from six import text_type | ||
import ckan.plugins as p | ||
|
||
ignore_empty = p.toolkit.get_validator('ignore_empty') | ||
|
||
DEFAULT_VIDEO_FORMATS = 'mp4 ogg webm' | ||
|
||
|
||
class VideoView(p.SingletonPlugin): | ||
'''This plugin makes views of video resources, using a <video> tag''' | ||
|
||
p.implements(p.IConfigurer, inherit=True) | ||
p.implements(p.IResourceView, inherit=True) | ||
|
||
def update_config(self, config): | ||
p.toolkit.add_template_directory(config, 'theme/templates') | ||
self.formats = config.get( | ||
'ckan.preview.video_formats', | ||
DEFAULT_VIDEO_FORMATS).split() | ||
|
||
def info(self): | ||
return {'name': 'video_view', | ||
'title': p.toolkit._('Video'), | ||
'icon': 'file-video-o', | ||
'schema': {'video_url': [ignore_empty, text_type], | ||
'poster_url': [ignore_empty, text_type]}, | ||
'iframed': False, | ||
'always_available': True, | ||
'default_title': p.toolkit._('Video'), | ||
} | ||
|
||
def can_view(self, data_dict): | ||
return (data_dict['resource'].get('format', '').lower() | ||
in self.formats) | ||
|
||
def view_template(self, context, data_dict): | ||
return 'video_view.html' | ||
|
||
def form_template(self, context, data_dict): | ||
return 'video_form.html' |
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,30 @@ | ||
# encoding: utf-8 | ||
|
||
from ckan.lib.helpers import url_for | ||
from ckan.tests import helpers, factories | ||
|
||
import ckan.plugins as p | ||
import pytest | ||
|
||
|
||
@pytest.mark.ckan_config('ckan.views.default_views', '') | ||
@pytest.mark.ckan_config("ckan.plugins", "video_view") | ||
@pytest.mark.usefixtures("clean_db", "with_plugins") | ||
def test_view_shown_on_resource_page_with_video_url(app): | ||
|
||
dataset = factories.Dataset() | ||
|
||
resource = factories.Resource(package_id=dataset['id'], | ||
format='mp4') | ||
|
||
resource_view = factories.ResourceView( | ||
resource_id=resource['id'], | ||
view_type='video_view', | ||
video_url='https://example/video.mp4') | ||
|
||
url = url_for('resource.read', | ||
id=dataset['name'], resource_id=resource['id']) | ||
|
||
response = app.get(url) | ||
|
||
assert resource_view['video_url'] in response |
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,4 @@ | ||
{% import 'macros/form.html' as form %} | ||
|
||
{{ form.input('video_url', id='field-video_url', label=_('Video url'), placeholder=_('eg. http://example.com/video.mpeg (if blank uses resource url)'), value=data.video_url, error=errors.video_url, classes=['control-full', 'control-large']) }} | ||
{{ form.input('poster_url', id='field-poster_url', label=_('Poster url'), placeholder=_('eg. http://example.com/poster.jpg'), value=data.poster_url, error=errors.poster_url, classes=['control-full', 'control-large']) }} |
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,12 @@ | ||
{% set res_url = resource_view.get('video_url') or resource.get('url') %} | ||
|
||
<video style="margin:auto; max-height:100%; width: 250px; min-width: 100%; display:block" | ||
src="{{ resource_view.video_url or resource.get('url') }}" | ||
type="{{ resource.get('format') }}" controls | ||
poster="{{ resource_view.poster_url }}"> | ||
{% trans %} | ||
Sorry, your browser doesn't support embedded videos, | ||
but don't worry, you can <a href="{{ res_url }}" alt="video url">download it</a> | ||
and watch it with your favorite video player! | ||
{% endtrans %} | ||
</video> |
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