Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test a custom python-social-auth pipeline?

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.

like image 947
shad0w_wa1k3r Avatar asked Aug 07 '14 22:08

shad0w_wa1k3r


1 Answers

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.

like image 148
Henrik Andersson Avatar answered Sep 20 '22 11:09

Henrik Andersson