Skip to content

Commit

Permalink
Merge pull request #97 from SalesforceFoundation/feature/robot_linter…
Browse files Browse the repository at this point in the history
…rors

[Robot] fixing robot lint warnings and errors
  • Loading branch information
gaganpsandhu authored Mar 16, 2021
2 parents 44a0744 + 7395f03 commit 43db142
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 36 deletions.
2 changes: 2 additions & 0 deletions robot/OutboundFunds/resources/OutboundFunds.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def _init_locators(self):
outboundfunds_lex_locators.update(locators)

def get_namespace_prefix(self, name):
""" This is a helper function to capture the namespace prefix of the target org """
parts = name.split("__")
if parts[-1] == "c":
parts = parts[:-1]
Expand All @@ -62,6 +63,7 @@ def get_namespace_prefix(self, name):
return ""

def get_outfunds_namespace_prefix(self):
"""Get outfunds__ prefix for custom objects"""
if not hasattr(self.cumulusci, "_describe_result"):
self.cumulusci._describe_result = self.cumulusci.sf.describe()
objects = self.cumulusci._describe_result["sobjects"]
Expand Down
42 changes: 28 additions & 14 deletions robot/OutboundFunds/resources/OutboundFunds.robot
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ API Create Disbursement on a Funding Request
[Return] &{disbursement}

Change Object Permissions
[Documentation] Adds or removes the Create, Read, Edit and Delete permissions for the specified object on the specified permission set..
[Documentation] Adds or removes the Create, Read, Edit and Delete permissions
... for the specified object on the specified permission set..
[Arguments] ${action} ${objectapiname} ${permset}


${removeobjperms} = Catenate SEPARATOR=\n
... ObjectPermissions objperm;
... objperm = [SELECT Id, PermissionsRead, PermissionsEdit, PermissionsCreate, PermissionsDelete FROM ObjectPermissions
... objperm = [SELECT Id, PermissionsRead, PermissionsEdit, PermissionsCreate,
... PermissionsDelete FROM ObjectPermissions
... WHERE parentId IN ( SELECT id FROM permissionset WHERE PermissionSet.Name = '${permset}')
... AND SobjectType='${objectapiname}'];
... objperm.PermissionsRead = false;
Expand All @@ -138,7 +140,8 @@ Change Object Permissions

${addobjperms} = Catenate SEPARATOR=\n
... String permid = [SELECT id FROM permissionset WHERE PermissionSet.Name = '${permset}'].id;
... ObjectPermissions objperm = New ObjectPermissions(PermissionsRead = true, PermissionsEdit = true, PermissionsCreate = true,
... ObjectPermissions objperm = New ObjectPermissions(PermissionsRead = true,
... PermissionsEdit = true, PermissionsCreate = true,
... PermissionsDelete = true, ParentId = permid, SobjectType='${objectapiname}');
... insert objperm;

Expand All @@ -151,7 +154,8 @@ Change Object Permissions
... apex= ${addobjperms}

Change Field Permissions
[Documentation] Adds or removes the Create, Read, Edit and Delete permissions for the specified object field on the specified permission set.
[Documentation] Adds or removes the Create, Read, Edit and Delete permissions
... for the specified object field on the specified permission set.
[Arguments] ${action} ${objectapiname} ${fieldapiname} ${permset}

${removefieldperms} = Catenate SEPARATOR=\n
Expand All @@ -166,8 +170,10 @@ Change Field Permissions

${addfieldperms} = Catenate SEPARATOR=\n
... String permid = [SELECT id FROM permissionset WHERE PermissionSet.Name = '${permset}'].id;
... FieldPermissions fldperm = New FieldPermissions(PermissionsRead = true, PermissionsEdit = true,
... ParentId = permid, Field = '${objectapiname}.${fieldapiname}', SobjectType='${objectapiname}');
... FieldPermissions fldperm = New FieldPermissions(PermissionsRead = true,
... PermissionsEdit = true,
... ParentId = permid, Field = '${objectapiname}.${fieldapiname}',
... SobjectType='${objectapiname}');
... insert fldperm;

Run Keyword if "${action}" == "remove"
Expand All @@ -179,36 +185,44 @@ Change Field Permissions
... apex= ${addfieldperms}

Object Permissions Cleanup
[Documentation] Resets all object permissions in case a test fails before they are restored. Skips the reset if the permissions have already been added back.
[Documentation] Resets all object permissions in case a test fails
... before they are restored. Skips the reset if the permissions
... have already been added back.
[Arguments] ${objectapiname} ${permset}

${addobjback} = Catenate SEPARATOR=\n
... List<ObjectPermissions> checkperms = [SELECT PermissionsRead FROM ObjectPermissions
... WHERE parentId IN ( SELECT id FROM permissionset WHERE PermissionSet.Name = '${permset}') AND
... WHERE parentId IN ( SELECT id FROM permissionset WHERE PermissionSet.Name = '${permset}')
... AND
... SobjectType = '${objectapiname}'];
... if (checkperms.isEmpty()) {
... String permid = [SELECT id FROM permissionset WHERE PermissionSet.Name = '${permset}'].id;
... ObjectPermissions objperm = New ObjectPermissions(PermissionsRead = true, PermissionsEdit = true, PermissionsCreate = true,
... ObjectPermissions objperm = New ObjectPermissions(PermissionsRead = true,
... PermissionsEdit = true, PermissionsCreate = true,
... PermissionsDelete = true, ParentId = permid, SobjectType = '${objectapiname}');
... insert objperm; }
... else { System.debug('Permissions Exist, skipping.'); }

Run Task execute_anon apex=${addobjback}

Field Permissions Cleanup
[Documentation] Resets all field permissions in case a test fails before they are restored. Skips the reset if the permissions have already been added back.
[Documentation] Resets all field permissions in case a test fails before they are restored.
... Skips the reset if the permissions have already been added back.
[Arguments] ${objectapiname} ${fieldapiname} ${permset}

${ns} = Get NPSP Namespace Prefix
${ns} = Get Outfunds Namespace Prefix

${addfieldback} = Catenate SEPARATOR=\n
... List<FieldPermissions> checkperms = [SELECT PermissionsRead FROM FieldPermissions
... WHERE parentId IN ( SELECT id FROM permissionset WHERE PermissionSet.Name = '${permset}') AND
... WHERE parentId IN ( SELECT id FROM permissionset WHERE PermissionSet.Name = '${permset}')
... AND
... SobjectType = '${objectapiname}' AND Field = '${objectapiname}.${fieldapiname}'];
... if (checkperms.isEmpty()) {
... String permid = [SELECT id FROM permissionset WHERE PermissionSet.Name = '${permset}'].id;
... FieldPermissions fldperm = New FieldPermissions(PermissionsRead = true, PermissionsEdit = true,
... ParentId = permid, Field = '${objectapiname}.${fieldapiname}', SobjectType = '${objectapiname}');
... FieldPermissions fldperm = New FieldPermissions(PermissionsRead = true,
... PermissionsEdit = true,
... ParentId = permid, Field = '${objectapiname}.${fieldapiname}',
... SobjectType = '${objectapiname}');
... insert fldperm; }
... else { System.debug('Permissions Exist, skipping.'); }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*** Settings ***

Documentation Create an awarded funding request and add disbursemnt
Resource robot/OutboundFunds/resources/OutboundFunds.robot
Library cumulusci.robotframework.PageObjects
... robot/OutboundFunds/resources/FundingRequestPageObject.py
Expand All @@ -12,15 +12,18 @@ Suite Teardown Capture Screenshot And Delete Records And Close Browser

*** Keywords ***
Setup Test Data
[Documentation] Create data to run tests
${ns} = Get Outfunds Namespace Prefix
Set Suite Variable ${ns}
${fundingprogram} = API Create Funding Program
Set suite variable ${fundingprogram}
${contact} = API Create Contact
Store Session Record Contact ${contact}[Id]
Set suite variable ${contact}
${funding_request} = API Create Funding Request ${fundingprogram}[Id] ${contact}[Id]
... ${ns}Status__c=Awarded ${ns}Awarded_Amount__c=100000
${funding_request} = API Create Funding Request
... ${fundingprogram}[Id] ${contact}[Id]
... ${ns}Status__c=Awarded
... ${ns}Awarded_Amount__c=100000
Store Session Record ${ns}Funding_Request__c ${funding_request}[Id]
Set suite variable ${funding_request}

Expand All @@ -43,5 +46,5 @@ Create Disbursement on a Funding Request
Wait Until Element Is Visible text:Scheduled Date
Save Disbursement
Current Page Should Be Details Funding_Request__c
Validate Field Value Unpaid Disbursements contains $80,000.00
Validate Field Value Available for Disbursement contains $20,000.00
Validate Field Value Unpaid Disbursements contains $80,000.00
Validate Field Value Available for Disbursement contains $20,000.00
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*** Settings ***

Documentation Create a nw Funding Program
Resource robot/OutboundFunds/resources/OutboundFunds.robot
Library cumulusci.robotframework.PageObjects
... robot/OutboundFunds/resources/FundingProgramPageObject.py
Expand All @@ -12,6 +12,7 @@ Suite Teardown Capture Screenshot And Delete Records And Close Browser

*** Keywords ***
Setup Test Data
[Documentation] Create data to run tests
${ns} = Get Outfunds Namespace Prefix
Set suite variable ${ns}
&{fundingprogram} = API Create Funding Program
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*** Settings ***

Documentation Create a funding request.
Resource robot/OutboundFunds/resources/OutboundFunds.robot
Library cumulusci.robotframework.PageObjects
... robot/OutboundFunds/resources/FundingRequestPageObject.py
Expand All @@ -12,6 +12,7 @@ Suite Teardown Capture Screenshot And Delete Records And Close Browser

*** Keywords ***
Setup Test Data
[Documentation] Create data to run tests
${ns} = Get Outfunds Namespace Prefix
Set Suite Variable ${ns}
${fundingprogram} = API Create Funding Program
Expand All @@ -20,12 +21,14 @@ Setup Test Data
${contact} = API Create Contact
Store Session Record Contact ${contact}[Id]
Set suite variable ${contact}
${funding_request} = API Create Funding Request ${fundingprogram}[Id] ${contact}[Id]
${funding_request} = API Create Funding Request
... ${fundingprogram}[Id] ${contact}[Id]
Store Session Record ${ns}Funding_Request__c ${funding_request}[Id]
Set suite variable ${funding_request}
${awardedfunding_request} = API Create Funding Request ${fundingprogram}[Id] ${contact}[Id]
... ${ns}Status__c=Awarded ${ns}Awarded_Amount__c=100000
Store Session Record ${ns}Funding_Request__c ${awardedfunding_request}[Id]
${awardedfunding_request} = API Create Funding Request
... ${fundingprogram}[Id] ${contact}[Id]
... ${ns}Status__c=Awarded ${ns}Awarded_Amount__c=100000
Store Session Record ${ns}Funding_Request__c ${awardedfunding_request}[Id]
Set suite variable ${awardedfunding_request}
${fr_name} = Generate New String
Set suite variable ${fr_name}
Expand All @@ -43,7 +46,8 @@ Create Funding Request Via API
Wait Until Loading Is Complete
Current Page Should Be Details Funding_Request__c
Validate Field Value Status contains In progress
Validate Field Value Funding Request Name contains ${funding_request}[Name]
Validate Field Value Funding Request Name contains
... ${funding_request}[Name]

Create Funding Request via UI in Outbound Funds
[Documentation] Creates a Funding Request via UI.
Expand All @@ -58,4 +62,4 @@ Create Funding Request via UI in Outbound Funds
Click Save
wait until modal is closed
Current Page Should Be Details Funding_Request__c
Validate Field Value Funding Request Name contains ${fr_name}
Validate Field Value Funding Request Name contains ${fr_name}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*** Settings ***

Documentation Create a Requirement on a Funding Request.
Resource robot/OutboundFunds/resources/OutboundFunds.robot
Library cumulusci.robotframework.PageObjects
... robot/OutboundFunds/resources/FundingRequestPageObject.py
Expand All @@ -12,15 +12,18 @@ Suite Teardown Capture Screenshot And Delete Records And Close Browser

*** Keywords ***
Setup Test Data
[Documentation] Create data to run tests
${ns} = Get Outfunds Namespace Prefix
Set Suite Variable ${ns}
${fundingprogram} = API Create Funding Program
Set suite variable ${fundingprogram}
${contact} = API Create Contact
Store Session Record Contact ${contact}[Id]
Set suite variable ${contact}
${funding_request} = API Create Funding Request ${fundingprogram}[Id] ${contact}[Id]
... ${ns}Status__c=In Progress ${ns}Awarded_Amount__c=100000
${funding_request} = API Create Funding Request ${fundingprogram}[Id]
... ${contact}[Id]
... ${ns}Status__c=In Progress
... ${ns}Awarded_Amount__c=100000
Store Session Record ${ns}Funding_Request__c ${funding_request}[Id]
Set suite variable ${funding_request}
${req_name} = Generate New String
Expand All @@ -30,7 +33,7 @@ Setup Test Data
Add a Requirement on a Funding Request
[Documentation] Creates a Funding Request via API.
... Go to Requirements and add a new Requirement
[tags] feature:Funding Request Requirements
[tags] feature:FundingRequest Requirements
Go To Page Listing ${ns}Funding_Request__c
Click Link With Text ${funding_request}[Name]
Wait Until Loading Is Complete
Expand All @@ -43,5 +46,5 @@ Add a Requirement on a Funding Request
Click Save
wait until modal is closed
Click Related List Link ${req_name}
Validate Field Value Requirement Name contains ${req_name}
Validate Field Value Requirement Name contains ${req_name}
Validate Field Value Primary Contact contains ${contact}[Name]
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
*** Settings ***

Documentation Create a new Contact via API and UI.
Resource cumulusci/robotframework/Salesforce.robot
Suite Setup Open Test Browser
Suite Teardown Delete Records and Close Browser

*** Test Cases ***

Via API
[Documentation] Create a Contact via API
${first_name} = Generate Random String
${last_name} = Generate Random String
${contact_id} = Salesforce Insert Contact
Expand All @@ -16,6 +17,7 @@ Via API
Validate Contact ${contact_id} ${first_name} ${last_name}

Via UI
[Documentation] Create a Contact via UI
${first_name} = Generate Random String
${last_name} = Generate Random String
Go To Object Home Contact
Expand All @@ -28,18 +30,16 @@ Via UI
${contact_id} = Get Current Record Id
Store Session Record Contact ${contact_id}
Validate Contact ${contact_id} ${first_name} ${last_name}


*** Keywords ***

Validate Contact
[Arguments] ${contact_id} ${first_name} ${last_name}
[Documentation] Validate via UI and API
# Validate via UI
Go To Record Home ${contact_id}
Page Should Contain ${first_name} ${last_name}
# Validate via API
&{contact} = Salesforce Get Contact ${contact_id}
Should Be Equal ${first_name} &{contact}[FirstName]
Should Be Equal ${last_name} &{contact}[LastName]


0 comments on commit 43db142

Please sign in to comment.