'set kwargs in test of serializer

I wrote a serializer in which I used the kwargs in its validate() . here is it:

  def validate(self, value):
    course_id = self.context.get("view").kwargs.get("course_id ")
    ....

now I want to write a test but I don't know how to pass the kwargs to it.

here is the test I am trying to write:

def test_valid_data(self):
    serializer = CourseSerializer(
        data=self.course,
             )
    self.assertTrue(serializer.is_valid())

I test this but it didn't work:

def test_valid_data(self):
    serializer = CourseSerializer(
        data=self.course,
         kwargs={
            "course_id": test_course_id
        },

    )
    self.assertTrue(serializer.is_valid())


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source