Пример #1
0
 def setUp(self):
     self.user_dao = Mock()
     self.voicemail_dao = Mock()
     self.user_voicemail_dao = Mock()
     self.notifier = Mock()
     self.validator = Mock(AssociationValidator)
     self.service = UserVoicemailService(self.user_dao,
                                         self.voicemail_dao,
                                         self.user_voicemail_dao,
                                         self.validator,
                                         self.notifier)
Пример #2
0
class TestUserVoicemailService(unittest.TestCase):

    def setUp(self):
        self.user_dao = Mock()
        self.voicemail_dao = Mock()
        self.user_voicemail_dao = Mock()
        self.notifier = Mock()
        self.validator = Mock(AssociationValidator)
        self.service = UserVoicemailService(self.user_dao,
                                            self.voicemail_dao,
                                            self.user_voicemail_dao,
                                            self.validator,
                                            self.notifier)

    def test_when_getting_parent_then_dao_is_called(self):
        expected_user_voicemail = self.user_voicemail_dao.get_by_user_id.return_value

        result = self.service.get_by_parent(sentinel.user_id)

        self.user_voicemail_dao.get_by_user_id.assert_called_once_with(sentinel.user_id)
        assert_that(result, equal_to(expected_user_voicemail))

    def test_when_listing_by_children_then_voicemail_dao_is_called(self):
        expected_user_voicemails = self.user_voicemail_dao.find_all_by_voicemail_id.return_value

        result = self.service.list_by_child(sentinel.voicemail_id)

        self.user_voicemail_dao.find_all_by_voicemail_id.assert_called_once_with(sentinel.voicemail_id)
        assert_that(result, equal_to(expected_user_voicemails))

    def test_when_validating_parent_then_user_dao_is_called(self):
        self.service.validate_parent(sentinel.user_id)

        self.user_dao.get.assert_called_once_with(sentinel.user_id)

    def test_when_validating_resource_then_voicemail_dao_is_called(self):
        self.service.validate_resource(sentinel.voicemail_id)

        self.voicemail_dao.get.assert_called_once_with(sentinel.voicemail_id)

    def test_when_associating_then_association_is_validated(self):
        association = Mock(UserVoicemail)
        self.service.associate(association)

        self.validator.validate_association.assert_called_once_with(association)

    def test_when_associating_then_dao_is_called(self):
        association = Mock(UserVoicemail)
        self.service.associate(association)

        self.user_voicemail_dao.associate.assert_called_once_with(association)

    def test_when_associating_then_notifier_is_called(self):
        association = Mock(UserVoicemail)
        self.service.associate(association)

        self.notifier.associated.assert_called_once_with(association)

    def test_when_dissociating_then_dissociation_is_validated(self):
        dissociation = Mock(UserVoicemail)
        self.service.dissociate(dissociation)

        self.validator.validate_dissociation.assert_called_once_with(dissociation)

    def test_when_dissociating_then_dao_is_called(self):
        dissociation = Mock(UserVoicemail)
        self.service.dissociate(dissociation)

        self.user_voicemail_dao.dissociate.assert_called_once_with(dissociation)

    def test_when_dissociating_then_notifier_is_called(self):
        dissociation = Mock(UserVoicemail)
        self.service.dissociate(dissociation)

        self.notifier.dissociated.assert_called_once_with(dissociation)