Skip to content

Commit

Permalink
Add icon to tool config xml (#57)
Browse files Browse the repository at this point in the history
* Add .pytest_cache directory to .gitignore
* Add optional blti:icon parameter to ToolConfiguration xml generator
* Add optional blti:icon tag to ToolConfig tests
* Update tests to cover icon and cartridge_icon parameters
  • Loading branch information
Petar Nikolovski authored and ryanhiebert committed Jun 19, 2018
1 parent 404fba5 commit 280d3ff
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ venv

# pytest
.cache
.pytest_cache

# Coverage
.coverage*
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ configuration URL when registering your app with the LTI consumer.
description = app_description
)
# or you may need some additional LTI parameters
lti_tool_config.cartridge_bundle = 'BLTI001_Bundle'
lti_tool_config.cartridge_icon = 'BLTI001_Icon'
lti_tool_config.icon = 'http://www.example.com/icon.png'
return HttpResponse(lti_tool_config.to_xml(), content_type='text/xml')
Expand Down
4 changes: 4 additions & 0 deletions src/lti/tool_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ def to_xml(self, opts=defaultdict(lambda: None)):
option = etree.SubElement(root, '{%s}%s' % (NSMAP['blti'], key))
option.text = getattr(self, key)

if getattr(self, 'icon'):
option = etree.SubElement(root, '{%s}%s' % (NSMAP['blti'], 'icon'))
option.text = getattr(self, 'icon')

vendor_keys = ['name', 'code', 'description', 'url']
if any('vendor_' + key for key in vendor_keys) or\
self.vendor_contact_email:
Expand Down
28 changes: 26 additions & 2 deletions tests/test_tool_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@
</cartridge_basiclti_link>
'''

CC_LTI_OPTIONAL_PARAMS_XML = b'''<?xml version="1.0" encoding="UTF-8"?>
<cartridge_basiclti_link xmlns:blti="http://www.imsglobal.org/xsd/imsbasiclti_v1p0" xmlns:lticm="http://www.imsglobal.org/xsd/imslticm_v1p0" xmlns:lticp="http://www.imsglobal.org/xsd/imslticp_v1p0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.imsglobal.org/xsd/imslticc_v1p0" xsi:schemaLocation="http://www.imsglobal.org/xsd/imslticc_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticc_v1p0.xsd http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0p1.xsd http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd">
<blti:title>Test config</blti:title>
<blti:description/>
<blti:launch_url>http://www.example.com</blti:launch_url>
<blti:secure_launch_url>http://www.example.com</blti:secure_launch_url>
<blti:icon>http://wil.to/_/beardslap.gif</blti:icon>
<blti:vendor/>
<cartridge_icon identifierref="BLTI001_Icon"/>
</cartridge_basiclti_link>
'''

def normalize_xml(xml_str):
parser = etree.XMLParser(remove_blank_text=True)
root = etree.XML(xml_str, parser)
Expand All @@ -90,7 +102,6 @@ def test_generate_xml(self):
custom_params = {"custom1": "customval1"})
config.description ='Description of boringness'
config.launch_url = 'http://www.example.com/lti'
config.icon = 'http://wil.to/_/beardslap.gif'
config.vendor_code = 'test'
config.vendor_name = 'test.tool'
config.vendor_description = 'We test things'
Expand Down Expand Up @@ -119,7 +130,6 @@ def test_allow_suboptions(self):
custom_params = {"custom1": "customval1"})
config.description ='Description of boringness'
config.launch_url = 'http://www.example.com/lti'
config.icon = 'http://wil.to/_/beardslap.gif'
config.vendor_code = 'test'
config.vendor_name = 'test.tool'
config.vendor_description = 'We test things'
Expand Down Expand Up @@ -147,6 +157,20 @@ def test_allow_suboptions(self):
got = normalize_xml(config.to_xml())
self.assertEqual(got, correct)

def test_optional_config_parameters(self):
'''
Should contain cartridge_icon, and blti:icon.
'''
config = ToolConfig(title = "Test config",
launch_url = "http://www.example.com",
secure_launch_url = "http://www.example.com")
config.icon = 'http://wil.to/_/beardslap.gif'
config.cartridge_icon = 'BLTI001_Icon'

correct = normalize_xml(CC_LTI_OPTIONAL_PARAMS_XML)
got = normalize_xml(config.to_xml())
self.assertEqual(got, correct)

def test_read_xml_config(self):
'''
Should read an XML config.
Expand Down

0 comments on commit 280d3ff

Please sign in to comment.