Added testcase for baseInteractor and started testcase for audiorecorder

This commit is contained in:
Manuel Cortez 2019-01-04 17:34:15 -06:00
parent fdfeb2a90b
commit f8738c64b7
3 changed files with 81 additions and 1 deletions

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import unittest
testmodules = ["test.test_renderers", "test.test_setup_py2exe"]
testmodules = ["test.test_setup_py2exe", "test.test_base_interactor", "test.test_renderers"]
suite = unittest.TestSuite()

View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
import unittest
import mock
import languageHandler
from presenters import audioRecorder as presenter
from interactors import audioRecorder as interactor
class audioRecorderTestCase(unittest.TestCase):
""" Test both the presenter and interactor of the audio recorder feature. View stuff will be mocked."""
# @mock.patch("presenters.audioRecorder.sound_lib", esp_set=True)
# @mock.patch("presenters.audioRecorder.pub", esp_set=True)
# @mock.patch("presenters.audioRecorder.tempfile", esp_set=True)
# @mock.patch("presenters.audioRecorder.sound", esp_set=True)
# @mock.patch("presenters.audioRecorder.output", esp_set=True)
# @mock.patch("presenters.audioRecorder.os", esp_set=True)
# def test_audiorecorder_interactor(self, soundlib_mock, pub_mock, tempfile_mock, sound_mock, output_mock, os_mock, widgetUtils_mock, interactor_pub_mock):
# """ Test methods for audio recorder. """
# tempfile_mock.mktemp.return_value = "somefile.wav"
# sound_mock.get_recording.return_value = "some_recording"
# view=mock.MagicMock(name="view")
# interactor_ = interactor.audioRecorderInteractor()
# presenter_ = presenter.audioRecorderPresenter(view=view, interactor=interactor_)
# interactor_.install.assert_called_with(view=view, presenter=presenter_)
# interactor_.start.assert_called_with()
# # Start sending events to the presenter and see its reactions.
# presenter_.start_recording()
# print(presenter_.recording)
@mock.patch("interactors.base.pub", esp_set=True)
@mock.patch("interactors.audioRecorder.widgetUtils", esp_set=True)
def test_audiorecorder_interactor(self, widgetUtils_mock, pub_mock):
pub_mock.subscribe.return_value = True
view=mock.MagicMock(name="view")
interactor_ = interactor.audioRecorderInteractor()
presenter_ = mock.MagicMock(name="Presenter", esp_set=presenter.audioRecorderPresenter)
interactor_.install(view=view, presenter=presenter_)
print(pub_mock.subscribe.called)
def setUp(self):
languageHandler.setLanguage("en")
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
import unittest
import mock
from interactors import base
class baseInteractorTestCase(unittest.TestCase):
""" some tests for the base interactor implementation."""
@mock.patch("interactors.base.pub", esp_set=True)
def test_base_interactor(self, pub_mock):
""" Test the base interactor class. """
view=mock.MagicMock(name="view")
interactor_ = base.baseInteractor()
presenter_ = mock.MagicMock(name="Presenter")
interactor_.install(view=view, presenter=presenter_, modulename="base")
# Check if the interactor has called pubsub correctly.
pub_mock.subscribe.assert_any_call(interactor_.disable_control, "base_disable_control"),
pub_mock.subscribe.assert_any_call(interactor_.enable_control, "base_enable_control"),
pub_mock.subscribe.assert_any_call(interactor_.set_label, "base_set_label"),
pub_mock.subscribe.assert_any_call(interactor_.focus_control, "base_focus_control")
# Now, simulate some event calls.
interactor_.disable_control(control="some_control")
view.disable.assert_called_with("some_control")
interactor_.enable_control(control="some_control")
view.enable.assert_called_with("some_control")
interactor_.focus_control(control="some_control")
view.some_control.SetFocus()
interactor_.uninstall()
pub_mock.unsubscribe.assert_any_call(interactor_.disable_control, "base_disable_control"),
pub_mock.unsubscribe.assert_any_call(interactor_.enable_control, "base_enable_control"),
pub_mock.unsubscribe.assert_any_call(interactor_.set_label, "base_set_label"),
pub_mock.unsubscribe.assert_any_call(interactor_.focus_control, "base_focus_control")
if __name__ == "__main__":
unittest.main()