cheah2go's avatar

How to mock an uploaded file

Hi, I'm just getting into testing and I'd like to test a class that handles a post request containing uploaded files. Is there a way to simulate that?

0 likes
1 reply
bart's avatar

You could create a simple file object, yes. But IMO you don't need it. The upload() method call is from a class you don't own, right? You should never test classes you don't own, so the simplest way is to mock that class and check if the upload method has been called once.

Please or to participate in this conversation.