Skip to content

Commit

Permalink
Merge f89710c into cccf918
Browse files Browse the repository at this point in the history
  • Loading branch information
aarranz committed Jul 18, 2018
2 parents cccf918 + f89710c commit 9cf0d3c
Show file tree
Hide file tree
Showing 37 changed files with 93 additions and 85 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ python:
env:
- CKANVERSION=2.5.3 POSTGISVERSION=2
- CKANVERSION=2.6.3 POSTGISVERSION=2
- CKANVERSION=2.7.0 POSTGISVERSION=2
- CKANVERSION=2.7.3 POSTGISVERSION=2
- CKANVERSION=2.8.0 POSTGISVERSION=2
services:
- redis-server
- postgresql
Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
recursive-include ckanext/right_time_context/fanstatic *
recursive-include ckanext/right_time_context/public *
recursive-include ckanext/right_time_context/templates *
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
CKAN ckanext-ngsiview
=====================
CKAN ckanext-right_time_context
===============================

[![Build Status](https://travis-ci.org/conwetlab/ckanext-ngsiview.svg?branch=ngsiv2)](https://travis-ci.org/conwetlab/ckanext-ngsiview)
[![Coverage Status](https://coveralls.io/repos/github/conwetlab/ckanext-ngsiview/badge.svg?branch=ngsiv2)](https://coveralls.io/github/conwetlab/ckanext-ngsiview?branch=ngsiv2)
[![Build Status](https://travis-ci.org/conwetlab/ckanext-right_time_context.svg?branch=master)](https://travis-ci.org/conwetlab/ckanext-right_time_context)
[![Coverage Status](https://coveralls.io/repos/github/conwetlab/ckanext-right_time_context/badge.svg?branch=master)](https://coveralls.io/github/conwetlab/ckanext-right_time_context?branch=master)

CKAN extension that will give you the ability to manage real-time resources provided by a FIWARE Context Broker. This extension also provides a basic view to provide a data preview to user browsing context broker resources, altough it can be combined with other plugins (e.g. the [`ckanext-wirecloud_view`](https://github.com/conwetlab/ckanext-wirecloud_view.git) one) to provide a more advanced visualization of the data provided using CKAN.

**Note**: This extension is being tested in CKAN 2.5, 2.6 and 2.7. These are
**Note**: This extension is being tested using CKAN 2.5, 2.6, 2.7 and 2.8. These are
therefore considered as the supported versions


Expand All @@ -17,21 +17,21 @@ therefore considered as the supported versions

## Installation

To install ckanext-ngsiview:
To install `ckanext-right_time_context`:

1. Activate your CKAN virtual environment, for example:

```
. /usr/lib/ckan/default/bin/activate
```

2. Install the ckanext-ngsiview Python package into your virtual environment:
2. Install the `ckanext-right_time_context` python package into your virtual environment:

```
pip install ckanext-ngsiview
pip install ckanext-right_time_context
```

3. Add `ngsiview` to the `ckan.plugins` setting in your CKAN
3. Add `right_time_context` to the `ckan.plugins` setting in your CKAN
config file (e.g. `/etc/ckan/default/production.ini`).

4. Restart CKAN. For example if you've deployed CKAN with Apache:
Expand All @@ -43,12 +43,12 @@ To install ckanext-ngsiview:

## Development Installation

To install `ckanext-ngsiview` for development, activate your CKAN virtualenv and
To install `ckanext-right_time_context` for development, activate your CKAN virtualenv and
do:

```
git clone https://github.com/conwetlab/ckanext-ngsiview.git
cd ckanext-ngsiview
git clone https://github.com/conwetlab/ckanext-right_time_context.git
cd ckanext-right_time_context
python setup.py develop
```

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# Copyright 2018 CoNWeT Lab. Univerisdad Politécnica de Madrid
# Copyright (c) 2018 Future Internet Consulting and Development Solutions S.L.
#
# This file is part of ckanext-ngsipreview.
# This file is part of ckanext-right_time_context.
#
# Ckanext-ngsiview is free software: you can redistribute it and/or
# Ckanext-right_time_context is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Ckanext-ngsiview is distributed in the hope that it will be useful,
# Ckanext-right_time_context is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
Expand Down Expand Up @@ -150,7 +150,7 @@ def proxy_ngsi_resource(self, resource_id):
base.abort(409, detail='Invalid URL.')

# Process verify configuration
verify_conf = os.environ.get('CKAN_NGSI_VERIFY_REQUESTS', toolkit.config.get('ckan.ngsi.verify_requests'))
verify_conf = os.environ.get('CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS', toolkit.config.get('ckan.right_time_context.verify_requests'))
if verify_conf is None:
verify_conf = os.environ.get('CKAN_VERIFY_REQUESTS', toolkit.config.get('ckan.verify_requests'))

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ckan.module('ngsiview',function(jQuery,_){
ckan.module('right_time_context',function(jQuery,_){
return{
options:{
i18n:{error:_('An error occurred: %(text)s %(error)s')},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ckan.module('ngsiview',function(jQuery,_){
ckan.module('right_time_context',function(jQuery,_){
return{
options:{
i18n:{error:_('An error occurred: %(text)s %(error)s')},
Expand Down
35 changes: 18 additions & 17 deletions ckanext/ngsiview/plugin.py → ckanext/right_time_context/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# Copyright 2018 CoNWeT Lab, Universidad Politécnica de Madrid
# Copyright (c) 2018 Future Internet Consulting and Development Solutions S.L.
#
# This file is part of ckanext-ngsipreview.
# This file is part of ckanext-right_time_context.
#
# Ckanext-ngsiview is free software: you can redistribute it and/or
# Ckanext-right_time_context is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Ckanext-ngsiview is distributed in the hope that it will be useful,
# Ckanext-right_time_context is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
Expand Down Expand Up @@ -55,7 +55,7 @@ class NgsiView(p.SingletonPlugin):
def before_map(self, m):
m.connect(
'/dataset/{id}/resource/{resource_id}/ngsiproxy',
controller='ckanext.ngsiview.controller:ProxyNGSIController',
controller='ckanext.right_time_context.controller:ProxyNGSIController',
action='proxy_ngsi_resource'
)
return m
Expand All @@ -76,13 +76,13 @@ def get_available_auth_methods():
return auth_options

return {
"ngsiview_get_available_auth_methods": get_available_auth_methods,
"right_time_context_get_available_auth_methods": get_available_auth_methods,
}

def get_proxified_ngsi_url(self, data_dict):
url = h.url_for(
action='proxy_ngsi_resource',
controller='ckanext.ngsiview.controller:ProxyNGSIController',
controller='ckanext.right_time_context.controller:ProxyNGSIController',
id=data_dict['package']['name'],
resource_id=data_dict['resource']['id']
)
Expand All @@ -95,20 +95,21 @@ def configure(self, config):

def update_config(self, config):
p.toolkit.add_template_directory(config, 'templates')
p.toolkit.add_resource('fanstatic', 'ngsiview')
p.toolkit.add_resource('fanstatic', 'right_time_context')
p.toolkit.add_public_directory(config, 'public')

def info(self):
return {'name': 'ngsiview',
'title': p.toolkit._('NGSI'),
'icon': 'file-text-o' if p.toolkit.check_ckan_version(min_version='2.7') else 'file-text-alt',
'default_title': p.toolkit._('NGSI'),
'default_description': 'NGSI resource',
'always_available': False,
'iframed': True,
'preview_enabled': True,
'full_page_edit': False,
}
return {
'name': 'ngsi_view',
'title': p.toolkit._('NGSI'),
'icon': 'file-text-o' if p.toolkit.check_ckan_version(min_version='2.7') else 'file-text-alt',
'default_title': p.toolkit._('NGSI'),
'default_description': 'NGSI resource',
'always_available': False,
'iframed': True,
'preview_enabled': True,
'full_page_edit': False,
}

def can_view(self, data_dict):
resource = data_dict['resource']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

{% block styles %}
{{ super() }}
{% resource 'ngsiview/css/ngsi_icons.css' %}
{% resource 'right_time_context/css/ngsi_icons.css' %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div style="" id="map" class="map" data-module="ngsiviewmap"></div>
</div>
</br>
<pre data-module="ngsiview" style="position: relative;overflow:hidden;">
<pre data-module="right_time_context" style="position: relative;overflow:hidden;">
<div class="loading">
{{ _('Loading...') }}
</div>
Expand All @@ -18,12 +18,12 @@
</script>
{% endblock %}

{% resource 'ngsiview/vendor/highlight/highlight.pack.js' %}
{% resource 'ngsiview/vendor/bootstrap/js/bootstrap.js' %}
{% resource 'ngsiview/vendor/dygraph/dygraph-combined.js' %}
{% resource 'ngsiview/view_ngsi.js' %}
{% resource 'ngsiview/vendor/bootstrap/css/bootstrap-responsive.css' %}
{% resource 'ngsiview/vendor/bootstrap/css/bootstrap.css' %}
{% resource 'ngsiview/css/ngsi.css' %}
{% resource 'right_time_context/vendor/highlight/highlight.pack.js' %}
{% resource 'right_time_context/vendor/bootstrap/js/bootstrap.js' %}
{% resource 'right_time_context/vendor/dygraph/dygraph-combined.js' %}
{% resource 'right_time_context/view_ngsi.js' %}
{% resource 'right_time_context/vendor/bootstrap/css/bootstrap-responsive.css' %}
{% resource 'right_time_context/vendor/bootstrap/css/bootstrap.css' %}
{% resource 'right_time_context/css/ngsi.css' %}

{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h3 class="ngsireg-input hidden">Data Provided</h3>
<h3 class="ngsiview-input hidden">NGSI Extra</h3>
{{ form.input('tenant', id='tenant', label=_('Tenant'), placeholder=_('Tenant'), value=data.tenant, error=errors.tenant, classes=['ngsiview-input', 'control-full', 'hidden']) }}
{{ form.input('service_path', id='service-path', label=_('Service Path'), placeholder=_('Service Path'), value=data.service_path, error=errors.service_path, classes=['ngsiview-input', 'control-full', 'hidden']) }}
{{ form.select('auth_type', label=_('Auth Type'), options=h.get_supported_auth(), selected=data.oauth_type, error=errors.auth_type, classes=['ngsiview-input', 'hidden']) }}
{{ form.select('auth_type', label=_('Auth Type'), options=h.right_time_context_get_available_auth_methods(), selected=data.auth_type, error=errors.auth_type, classes=['ngsiview-input', 'hidden']) }}
{{ form.textarea('payload', id='field-payload', label=_('Payload'), placeholder=_('JSON query'), value=data.payload, error=errors.payload, classes=['ngsiview-v1', 'hidden'])}}

<script type="text/javascript">
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

# Copyright (c) 2018 Future Internet Consulting and Development Solutions S.L.

# This file is part of ckanext-ngsiview.
# This file is part of ckanext-right_time_context.
#
# Ckanext-ngsiview is free software: you can redistribute it and/or
# Ckanext-right_time_context is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Ckanext-ngsiview is distributed in the hope that it will be useful,
# Ckanext-right_time_context is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with ckanext-ngsiview. If not, see http://www.gnu.org/licenses/.
# along with ckanext-right_time_context. If not, see http://www.gnu.org/licenses/.

import unittest

from mock import ANY, DEFAULT, patch
from parameterized import parameterized

from ckanext.ngsiview.controller import ProxyNGSIController
from ckanext.right_time_context.controller import ProxyNGSIController


class NgsiViewControllerTestCase(unittest.TestCase):
Expand Down Expand Up @@ -67,7 +67,7 @@ def _mock_response(self, req_method):
({"service_path": "/a", 'format': 'fiware-ngsi'}, {"FIWARE-ServicePath": "/a"}),
({"tenant": "a", "service_path": "/a,/b", 'format': 'fiware-ngsi'}, {"FIWARE-Service": "a", "FIWARE-ServicePath": "/a,/b"}),
])
@patch.multiple("ckanext.ngsiview.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
@patch.multiple("ckanext.right_time_context.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
def test_basic_request(self, resource, headers, base, logic, requests, toolkit, os):
resource['url'] = "http://cb.example.org/v2/entites"
logic.get_action('resource_show').return_value = resource
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_basic_request(self, resource, headers, base, logic, requests, toolkit,
'attrs': [],
}, {})
])
@patch.multiple("ckanext.ngsiview.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
@patch.multiple("ckanext.right_time_context.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
def test_registration_request(self, resource, query, headers, base, logic, requests, toolkit, os):
logic.get_action('resource_show').return_value = resource
response, body = self._mock_response(requests.post())
Expand All @@ -127,7 +127,7 @@ def test_registration_request(self, resource, query, headers, base, logic, reque
requests.post.assert_called_with(url, headers=expected_headers, json=query, stream=True, verify=True)
base.response.body_file.write.assert_called_with(body)

@patch.multiple("ckanext.ngsiview.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
@patch.multiple("ckanext.right_time_context.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
def test_invalid_expression(self, base, logic, requests, toolkit, os):
resource = {
'format': 'fiware-ngsi-registry',
Expand All @@ -149,7 +149,7 @@ def test_invalid_expression(self, base, logic, requests, toolkit, os):
self.controller.proxy_ngsi_resource("resource_id")
base.abort.assert_called_with(422, detail='The expression is not a valid one for NGSI Registration, only georel, geometry, and coords is supported')

@patch.multiple("ckanext.ngsiview.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
@patch.multiple("ckanext.right_time_context.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
def test_invalid_reg_query(self, base, logic, requests, toolkit, os):
logic.get_action('resource_show').return_value = self.REGISTRY_RESOURCE
response, body = self._mock_response(requests.post())
Expand All @@ -171,7 +171,7 @@ def test_invalid_reg_query(self, base, logic, requests, toolkit, os):
("ftp://example.com",),
("tatata:///da",),
])
@patch.multiple("ckanext.ngsiview.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
@patch.multiple("ckanext.right_time_context.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
def test_invalid_url_request(self, url, base, logic, requests, toolkit, os=DEFAULT):
resource = {
'url': url,
Expand All @@ -189,7 +189,7 @@ def test_invalid_url_request(self, url, base, logic, requests, toolkit, os=DEFAU
(True,),
(False,),
])
@patch.multiple("ckanext.ngsiview.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
@patch.multiple("ckanext.right_time_context.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
def test_auth_required_request(self, auth_configured, base, logic, requests, toolkit, os):
resource = {
'url': "http://cb.example.org/v2/entites",
Expand Down Expand Up @@ -220,7 +220,7 @@ def test_auth_required_request(self, auth_configured, base, logic, requests, too
("ConnectionError", 502),
("Timeout", 504),
])
@patch.multiple("ckanext.ngsiview.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
@patch.multiple("ckanext.right_time_context.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
def test_auth_required_request(self, exception, status_code, base, logic, requests, toolkit, os):
resource = {
'url': "http://cb.example.org/v2/entites",
Expand All @@ -240,19 +240,19 @@ def test_auth_required_request(self, exception, status_code, base, logic, reques
@parameterized.expand([
({}, {}, True),
({}, {"ckan.verify_requests": False}, False),
({}, {"ckan.ngsi.verify_requests": False, "ckan.verify_requests": True}, False),
({}, {"ckan.right_time_context.verify_requests": False, "ckan.verify_requests": True}, False),
({"CKAN_VERIFY_REQUESTS": "false"}, {"ckan.verify_requests": True}, False),
({"CKAN_NGSI_VERIFY_REQUESTS": "True"}, {"ckan.verify_requests": False}, True),
({"CKAN_NGSI_VERIFY_REQUESTS": "True"}, {"ckan.ngsi.verify_requests": False}, True),
({"CKAN_NGSI_VERIFY_REQUESTS": "true", "CKAN_VERIFY_REQUESTS": "false"}, {"ckan.verify_requests": False}, True),
({"CKAN_NGSI_VERIFY_REQUESTS": "on"}, {"ckan.verify_requests": False}, True),
({"CKAN_NGSI_VERIFY_REQUESTS": "1"}, {"ckan.verify_requests": False}, True),
({"CKAN_NGSI_VERIFY_REQUESTS": "off"}, {"ckan.verify_requests": True}, False),
({"CKAN_NGSI_VERIFY_REQUESTS": "0"}, {"ckan.verify_requests": True}, False),
({"CKAN_NGSI_VERIFY_REQUESTS": "/path"}, {"ckan.verify_requests": True}, "/path"),
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": "True"}, {"ckan.verify_requests": False}, True),
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": "True"}, {"ckan.right_time_context.verify_requests": False}, True),
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": "true", "CKAN_VERIFY_REQUESTS": "false"}, {"ckan.verify_requests": False}, True),
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": "on"}, {"ckan.verify_requests": False}, True),
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": "1"}, {"ckan.verify_requests": False}, True),
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": "off"}, {"ckan.verify_requests": True}, False),
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": "0"}, {"ckan.verify_requests": True}, False),
({"CKAN_RIGHT_TIME_CONTEXT_VERIFY_REQUESTS": "/path"}, {"ckan.verify_requests": True}, "/path"),
({"CKAN_VERIFY_REQUESTS": "/path/A/b"}, {"ckan.verify_requests": "path/2"}, "/path/A/b"),
])
@patch.multiple("ckanext.ngsiview.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
@patch.multiple("ckanext.right_time_context.controller", base=DEFAULT, logic=DEFAULT, requests=DEFAULT, toolkit=DEFAULT, os=DEFAULT)
def test_verify_requests(self, env, config, expected_value, base, logic, requests, toolkit, os):
logic.get_action('resource_show').return_value = {
'url': "https://cb.example.org/v2/entites",
Expand Down

0 comments on commit 9cf0d3c

Please sign in to comment.