def test_build_manager(self, AssociationManager, InternalAssociator, IncallAssociator, line_extension_validator, context_dao, ule_services, user_line_dao, incall_dao, extension_dao, extension_validator, line_device_validator): association_manager = AssociationManager.return_value = Mock(AssociationManager) internal_association = InternalAssociator.return_value = Mock(InternalAssociator) incall_association = IncallAssociator.return_value = Mock(IncallAssociator) result = build_manager() assert_that(result, equal_to(association_manager)) AssociationManager.assert_called_once_with(context_dao, line_extension_validator, { 'internal': internal_association, 'incall': incall_association}) InternalAssociator.assert_called_once_with(ule_services, extension_validator, line_extension_validator, line_device_validator) IncallAssociator.assert_called_once_with(line_extension_validator, user_line_dao, incall_dao, extension_dao)
def setUp(self): self.extension_validator = Mock() self.line_extension_validator = Mock() self.line_device_validator = Mock() self.ule_dao = Mock() self.line_extension = Mock(LineExtension, line_id=12, extension_id=15) self.associator = InternalAssociator(self.ule_dao, self.extension_validator, self.line_extension_validator, self.line_device_validator)
class TestInternalAssociator(unittest.TestCase): def setUp(self): self.extension_validator = Mock() self.line_extension_validator = Mock() self.line_device_validator = Mock() self.ule_dao = Mock() self.line_extension = Mock(LineExtension, line_id=12, extension_id=15) self.associator = InternalAssociator(self.ule_dao, self.extension_validator, self.line_extension_validator, self.line_device_validator) def test_when_associating_then_validates_line_not_associated_to_any_extension(self): self.associator.associate(self.line_extension) self.line_extension_validator.validate_line_not_associated_to_extension.assert_called_once_with(self.line_extension) def test_when_associating_then_validates_extension_not_associated(self): self.associator.associate(self.line_extension) self.extension_validator.validate_extension_not_associated.assert_called_once_with(self.line_extension.extension_id) def test_when_associating_then_creates_ule(self): self.associator.associate(self.line_extension) self.ule_dao.associate_line_extension.assert_called_once_with(self.line_extension) def test_when_dissociating_then_validates_not_associated_to_device(self): self.associator.dissociate(self.line_extension) self.line_device_validator.validate_no_device.assert_called_once_with(self.line_extension.line_id) def test_when_dissociating_then_deletes_ule(self): self.associator.dissociate(self.line_extension) self.ule_dao.dissociate_line_extension.assert_called_once_with(self.line_extension)