简体   繁体   English

如何使用 python simple-salesforce 测试插入/更新是否成功

[英]How to test if insert/update will succeed with python simple-salesforce

tl;dr How can I test the viability of an update or insert using the simple-salesforce python package? tl;dr如何使用 simple-salesforce python 包测试updateinsert的可行性?

I am writing a test script for a simple-salesforce based python class I have created.我正在为我创建的基于简单 salesforce 的 python 类编写测试脚本。 The class involves sf.bulk.Object_Name__c.insert(data) and sf.bulk.Object_Name__c.update(data) code, but in the test script I would like to confirm that the insert/update would insert successfully or not, without actually committing the new record or change.该类涉及sf.bulk.Object_Name__c.insert(data)sf.bulk.Object_Name__c.update(data)代码,但在测试脚本中我想确认插入/更新是否成功插入,而无需实际提交新记录或更改。

The only item I saw that suggested this might be possible was a page in the Simple-Salesforce documentation noting the existence of the simple_salesforce.tests.test_util module.我看到的唯一表明这可能是可能的项目是Simple-Salesforce 文档中的一个页面,其中指出simple_salesforce.tests.test_util模块的存在。 Unfortunately, I was not able figure out how to access this sub-module, or subsequently try out the test_util class, and the document was quite sparse on instructions on how to do so.不幸的是,我无法弄清楚如何访问这个子模块,或者随后尝试test_util类,并且文档中关于如何这样做的说明非常稀少。

I don't believe this is possible.我不相信这是可能的。 The simple-salesforce package is, essentially, syntactic sugar for building code that will hook into Salesforce's native Rest APIs. simple-salesforce 包本质上是用于构建代码的语法糖,这些代码将挂钩到 Salesforce 的原生 Rest API。

The subpackage simple_salesforce.tests is not a hook into the Salesforce Test functionality, but rather the test code for simple_salesforce itself.子包 simple_salesforce.tests 不是 Salesforce 测试功能的挂钩,而是 simple_salesforce 本身的测试代码。

The type of testing that you would like to complete is limited to Salesforce's native Database.Test class.您想要完成的测试类型仅限于 Salesforce 的本机 Database.Test 类。 These are built in Apex and run within Salesforce itself.这些内置于 Apex 中并在 Salesforce 本身内运行。 There isn't a good way to complete the test you would like to do.没有完成您想做的测试的好方法。

You could write test classes to ensure that the requests that your code generates are properly formatted, but testing that it could actually generate records within Salesforce would require simple-salesforce to be aware of all of your SFDC Organizations metadata, validations, permissions, triggers, processes, etc. This would require simple-salesforce to all but completely replicate salesforce - making it much less simple.您可以编写测试类以确保您的代码生成的请求格式正确,但测试它是否可以在 Salesforce 中实际生成记录需要 simple-salesforce 了解您的所有 SFDC 组织元数据、验证、权限、触发器、流程等。这将需要 simple-salesforce 几乎完全复制 salesforce - 使其不那么简单。

My recommendation is to test your code in a sandbox environment and ensure it works there before moving directly to production.我的建议是在沙盒环境中测试您的代码,并确保它在直接进入生产环境之前可以正常工作。

Alternatively, (and this is purely hypothetical and pretty hacky) you could attempt to build your own hooks into the Salesforce APIs to utilize the Database.setSavePoint() and Database.rollBack() functions.或者,(这纯粹是假设性的,而且很老套)您可以尝试将自己的挂钩构建到 Salesforce API 中,以利用 Database.setSavePoint() 和 Database.rollBack() 函数。 You would set a save point, initialize your bulk job, wait for the bulk job to finish, complete your tests to confirm things were committed, and then rollback to the save point.您将设置一个保存点,初始化您的批量作业,等待批量作业完成,完成您的测试以确认事情已提交,然后回滚到保存点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM