Unit test Scrapy parse function with inline_requests decorator

Viewed 134

I have a Scrapy Spider and it has a parse function which has inline_requests decorator, the inline request yields an item which is then combined to return the final output. Below is the code for reference -

@inline_requests
def parse(self, response):
    final_op = {}
    data = json.loads(response.body)
    body = {"id": data['id']}
    request_body = json.dumps(body)
    url = 'https://example.com'
    new_data = yield Request(url, method='POST', body=request_body)
    final_op['Name'] = data['Name value']
    final_op['other data'] = new_data['field']
    yield final_op

I want to Unit test this parse function and for that I need to mock the inline request. How can this be achieved? There is similar SO question here but that doesn't help.

0 Answers
Related