-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* reduce log noise - fixes #1985 * reactivate actually working rlink tests * add WAP webservice tests * fix WAP webservice running in proxy workers
- Loading branch information
Showing
12 changed files
with
247 additions
and
71 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
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 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,6 @@ | ||
##################################################################################### | ||
# | ||
# Copyright (c) Crossbar.io Technologies GmbH | ||
# SPDX-License-Identifier: EUPL-1.2 | ||
# | ||
##################################################################################### |
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,10 @@ | ||
<html> | ||
<title>Greeting</title> | ||
<body> | ||
<h1>Greeting</H1> | ||
<p> | ||
Hi {{ name }}! This is your personalized greeting message: | ||
</p> | ||
<strong>{{ message }}</strong> | ||
</body> | ||
</html> |
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,10 @@ | ||
<html> | ||
<title>Report</title> | ||
<body> | ||
<h1>Product Report</H1> | ||
<div>This is a product report for product id: <b>{{product_id}}</b></div> | ||
<div>Report is: <b>{{report}}</b></div> | ||
<div>For month <b>{{month}}</b> year <b>{{year}}</b> | ||
<div>Flasky: <b>{{flasky}}</b></div> | ||
</body> | ||
</html> |
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,80 @@ | ||
##################################################################################### | ||
# | ||
# Copyright (c) Crossbar.io Technologies GmbH | ||
# SPDX-License-Identifier: EUPL-1.2 | ||
# | ||
##################################################################################### | ||
|
||
import os | ||
from twisted.trial.unittest import TestCase | ||
|
||
from werkzeug.routing import Map, Rule | ||
from jinja2 import Environment, FileSystemLoader | ||
from jinja2.environment import Template | ||
|
||
from crossbar.webservice.wap import WapResource | ||
|
||
|
||
class WapTestCase(TestCase): | ||
""" | ||
Tests for :class:`crossbar.webservice.wap.WapResource`. | ||
""" | ||
|
||
_WAP1 = { | ||
"type": | ||
"wap", | ||
"templates": | ||
"../templates", | ||
"sandbox": | ||
True, | ||
"routes": [{ | ||
"path": "/greeting/<name>", | ||
"method": "GET", | ||
"call": "com.example.greeting", | ||
"render": "greeting.html" | ||
}, { | ||
"path": "/product/<int:product_id>/<report>/<int:year>/<int:month>", | ||
"method": "GET", | ||
"call": "com.example.get_product_report", | ||
"render": "product_report.html" | ||
}], | ||
"wamp": { | ||
"realm": "realm1", | ||
"authrole": "anonymous" | ||
} | ||
} | ||
|
||
def setUp(self): | ||
self._templates_dir = os.path.join(os.path.dirname(__file__), 'templates') | ||
self._jinja_env = Environment(loader=FileSystemLoader(self._templates_dir), autoescape=True) | ||
|
||
def test_map_adapter(self): | ||
# https://werkzeug.palletsprojects.com/en/2.1.x/routing/#werkzeug.routing.MapAdapter.match | ||
test_map = Map() | ||
url = '/reports/product/<int:product_id>/<report>/<int:year>/<int:month>' | ||
endpoint = 'endpoint1' | ||
rule = Rule(url, methods=['GET'], endpoint=endpoint) | ||
test_map.add(rule) | ||
test_adapter = test_map.bind('localhost', '/') | ||
|
||
test_url = '/reports/product/123/total/2016/12' | ||
test_data = {'product_id': 123, 'report': 'total', 'year': 2016, 'month': 12} | ||
|
||
_endpoint, _kwargs = test_adapter.match(test_url, method='GET', query_args={}) | ||
|
||
self.assertEqual(_endpoint, endpoint) | ||
self.assertEqual(_kwargs, test_data) | ||
|
||
def test_map_adapter_factory(self): | ||
|
||
map_adapter = WapResource._create_map_adapter(self._jinja_env, self._WAP1, 'localhost', 'reports') | ||
|
||
test_url = '/reports/product/123/total/2016/12' | ||
test_data = {'product_id': 123, 'report': 'total', 'year': 2016, 'month': 12} | ||
_endpoint, _kwargs = map_adapter.match(test_url, method='GET', query_args={}) | ||
|
||
# ('com.example.get_product_report', <Template 'product_report.html'>) != 'localhost' | ||
|
||
self.assertEqual(_endpoint[0], 'com.example.get_product_report') | ||
self.assertIsInstance(_endpoint[1], Template) | ||
self.assertEqual(_kwargs, test_data) |
Oops, something went wrong.