Ejemplo n.º 1
0
 def setup_method(self, method):
     super().create_patches([
         'quactrl.services.testing.Inspector',
         'quactrl.services.testing.DeviceContainer'
     ])
     self.db = Mock()
     self.service = t.Service(self.db, 'location')
Ejemplo n.º 2
0
    def should_stop_a_cavity(self):
        serv = t.Service(self.db, 'location')

        serv.inspectors[1] = inspector_1 = Mock()

        pending_orders = serv.stop(1)

        assert 1 not in serv.inspectors
        inspector_1.stop.assert_called_with()
        assert pending_orders == inspector_1.stop.return_value
Ejemplo n.º 3
0
    def should_init_with_dev_container(self):
        serv = t.Service(self.db, 'location')

        assert serv.cavities == 0
        assert not serv.active_cavities

        dev_repo = self.db.Devices.return_value
        dev_repo.get_all_from.assert_called_with('location')
        self.DeviceContainer.assert_called_with(
            dev_repo.get_all_from.return_value)
Ejemplo n.º 4
0
    def should_stop_all_cavities(self):
        serv = t.Service(self.db, 'location')

        serv.inspectors[1] = inspector_1 = Mock()
        serv.inspectors[3] = inspector_3 = Mock()

        pending_orders = serv.stop()

        assert not serv.inspectors
        inspector_1.stop.assert_called_with()
        inspector_3.stop.assert_called_with()
        assert pending_orders[1] == inspector_1.stop.return_value
        assert pending_orders[3] == inspector_3.stop.return_value
Ejemplo n.º 5
0
    def should_restart_all_cavities(self):
        serv = t.Service(self.db, 'location')
        serv.inspectors[1] = Mock()
        serv.inspectors[4] = Mock()

        serv.start = Mock()
        serv.stop = Mock()
        serv.stop.return_value = ['order']

        serv.restart()

        assert len(serv.stop.mock_calls) == 2
        assert len(serv.start.mock_calls) == 2
Ejemplo n.º 6
0
    def should_restart_a_cavity_returning_orders(self):
        serv = t.Service(self.db, 'location')
        serv.inspectors[1] = Mock()

        serv.start = Mock()
        serv.stop = Mock()
        serv.stop.return_value = ['order']

        result = serv.restart(1, False)

        serv.stop.assert_called_with(1)
        serv.start.assert_called_with(1)
        serv.inspectors[1].orders.put.assert_not_called()
        assert result == ['order']
Ejemplo n.º 7
0
    def should_start_a_cavity(self):
        serv = t.Service(self.db, 'location')

        serv.start(1)
        assert serv.cavities == 1
        assert serv.active_cavities == [1]
        self.Inspector.assert_called_with(self.db,
                                          self.DeviceContainer.return_value,
                                          'location', 1, True)

        serv.restart = Mock()
        serv.start(1)

        serv.restart.assert_called_with(1)
Ejemplo n.º 8
0
    def should_start_many_cavities(self):
        serv = t.Service(self.db, 'location')

        serv.start([1, 3, 5])
        assert serv.cavities == 3
        assert set(serv.active_cavities) == set([1, 3, 5])