def test_questions_are_recorded(): fake_interact = FakeInteract() fake_interact.answers = {"coffee": "y", "tea": "n"} with mock.patch('qisys.interact', fake_interact): assert qisys.interact.ask_yes_no("Do you like tea?") == "n" assert fake_interact.questions[0]['message'] == "Do you like tea?" assert fake_interact.questions[0]['default'] == False
def test_fake_interact_dict(): """ Test Fake Interact Dict """ fake_interact = FakeInteract() fake_interact.answers = {"coffee": "y", "tea": "n"} with mock.patch('qisys.interact', fake_interact): assert qisys.interact.ask_yes_no("Do you like tea?") == "n" assert qisys.interact.ask_yes_no("Do you like coffee?") == "y"
def test_fake_interact_list(): """ Test Fake Interact """ fake_interact = FakeInteract() fake_interact.answers = [False, "coffee!"] with mock.patch('qisys.interact', fake_interact): assert qisys.interact.ask_yes_no("tea?") is False assert qisys.interact.ask_string("then what?") == "coffee!"
def test_questions_are_recorded(): fake_interact = FakeInteract() fake_interact.answers = {"coffee" : "y", "tea" : "n"} with mock.patch('qisys.interact', fake_interact): assert qisys.interact.ask_yes_no("Do you like tea?") == "n" assert fake_interact.questions[0]['message'] == "Do you like tea?" assert fake_interact.questions[0]['default'] == False
def setup_answers(self, answers): """ Set the return value of qisys.interact.ask_* for this test """ fake_interact = FakeInteract() fake_interact.answers = answers self.interact_patcher = mock.patch('qisys.interact', fake_interact) self.interact_patcher.start()
def interact(request): """ Replace all functions in qisys.interact, and let the user predifine the answers, and inspect the questions that were asked """ from qisys.test.fake_interact import FakeInteract fake_interact = FakeInteract() patcher = mock.patch('qisys.interact', fake_interact) request.addfinalizer(patcher.stop) return patcher.start()