Skip to content

Mocking Component.render_to_response #844

Answered by JuroOravec
TheSteveBurgess asked this question in Q&A
Discussion options

You must be logged in to vote

So far I always tested only the output HTML, not the context, so I haven't tried mocking render_to_response.

Some options that come to mind:

  1. Mock self._render() instead - this is the normalized entrypoint, and it doesn't get re-applied like the public render and render_to_response do
  2. Check for the given context in get_context_data(), e.g.
    # Setup
    captured = None
    class MyTable(Component):
        def get_context_data(self):
            captured = self.input.context
    
    # Act
    MyTable.render_to_response({ "data": [1,2,3] })
    
    # Assert
    assert isinstance(captured, Context)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@TheSteveBurgess
Comment options

Answer selected by JuroOravec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants