Skip to content

Commit

Permalink
Improve current template tests to take into account the new required …
Browse files Browse the repository at this point in the history
…attribute. See Wirecloud#291
  • Loading branch information
aarranz authored and Alejandro Rodriguez committed Jul 24, 2017
1 parent 8b6ef80 commit 9d07705
Show file tree
Hide file tree
Showing 23 changed files with 113 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/wirecloud/commons/utils/template/parsers/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def _parse_workspace_info(self):
'name': var_name,
'label': self._get_translation_field(RDFS, 'label', param, var_name + '_label', required=True, type='vdef', variable=var_name, field='label'),
'type': self._get_field(WIRE, 'type', param),
'description': self._get_translation_field(RDFS, 'description', param, var_name + '_description', required=False, type='vdef', variable=var_name, field='description'),
'description': self._get_translation_field(DCTERMS, 'description', param, var_name + '_description', required=False, type='vdef', variable=var_name, field='description'),
'readonly': self._get_field(WIRE, 'readonly', param, required=False).lower() == 'true',
'default': self._get_field(WIRE, 'default', param, required=False),
'value': self._get_field(WIRE, 'value', param, required=False, default=None),
Expand Down
2 changes: 1 addition & 1 deletion src/wirecloud/commons/utils/template/writers/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def write_mashup_params(graph, resource_uri, template_info):
graph.add((param_node, WIRE['index'], rdflib.Literal(str(param_index))))
graph.add((param_node, RDFS['label'], rdflib.Literal(param['label'])))
graph.add((param_node, WIRE['type'], rdflib.Literal(param['type'])))
graph.add((param_node, RDFS['description'], rdflib.Literal(param['description'])))
graph.add((param_node, DCTERMS['description'], rdflib.Literal(param['description'])))

if param.get('readonly', False) is True:
graph.add((param_node, WIRE['readonly'], rdflib.Literal('true')))
Expand Down
Binary file modified src/wirecloud/platform/localcatalogue/test-data/basic_widget.wgt
Binary file not shown.
4 changes: 2 additions & 2 deletions src/wirecloud/platform/localcatalogue/test-data/template1.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dcterms:creator rdf:resource="http://creatoruri/"/>
<usdl-core:versionInfo>0.1</usdl-core:versionInfo>
<wire:hasImageUri rdf:resource="images/catalogue.png"/>
<wire:hasiPhoneImageUri rdf:resource="images/catalogue_iphone.png"/>
<wire:hasiPhoneImageUri rdf:resource="images/catalogue_smartphone.png"/>

<dcterms:license rdf:resource="http://www.apache.org/licenses/LICENSE-2.0.html" />

Expand Down Expand Up @@ -112,7 +112,7 @@
<dcterms:title>ImageURI</dcterms:title>
</foaf:Image>

<foaf:Image rdf:about="images/catalogue_iphone.png">
<foaf:Image rdf:about="images/catalogue_smartphone.png">
<dcterms:title>iPhoneImageURI</dcterms:title>
</foaf:Image>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>__MSG_displayName__</title>
<email>[email protected]</email>
<image>images/catalogue.png</image>
<smartphoneimage>images/catalogue_iphone.png</smartphoneimage>
<smartphoneimage>images/catalogue_smartphone.png</smartphoneimage>
<description>__MSG_description__</description>
<doc>doc/index.html</doc>
<license>Apache License 2.0</license>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>__MSG_displayName__</title>
<email>[email protected]</email>
<image>images/catalogue.png</image>
<smartphoneimage>images/catalogue_iphone.png</smartphoneimage>
<smartphoneimage>images/catalogue_smartphone.png</smartphoneimage>
<description>__MSG_description__</description>
<doc>doc/index.html</doc>
<license>Apache License 2.0</license>
Expand Down
4 changes: 2 additions & 2 deletions src/wirecloud/platform/localcatalogue/test-data/template2.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<dcterms:creator rdf:resource="http://creatoruri/"/>
<usdl-core:versionInfo>0.1</usdl-core:versionInfo>
<wire:hasImageUri rdf:resource="images/catalogue.png"/>
<wire:hasiPhoneImageUri rdf:resource="images/catalogue_iphone.png"/>
<wire:hasiPhoneImageUri rdf:resource="images/catalogue_smartphone.png"/>
<usdl-core:exposes rdf:resource="test.html"/>
<usdl-core:hasProvider rdf:resource="http://vendoruri/"/>

Expand Down Expand Up @@ -90,7 +90,7 @@
<dcterms:title>ImageURI</dcterms:title>
</foaf:Image>

<foaf:Image rdf:about="images/catalogue_iphone.png">
<foaf:Image rdf:about="images/catalogue_smartphone.png">
<dcterms:title>iPhoneImageURI</dcterms:title>
</foaf:Image>
</rdf:RDF>
4 changes: 2 additions & 2 deletions src/wirecloud/platform/localcatalogue/test-data/template3.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<dcterms:creator rdf:resource="http://creatoruri/"/>
<usdl-core:versionInfo>0.1</usdl-core:versionInfo>
<wire:hasImageUri rdf:resource="images/catalogue.png"/>
<wire:hasiPhoneImageUri rdf:resource="images/catalogue_iphone.png"/>
<wire:hasiPhoneImageUri rdf:resource="images/catalogue_smartphone.png"/>
<usdl-core:exposes rdf:resource="test.html"/>
<usdl-core:hasProvider rdf:resource="http://vendoruri/"/>

Expand Down Expand Up @@ -96,7 +96,7 @@
<dcterms:title>ImageURI</dcterms:title>
</foaf:Image>

<foaf:Image rdf:about="images/catalogue_iphone.png">
<foaf:Image rdf:about="images/catalogue_smartphone.png">
<dcterms:title>iPhoneImageURI</dcterms:title>
</foaf:Image>
</rdf:RDF>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
dcterms:creator <http://creatoruri/> ;
usdl-core:versionInfo "0.1" ;
wire:hasImageUri <images/catalogue.png> ;
wire:hasiPhoneImageUri <images/catalogue_iphone.png> ;
wire:hasiPhoneImageUri <images/catalogue_smartphone.png> ;
usdl-core:exposes <test.html> ;
usdl-core:hasProvider <http://vendoruri/> ;
vcard:addr _:b1 ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<details>
<email>[email protected]</email>
<image>images/catalogue.png</image>
<smartphoneimage>images/catalogue_iphone.png</smartphoneimage>
<smartphoneimage>images/catalogue_smartphone.png</smartphoneimage>
<description>__MSG_description__</description>
<authors>admin</authors>
</details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>__MSG_displayName__</title>
<email>[email protected]</email>
<image>images/catalogue.png</image>
<smartphoneimage>images/catalogue_iphone.png</smartphoneimage>
<smartphoneimage>images/catalogue_smartphone.png</smartphoneimage>
<description>__MSG_description__</description>
<authors>admin</authors>
</details>
Expand Down
4 changes: 2 additions & 2 deletions src/wirecloud/platform/localcatalogue/test-data/template5.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<dcterms:creator rdf:resource="http://creatoruri/"/>
<usdl-core:versionInfo>0.1</usdl-core:versionInfo>
<wire:hasImageUri rdf:resource="images/catalogue.png"/>
<wire:hasiPhoneImageUri rdf:resource="images/catalogue_iphone.png"/>
<wire:hasiPhoneImageUri rdf:resource="images/catalogue_smartphone.png"/>
<usdl-core:exposes rdf:resource="test.html"/>
<usdl-core:hasProvider rdf:resource="http://vendoruri/"/>

Expand Down Expand Up @@ -66,7 +66,7 @@
<dcterms:title>ImageURI</dcterms:title>
</foaf:Image>

<foaf:Image rdf:about="images/catalogue_iphone.png">
<foaf:Image rdf:about="images/catalogue_smartphone.png">
<dcterms:title>iPhoneImageURI</dcterms:title>
</foaf:Image>
</rdf:RDF>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<details>
<email>[email protected]</email>
<image>images/catalogue.png</image>
<smartphoneimage>images/catalogue_iphone.png</smartphoneimage>
<smartphoneimage>images/catalogue_smartphone.png</smartphoneimage>
<description>description</description>
<authors>admin</authors>
</details>
Expand Down
4 changes: 2 additions & 2 deletions src/wirecloud/platform/localcatalogue/test-data/template6.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<usdl-core:versionInfo>0.1</usdl-core:versionInfo>
<dcterms:creator rdf:resource="http://creatoruri/"/>
<wire:hasImageUri rdf:resource="images/catalogue.png"/>
<wire:hasiPhoneImageUri rdf:resource="images/catalogue_iphone.png"/>
<wire:hasiPhoneImageUri rdf:resource="images/catalogue_smartphone.png"/>
<usdl-core:exposes rdf:resource="test.html"/>
<usdl-core:hasProvider rdf:resource="http://vendoruri/"/>

Expand Down Expand Up @@ -66,7 +66,7 @@
<dcterms:title>ImageURI</dcterms:title>
</foaf:Image>

<foaf:Image rdf:about="images/catalogue_iphone.png">
<foaf:Image rdf:about="images/catalogue_smartphone.png">
<dcterms:title>iPhoneImageURI</dcterms:title>
</foaf:Image>
</rdf:RDF>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<details>
<email>[email protected]</email>
<image>images/catalogue.png</image>
<smartphoneimage>images/catalogue_iphone.png</smartphoneimage>
<smartphoneimage>images/catalogue_smartphone.png</smartphoneimage>
<description>description</description>
<authors>admin</authors>
</details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<details>
<email>[email protected]</email>
<image>images/catalogue.png</image>
<smartphoneimage>images/catalogue_iphone.png</smartphoneimage>
<smartphoneimage>images/catalogue_smartphone.png</smartphoneimage>
<description>description</description>
<authors>admin</authors>
</details>
Expand Down
4 changes: 2 additions & 2 deletions src/wirecloud/platform/localcatalogue/test-data/template8.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dcterms:creator rdf:resource="http://creatoruri/"/>
<usdl-core:versionInfo>0.1</usdl-core:versionInfo>
<wire:hasImageUri rdf:resource="images/catalogue.png"/>
<wire:hasiPhoneImageUri rdf:resource="images/catalogue_iphone.png"/>
<wire:hasiPhoneImageUri rdf:resource="images/catalogue_smartphone.png"/>

<usdl-core:utilizedResource rdf:resource="test.html"/>
<usdl-core:hasProvider rdf:resource="http://vendoruri/"/>
Expand Down Expand Up @@ -114,7 +114,7 @@
<dcterms:title>ImageURI</dcterms:title>
</foaf:Image>

<foaf:Image rdf:about="images/catalogue_iphone.png">
<foaf:Image rdf:about="images/catalogue_smartphone.png">
<dcterms:title>iPhoneImageURI</dcterms:title>
</foaf:Image>
</rdf:RDF>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<details>
<email>[email protected]</email>
<image>images/catalogue.png</image>
<smartphoneimage>images/catalogue_iphone.png</smartphoneimage>
<smartphoneimage>images/catalogue_smartphone.png</smartphoneimage>
<description>__MSG_description__</description>
<authors>admin</authors>
</details>
Expand Down
67 changes: 54 additions & 13 deletions src/wirecloud/platform/localcatalogue/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def check_basic_widget_info(self, resource):
self.assertEqual(data['version'], '0.1')
self.assertEqual(data['description'], 'Test Widget description')
self.assertEqual(data['image'], 'images/catalogue.png')
self.assertEqual(data['smartphoneimage'], 'images/catalogue_iphone.png')
self.assertEqual(data['smartphoneimage'], 'images/catalogue_smartphone.png')
self.assertEqual(data['doc'], 'doc/index.html')
self.assertEqual(data['license'], 'Apache License 2.0')
self.assertEqual(data['licenseurl'], 'http://www.apache.org/licenses/LICENSE-2.0.html')
Expand All @@ -112,7 +112,21 @@ def check_basic_widget_info(self, resource):
self.assertEqual(data['properties'], [{'default': '', 'secure': False, 'name': 'prop', 'label': 'Property label', 'type': 'text', 'description': '', 'multiuser': False}])

self.assertEqual(len(data['preferences']), 1)
self.assertEqual(data['preferences'], [{'default': 'value', 'secure': False, 'name': 'pref', 'label': 'Preference label', 'type': 'list', 'options': [{'value': '1', 'label': 'Option name'}], 'readonly': False, 'description': 'Preference description', 'value': None, 'multiuser': False}])
self.assertEqual(data['preferences'], [
{
'default': 'value',
'secure': False,
'name': 'pref',
'label': 'Preference label',
'type': 'list',
'options': [{'value': '1', 'label': 'Option name'}],
'readonly': False,
'description': 'Preference description',
'value': None,
'multiuser': False,
'required': False,
}
])

self.assertEqual(len(data['wiring']['inputs']), 1)
self.assertEqual(data['wiring']['inputs'], [{'name': 'slot', 'label': 'Slot label', 'type': 'text', 'description': '', 'friendcode': 'test_friend_code', 'actionlabel': ''}])
Expand All @@ -137,15 +151,15 @@ def test_widget_with_minimal_info(self):

def test_basic_widget_creation(self):

file_contents = self.build_simple_wgt('template1.xml', other_files=('images/catalogue.png', 'images/catalogue_iphone.png', 'doc/index.html'))
file_contents = self.build_simple_wgt('template1.xml', other_files=('doc/index.html',))
added, resource = install_resource_to_user(self.user, file_contents=file_contents)

self.assertTrue(added)
self.check_basic_widget_info(resource)

def test_basic_widget_creation_from_rdf(self):

file_contents = self.build_simple_wgt('template1.rdf', other_files=('images/catalogue.png', 'images/catalogue_iphone.png', 'doc/index.html'))
file_contents = self.build_simple_wgt('template1.rdf', other_files=('doc/index.html',))
added, resource = install_resource_to_user(self.user, file_contents=file_contents)

self.assertTrue(added)
Expand Down Expand Up @@ -194,7 +208,7 @@ def test_widget_code_cache(self):
client.login(username='test', password='test')
widget_code_path = {'vendor': 'Wirecloud', 'name': 'test', 'version': '0.1', 'file_path': 'index.html'}

file_contents = self.build_simple_wgt('template1.xml', other_files=('images/catalogue.png', 'images/catalogue_iphone.png', 'doc/index.html'))
file_contents = self.build_simple_wgt('template1.xml', other_files=('doc/index.html',))
added, resource = install_resource_to_user(self.user, file_contents=file_contents)
self.assertTrue(added)
resource_pk = resource.pk
Expand All @@ -211,7 +225,7 @@ def test_widget_code_cache(self):
self.assertRaises(CatalogueResource.DoesNotExist, CatalogueResource.objects.get, pk=resource_pk)

# Use a different xhtml code
file_contents = self.build_simple_wgt('template1.xml', b'code', other_files=('images/catalogue.png', 'images/catalogue_iphone.png', 'doc/index.html'))
file_contents = self.build_simple_wgt('template1.xml', b'code', other_files=('doc/index.html',))
resource = install_resource_to_user(self.user, file_contents=file_contents)

response = client.get(reverse('wirecloud.showcase_media', kwargs=widget_code_path) + '?entrypoint=true')
Expand All @@ -226,7 +240,7 @@ def test_install_resource_requires_wgt_instance(self):

def test_install_resource_to_group(self):

wgt_file = self.build_simple_wgt('template1.xml', b'code', other_files=('images/catalogue.png', 'images/catalogue_iphone.png', 'doc/index.html'))
wgt_file = self.build_simple_wgt('template1.xml', b'code', other_files=('doc/index.html',))

added, resource = install_resource_to_group(self.group, file_contents=wgt_file)
self.assertTrue(added)
Expand Down Expand Up @@ -263,7 +277,7 @@ def test_install_resource_to_group_duplicated(self):

def test_install_resource_to_all_users(self):

wgt_file = self.build_simple_wgt('template1.xml', b'code', other_files=('images/catalogue.png', 'images/catalogue_iphone.png', 'doc/index.html'))
wgt_file = self.build_simple_wgt('template1.xml', b'code', other_files=('doc/index.html',))

added, resource = install_resource_to_all_users(file_contents=wgt_file)
self.assertTrue(added)
Expand All @@ -273,7 +287,7 @@ def test_install_resource_to_all_users(self):

def test_fix_dev_version(self):

wgt_file = self.build_simple_wgt('template11.xml', b'code', other_files=('images/catalogue.png', 'images/catalogue_iphone.png', 'doc/index.html'))
wgt_file = self.build_simple_wgt('template11.xml', b'code', other_files=('doc/index.html',))
original_template = wgt_file.get_template()
original_version = TemplateParser(original_template).get_resource_info()['version']

Expand Down Expand Up @@ -311,7 +325,7 @@ def test_widget_with_notused_translation_indexes(self):

def test_template_translations(self):

file_contents = self.build_simple_wgt('template1.xml', other_files=('images/catalogue.png', 'images/catalogue_iphone.png', 'doc/index.html'))
file_contents = self.build_simple_wgt('template1.xml', other_files=('doc/index.html',))

added, resource = install_resource_to_user(self.user, file_contents=file_contents)

Expand All @@ -324,14 +338,28 @@ def test_template_translations(self):
self.assertEqual(data['title'], 'Widget de prueba')
self.assertEqual(data['description'], 'Descripción del Widget de pruebas')
self.assertEqual(data['image'], 'images/catalogue.png')
self.assertEqual(data['smartphoneimage'], 'images/catalogue_iphone.png')
self.assertEqual(data['smartphoneimage'], 'images/catalogue_smartphone.png')
self.assertEqual(data['doc'], 'doc/index.html')

self.assertEqual(len(data['properties']), 1)
self.assertEqual(data['properties'], [{'default': '', 'secure': False, 'name': 'prop', 'label': 'Etiqueta de la propiedad', 'type': 'text', 'description': '', 'multiuser': False}])

self.assertEqual(len(data['preferences']), 1)
self.assertEqual(data['preferences'], [{'default': 'value', 'secure': False, 'name': 'pref', 'label': 'Etiqueta de la preferencia', 'type': 'list', 'options': [{'value': '1', 'label': 'Nombre de la opción'}], 'readonly': False, 'description': 'Descripción de la preferencia', 'value': None, 'multiuser': False}])
self.assertEqual(data['preferences'], [
{
'default': 'value',
'secure': False,
'name': 'pref',
'label': 'Etiqueta de la preferencia',
'type': 'list',
'options': [{'value': '1', 'label': 'Nombre de la opción'}],
'readonly': False,
'description': 'Descripción de la preferencia',
'value': None,
'multiuser': False,
'required': False,
}
])

self.assertEqual(len(data['wiring']['inputs']), 1)
self.assertEqual(data['wiring']['inputs'], [{'name': 'slot', 'label': 'Etiqueta del endpoint de entrada', 'type': 'text', 'description': '', 'friendcode': 'test_friend_code', 'actionlabel': ''}])
Expand All @@ -353,7 +381,20 @@ def test_repeated_translation_indexes(self):
self.assertEqual(data['properties'], [{'default': '', 'secure': False, 'name': 'prop', 'label': 'Label', 'type': 'text', 'description': '', 'multiuser': False}])

self.assertEqual(len(data['preferences']), 1)
self.assertEqual(data['preferences'], [{'default': 'value', 'secure': False, 'name': 'pref', 'label': 'Label', 'readonly': False, 'type': 'text', 'description': 'Preference description', 'value': None, 'multiuser': False}])
self.assertEqual(data['preferences'], [
{
'default': 'value',
'secure': False,
'name': 'pref',
'label': 'Label',
'type': 'text',
'readonly': False,
'description': 'Preference description',
'value': None,
'multiuser': False,
'required': False,
}
])

self.assertEqual(len(data['wiring']['inputs']), 1)
self.assertEqual(data['wiring']['inputs'], [{'name': 'slot', 'label': 'Label', 'type': 'text', 'description': '', 'friendcode': 'test_friend_code', 'actionlabel': ''}])
Expand Down
3 changes: 2 additions & 1 deletion src/wirecloud/platform/workspace/mashupTemplateParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ def fillWorkspaceUsingTemplate(workspace, template):
'inheritable': False,
'label': param.get('label'),
'type': param.get('type'),
'required': param.get('required')
'description': param.get('description'),
'required': param.get('required'),
})

for tab_entry in mashup_description['tabs']:
Expand Down
13 changes: 13 additions & 0 deletions src/wirecloud/platform/workspace/test-data/wt5.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,22 @@

<wire-m:hasMashupParam>
<wire-m:MashupParam>
<wire:index>0</wire:index>
<dcterms:title>param</dcterms:title>
<wire:type>text</wire:type>
<rdfs:label>Parameter</rdfs:label>
<dcterms:description>Parameter description</dcterms:description>
</wire-m:MashupParam>
</wire-m:hasMashupParam>

<wire-m:hasMashupParam>
<wire-m:MashupParam>
<wire:index>1</wire:index>
<dcterms:title>optional_param</dcterms:title>
<wire:type>number</wire:type>
<rdfs:label>Optional Parameter</rdfs:label>
<dcterms:description>Parameter description</dcterms:description>
<wire:required>Parameter description</wire:required>
</wire-m:MashupParam>
</wire-m:hasMashupParam>

Expand Down
Loading

0 comments on commit 9d07705

Please sign in to comment.