-
-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to edit Profiles in Samples for pre verified/published states #1657
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
77c20c2
Added custom setter method to handle profiles
ramonski cee4bf1
Allow to edit profiles in pre verified/published states
ramonski 3759e71
Added upgrade step
ramonski 48b4db8
Changelog updated
ramonski f770319
Run typeinfo from senaite.core package
ramonski 1bb18a3
Added missing comma
ramonski 05b030d
Run import steps from snaite.core and bika.lims
ramonski a900bd0
Added doctest
ramonski 04275a9
Added missing method argument
ramonski e3b69eb
Fix tests
ramonski 921703a
Check the status of the Sample is "sample_received" (doctest)
xispa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
Analysis Profile | ||
================ | ||
|
||
Running this test from the buildout directory:: | ||
|
||
bin/test test_textual_doctests -t AnalysisProfile | ||
|
||
Needed Imports: | ||
|
||
>>> import re | ||
>>> from AccessControl.PermissionRole import rolesForPermissionOn | ||
>>> from bika.lims import api | ||
>>> from bika.lims.content.analysisrequest import AnalysisRequest | ||
>>> from bika.lims.utils.analysisrequest import create_analysisrequest | ||
>>> from bika.lims.utils import tmpID | ||
>>> from bika.lims.interfaces import ISubmitted | ||
>>> from bika.lims.workflow import doActionFor as do_action_for | ||
>>> from bika.lims.workflow import getCurrentState | ||
>>> from bika.lims.workflow import getAllowedTransitions | ||
>>> from DateTime import DateTime | ||
>>> from plone.app.testing import TEST_USER_ID | ||
>>> from plone.app.testing import TEST_USER_PASSWORD | ||
>>> from plone.app.testing import setRoles | ||
|
||
Functional Helpers: | ||
|
||
>>> def start_server(): | ||
... from Testing.ZopeTestCase.utils import startZServer | ||
... ip, port = startZServer() | ||
... return "http://{}:{}/{}".format(ip, port, portal.id) | ||
|
||
|
||
>>> def get_services(sample): | ||
... analyses = sample.getAnalyses(full_objects=True) | ||
... services = map(lambda an: an.getAnalysisService(), analyses) | ||
... return services | ||
|
||
>>> def receive_sample(sample): | ||
... do_action_for(sample, "receive") | ||
|
||
>>> def submit_analyses(sample): | ||
... for analysis in sample.getAnalyses(full_objects=True): | ||
... analysis.setResult(13) | ||
... do_action_for(analysis, "submit") | ||
|
||
>>> def verify_analyses(sample): | ||
... for analysis in sample.getAnalyses(full_objects=True): | ||
... if ISubmitted.providedBy(analysis): | ||
... do_action_for(analysis, "verify") | ||
|
||
>>> def retract_analyses(sample): | ||
... for analysis in sample.getAnalyses(full_objects=True): | ||
... if ISubmitted.providedBy(analysis): | ||
... do_action_for(analysis, "retract") | ||
|
||
Variables: | ||
|
||
>>> portal = self.portal | ||
>>> request = self.request | ||
>>> setup = portal.bika_setup | ||
>>> date_now = DateTime().strftime("%Y-%m-%d") | ||
>>> date_future = (DateTime() + 5).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) | ||
>>> supplier = api.create(setup.bika_suppliers, "Supplier", Name="Naralabs") | ||
>>> Cu = api.create(setup.bika_analysisservices, "AnalysisService", title="Copper", Keyword="Cu", Price="15", Category=category.UID(), Accredited=True) | ||
>>> Fe = api.create(setup.bika_analysisservices, "AnalysisService", title="Iron", Keyword="Fe", Price="10", Category=category.UID()) | ||
>>> Au = api.create(setup.bika_analysisservices, "AnalysisService", title="Gold", Keyword="Au", Price="20", Category=category.UID()) | ||
>>> Zn = api.create(setup.bika_analysisservices, "AnalysisService", title="Zink", Keyword="Zn", Price="20", Category=category.UID()) | ||
>>> service_uids1 = [Cu.UID(), Fe.UID(), Au.UID()] | ||
>>> service_uids2 = [Zn.UID()] | ||
>>> service_uids3 = [Cu.UID(), Fe.UID(), Au.UID(), Zn.UID()] | ||
>>> profile1 = api.create(setup.bika_analysisprofiles, "AnalysisProfile", title="Profile", Service=service_uids1) | ||
>>> profile2 = api.create(setup.bika_analysisprofiles, "AnalysisProfile", title="Profile", Service=service_uids2) | ||
>>> profile3 = api.create(setup.bika_analysisprofiles, "AnalysisProfile", title="Profile", Service=service_uids3) | ||
|
||
|
||
Assign Profile(s) | ||
----------------- | ||
|
||
Assigning Analysis Profiles adds the Analyses of the profile to the sample. | ||
|
||
>>> setup.setSelfVerificationEnabled(True) | ||
|
||
>>> values = { | ||
... 'Client': client.UID(), | ||
... 'Contact': contact.UID(), | ||
... 'DateSampled': date_now, | ||
... 'SampleType': sampletype.UID()} | ||
|
||
Create some Analysis Requests: | ||
|
||
>>> ar1 = create_analysisrequest(client, request, values, [Au.UID()]) | ||
>>> ar2 = create_analysisrequest(client, request, values, [Fe.UID()]) | ||
>>> ar3 = create_analysisrequest(client, request, values, [Cu.UID()]) | ||
|
||
Apply the profile object. Note the custom `setProfiles` (plural) setter: | ||
|
||
>>> ar1.setProfiles(profile1) | ||
|
||
All analyses from the profile should be added to the sample: | ||
|
||
>>> services = get_services(ar1) | ||
>>> set(map(api.get_uid, services)).issuperset(service_uids1) | ||
True | ||
|
||
The profile is applied to the sample: | ||
|
||
>>> profile1 in ar1.getProfiles() | ||
True | ||
|
||
Apply the profile UID: | ||
|
||
>>> ar2.setProfiles(profile2.UID()) | ||
|
||
All analyses from the profile should be added to the sample: | ||
|
||
>>> services = get_services(ar2) | ||
>>> set(map(api.get_uid, services)).issuperset(service_uids2) | ||
True | ||
|
||
The profile is applied to the sample: | ||
|
||
>>> profile2 in ar2.getProfiles() | ||
True | ||
|
||
|
||
Apply multiple profiles: | ||
|
||
>>> ar3.setProfiles([profile1, profile2, profile3.UID()]) | ||
|
||
All analyses from the profiles should be added to the sample: | ||
|
||
>>> services = get_services(ar3) | ||
>>> set(map(api.get_uid, services)).issuperset(service_uids1 + service_uids2 + service_uids3) | ||
True | ||
|
||
|
||
Remove Profile(s) | ||
----------------- | ||
|
||
Removing an analyis Sample retains the assigned analyses: | ||
|
||
>>> analyses = ar1.getAnalyses(full_objects=True) | ||
>>> ar1.setProfiles([]) | ||
>>> ar1.getProfiles() | ||
[] | ||
|
||
>>> set(ar1.getAnalyses(full_objects=True)) == set(analyses) | ||
True | ||
|
||
|
||
Assigning Profiles in "to_be_verified" status | ||
--------------------------------------------- | ||
|
||
>>> ar4 = create_analysisrequest(client, request, values, [Au.UID()]) | ||
|
||
>>> receive_sample(ar4) | ||
>>> submit_analyses(ar4) | ||
|
||
>>> api.get_workflow_status_of(ar4) | ||
'to_be_verified' | ||
|
||
>>> ar4.getProfiles() | ||
[] | ||
|
||
Setting the profile works up to this state: | ||
|
||
>>> ar4.setProfiles(profile1.UID()) | ||
>>> api.get_workflow_status_of(ar4) | ||
'sample_received' | ||
|
||
>>> services = get_services(ar3) | ||
>>> set(map(api.get_uid, services)).issuperset(service_uids1 + [Au.UID()]) | ||
True |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You still need to keep
setup.runImportStepFromProfile(profile, "workflow")
because of #1620: workflow definitions forInterpretationTemplate
andInterpretationTemplates
are located insenaite.core
profile.