I want to test user input confirmation answer in a custom management command. The test is for message displayed to user and answer that she enters.
The commands' code is:
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('id', type=int)
def handle(self, *args, **options):
try:
experiment = Experiment.objects.get(pk=options['id'])
except Experiment.DoesNotExist:
raise CommandError(
'Experiment with id "%d" does not exist' % (options['id'])
)
answer = input('Are you sure? (Y/n)')
if answer == 'Y':
experiment.delete()
This accepted answer suggests to use mocking, but it's in a lonely context. I want to test the user input as well other things that I could add to the custom command.
What would be an efficient approach?