Beispiel #1
0
class TestLineDeviceAssociationService(unittest.TestCase):

    def setUp(self):
        self.device_updater = Mock(DeviceUpdater)
        self.line_dao = Mock()
        self.service = LineDeviceAssociationService(self.line_dao, self.device_updater)

    def test_when_associating_a_line_to_a_device_then_updates_device_id_on_line(self):
        device = Device(id=sentinel.device_id)
        line = Line()

        self.service.associate(line, device)

        assert_that(line.device_id, equal_to(sentinel.device_id))
        self.line_dao.edit.assert_called_once_with(line)

    def test_when_associating_a_line_to_a_device_then_updates_lines_on_device(self):
        device = Device(id=sentinel.device_id)
        line = Line()

        self.service.associate(line, device)

        self.device_updater.update_for_line.assert_called_once_with(line)

    def test_when_dissociating_a_line_to_a_device_then_removes_device_id_on_line(self):
        device = Device(id=sentinel.device_id)
        line = Line(device_id=sentinel.device_id)

        self.service.dissociate(line, device)

        assert_that(line.device_id, equal_to(None))
        self.line_dao.edit.assert_called_once_with(line)

    def test_when_dissociating_a_line_to_a_device_then_updates_lines_on_device(self):
        device = Device(id=sentinel.device_id)
        line = Line()

        self.service.dissociate(line, device)

        self.device_updater.update_for_line.assert_called_once_with(line)
Beispiel #2
0
 def setUp(self):
     self.device_updater = Mock(DeviceUpdater)
     self.line_dao = Mock()
     self.service = LineDeviceAssociationService(self.line_dao, self.device_updater)