def test_earliest_no_seis(self):
     """ Test if the Project initializes as expected. """
     self.s_mock.return_value.__getitem__.side_effect = None
     self.s_mock.return_value.__getitem__.return_value = None
     self.project = Project(self.store_mock)
     t_expected = hydraulic_events[0].date_time
     self.assertEqual(self.project.earliest_event().date_time, t_expected)
 def test_earliest_no_events(self):
     self.h_mock.return_value.__getitem__.side_effect = None
     self.h_mock.return_value.__getitem__.return_value = None
     self.s_mock.return_value.__getitem__.side_effect = None
     self.s_mock.return_value.__getitem__.return_value = None
     self.project = Project(self.store_mock)
     self.assertIsNone(self.project.earliest_event())
 def test_close(self):
     """ Test if closing the project emits the will_close signal """
     app = QtCore.QCoreApplication([])
     mock_store = MagicMock()
     mock_signal_handler = MagicMock()
     project = Project(mock_store)
     project.will_close.connect(mock_signal_handler)
     project.close()
     app.processEvents()
     mock_signal_handler.assert_called_once_with(project)
    def test_update_project_time(self):
        """ Test if the project_time_changed signal is emitted as expected """
        self.project = Project(self.store_mock)
        app = QtCore.QCoreApplication([])
        handler = MagicMock()
        self.project.project_time_changed.connect(handler)
        t = datetime(2020, 1, 1, 17)

        self.project.update_project_time(t)
        app.processEvents()
        handler.assert_called_once_with(t)
 def test_init(self):
     """ Test if the Project initializes as expected. """
     self.project = Project(self.store_mock)
     self.assertIsNotNone(self.project)
     t_expected = seismic_events[0].date_time
     self.assertEqual(self.project.project_time, t_expected)
class ProjectTest(unittest.TestCase):
    def setUp(self):
        """
        Setup fake seismic and hydraulic histories which the project will
        use upon instantiation.

        """

        self.s_mock = s_patch.start()
        self.h_mock = h_patch.start()

        # Prepare a fake Store object
        self.store_mock = MagicMock()

    def tearDown(self):
        s_patch.stop()
        h_patch.stop()

    def test_close(self):
        """ Test if closing the project emits the will_close signal """
        app = QtCore.QCoreApplication([])
        mock_store = MagicMock()
        mock_signal_handler = MagicMock()
        project = Project(mock_store)
        project.will_close.connect(mock_signal_handler)
        project.close()
        app.processEvents()
        mock_signal_handler.assert_called_once_with(project)

    def test_init(self):
        """ Test if the Project initializes as expected. """
        self.project = Project(self.store_mock)
        self.assertIsNotNone(self.project)
        t_expected = seismic_events[0].date_time
        self.assertEqual(self.project.project_time, t_expected)

    def test_earliest_no_hydr(self):
        """ Test if the Project initializes as expected. """
        self.h_mock.return_value.__getitem__.side_effect = None
        self.h_mock.return_value.__getitem__.return_value = None
        self.project = Project(self.store_mock)
        t_expected = seismic_events[0].date_time
        self.assertEqual(self.project.earliest_event().date_time, t_expected)

    def test_earliest_no_seis(self):
        """ Test if the Project initializes as expected. """
        self.s_mock.return_value.__getitem__.side_effect = None
        self.s_mock.return_value.__getitem__.return_value = None
        self.project = Project(self.store_mock)
        t_expected = hydraulic_events[0].date_time
        self.assertEqual(self.project.earliest_event().date_time, t_expected)

    def test_earliest_no_events(self):
        self.h_mock.return_value.__getitem__.side_effect = None
        self.h_mock.return_value.__getitem__.return_value = None
        self.s_mock.return_value.__getitem__.side_effect = None
        self.s_mock.return_value.__getitem__.return_value = None
        self.project = Project(self.store_mock)
        self.assertIsNone(self.project.earliest_event())

    def test_event_time_range(self):
        self.project = Project(self.store_mock)
        expected = (seismic_events[0].date_time, seismic_events[1].date_time)
        self.assertEqual(self.project.event_time_range(), expected)

    def test_update_project_time(self):
        """ Test if the project_time_changed signal is emitted as expected """
        self.project = Project(self.store_mock)
        app = QtCore.QCoreApplication([])
        handler = MagicMock()
        self.project.project_time_changed.connect(handler)
        t = datetime(2020, 1, 1, 17)

        self.project.update_project_time(t)
        app.processEvents()
        handler.assert_called_once_with(t)
 def test_event_time_range(self):
     self.project = Project(self.store_mock)
     expected = (seismic_events[0].date_time, seismic_events[1].date_time)
     self.assertEqual(self.project.event_time_range(), expected)