-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix string results with html characters not displayed after submit (#…
…2285) * Fix string results with html characters not displayed after submit * Added doctest * Changelog * Additional test
- Loading branch information
Showing
3 changed files
with
117 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
String Result | ||
------------- | ||
|
||
An analysis can be configured so the captured value is treated as an string | ||
and not processed internally. | ||
|
||
Running this test from the buildout directory:: | ||
|
||
bin/test test_textual_doctests -t StringResult | ||
|
||
|
||
Test Setup | ||
.......... | ||
|
||
Needed Imports: | ||
|
||
>>> from bika.lims import api | ||
>>> from bika.lims.utils.analysisrequest import create_analysisrequest | ||
>>> from bika.lims.workflow import doActionFor as do_action_for | ||
>>> from DateTime import DateTime | ||
>>> from plone.app.testing import setRoles | ||
>>> from plone.app.testing import TEST_USER_ID | ||
>>> from plone.app.testing import TEST_USER_PASSWORD | ||
|
||
Functional Helpers: | ||
|
||
>>> def start_server(): | ||
... from Testing.ZopeTestCase.utils import startZServer | ||
... ip, port = startZServer() | ||
... return "http://{}:{}/{}".format(ip, port, portal.id) | ||
|
||
>>> def timestamp(format="%Y-%m-%d"): | ||
... return DateTime().strftime(format) | ||
|
||
>>> def new_sample(services): | ||
... values = { | ||
... 'Client': client.UID(), | ||
... 'Contact': contact.UID(), | ||
... 'DateSampled': date_now, | ||
... 'SampleType': sampletype.UID()} | ||
... service_uids = map(api.get_uid, services) | ||
... ar = create_analysisrequest(client, request, values, service_uids) | ||
... transitioned = do_action_for(ar, "receive") | ||
... return ar | ||
|
||
>>> def get_analysis(sample, service): | ||
... service_uid = api.get_uid(service) | ||
... for analysis in sample.getAnalyses(full_objects=True): | ||
... if analysis.getServiceUID() == service_uid: | ||
... return analysis | ||
... return None | ||
|
||
>>> def submit_analyses(ar, result="13"): | ||
... for analysis in ar.getAnalyses(full_objects=True): | ||
... analysis.setResult(result) | ||
... do_action_for(analysis, "submit") | ||
|
||
Variables: | ||
|
||
>>> portal = self.portal | ||
>>> request = self.request | ||
>>> setup = api.get_setup() | ||
>>> date_now = DateTime().strftime("%Y-%m-%d") | ||
|
||
We need to create some basic objects for the test: | ||
|
||
>>> setRoles(portal, TEST_USER_ID, ['LabManager',]) | ||
>>> client = api.create(portal.clients, "Client", Name="Happy Hills", ClientID="HH", MemberDiscountApplies=True) | ||
>>> contact = api.create(client, "Contact", Firstname="Rita", Lastname="Mohale") | ||
>>> sampletype = api.create(setup.bika_sampletypes, "SampleType", title="Water", Prefix="W") | ||
>>> labcontact = api.create(setup.bika_labcontacts, "LabContact", Firstname="Lab", Lastname="Manager") | ||
>>> department = api.create(setup.bika_departments, "Department", title="Chemistry", Manager=labcontact) | ||
>>> category = api.create(setup.bika_analysiscategories, "AnalysisCategory", title="Metals", Department=department) | ||
>>> Cu = api.create(setup.bika_analysisservices, "AnalysisService", title="Copper", Keyword="Cu", Price="15", Category=category.UID()) | ||
>>> Cu.setStringResult(True) | ||
|
||
Test string result | ||
.................. | ||
|
||
When a result is captured and the analysis has the StringResult setting, | ||
enabled, the system returns the string value "as-is" without any processing: | ||
|
||
>>> sample = new_sample([Cu]) | ||
|
||
>>> cu = get_analysis(sample, Cu) | ||
>>> cu.setResult(1.23456789) | ||
>>> cu.getResult() | ||
'1.23456789' | ||
>>> cu.getFormattedResult() | ||
'1.23456789' | ||
>>> cu.setResult('0') | ||
>>> cu.getResult() | ||
'0' | ||
>>> cu.getFormattedResult() | ||
'0' | ||
|
||
>>> cu.setResult('This is a result') | ||
>>> cu.getResult() | ||
'This is a result' | ||
>>> cu.getFormattedResult() | ||
'This is a result' | ||
|
||
If the result contains html characters, `getFormattedResult` escape them | ||
by default: | ||
|
||
>>> cu.setResult('< Detection Limit') | ||
>>> cu.getResult() | ||
'< Detection Limit' | ||
>>> cu.getFormattedResult() | ||
'< Detection Limit' | ||
|
||
Unless the parameter `html` is set to False: | ||
|
||
>>> cu.getFormattedResult(html=False) | ||
'< Detection Limit' |