【问题标题】:How to test a custom python-social-auth pipeline?如何测试自定义 python-social-auth 管道?
【发布时间】:2014-10-01 07:53:28
【问题描述】:

因此,我创建了一个自定义管道,用于保存从user.social_auth 模型的extra_data 属性获取的用户社交资料数据。我已经对其进行了彻底的测试,但是是手动的。

  1. 如何使用常规 django.test.TestCase 自动测试我的自定义管道?

  2. 如何测试正常流水线是否工作?用户注册、登录等?

我确实搜索了很多,但没有找到任何相关的类似问题,更不用说教程或documentation 了。

更新 - 我将问题发布为issue on github 并发现functionality for pipeline testing exists。现在我只需要弄清楚如何将它用于我的目的。

【问题讨论】:

    标签: python django django-testing python-social-auth django-tests


    【解决方案1】:

    首先 - 假设 Pipeline 机制有效,因此您无需对其进行测试。

    第二 - 找出你需要传递给你的函数的参数。

    第三 - 编写你的测试。

    使用 Django TestCase,您的测试将如下所示。

    from mycustompipeline import pipelinefunction
    
    class MyPipeLineTest(TestCase):
        def setUp(self):
            self.arg1 = Arg1() #both one and two could be mocks.
            self.arg2 = Arg2()
    
        def test_that_my_pipeline_does_something(self):
            result = pipelinefunction(self.arg1, self.arg2)
    
            self.assertTrue(result)
    

    这将是您的基本结构,没有关于您的管道功能的更多信息,这是尽可能好的。 无论如何,您都会了解 Django TestCase 是如何工作的。

    从中得到的好处是,您无需测试它如何与实际管道本身结合在一起,这是管道知道的,您只需担心您的功能。如果你因为某种原因需要一个管道对象,mock it

    【讨论】:

    • 对于“如何测试函数”这个一般性问题,这是一个很好的解决方案,但我将推动更详细的解决方案。具体来说,如何测试自定义partial pipeline functions?部分流水线功能为decorated。这种装饰需要strategy.storage.partial.store(current_partial) 的复杂参数。
    猜你喜欢
    • 2015-02-24
    • 2018-02-10
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多