How to test a custom python-social-auth pipeline?
Asked Answered
A

1

7

So, I have created a custom pipeline for saving user's social profile data fetched from extra_data attribute of the user.social_auth model. I have thoroughly tested it, but manually.

  1. How do I automate testing for my custom pipeline, by using regular django.test.TestCase?

  2. How to test if the normal pipeline works? User signup, login, etc.?

I did search a lot but didn't find any relevant similar questions let alone tutorials or documentation for it.

Update - I posted the question as an issue on github and found out that functionality for pipeline testing exists. Now I only need to figure out how to use it for my purpose.

Arianearianie answered 7/8, 2014 at 22:23 Comment(0)
B
6

First - Assume that the Pipeline mechanism works so you don't need to test that.

Second - Find out what arguments you need to pass to your function.

Third - Write your test.

Using Django TestCase your test would look like this.

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)

This would be your basic structure, without more information on what your pipeline does this is as good as it gets. You get the gist of how things work with Django TestCase anyways.

The thing to take away from this is that you don't need to test how it fits together with the actual pipeline itself, that's for the pipeline to know about, you just worry about your function. And if you need to have a pipeline object for some reason, mock it.

Braud answered 12/8, 2014 at 20:23 Comment(1)
This is a great solution for the general question of "how do I test a function", but I am going to push for a more detailed solution. Specifically, how would one test custom partial pipeline functions? Partial pipeline functions are decorated. This decoration requires complicated arguments for thestrategy.storage.partial.store(current_partial).Rigby

© 2022 - 2024 — McMap. All rights reserved.