Beispiel #1
0
    def test_find_by_user_id(self, user_voicemail_find_by_user_id):
        user_id = 123
        voicemail_id = 42
        expected_result = UserVoicemail(user_id=user_id,
                                        voicemail_id=voicemail_id)
        user_voicemail_find_by_user_id.return_value = UserVoicemail(
            user_id=user_id, voicemail_id=voicemail_id)

        result = user_voicemail_services.find_by_user_id(user_id)

        user_voicemail_find_by_user_id.assert_called_once_with(user_id)
        assert_that(result, equal_to(expected_result))
Beispiel #2
0
    def test_dissociated(self, bus_event_dissociated, sysconf_command_association_updated):
        user_voicemail = UserVoicemail(user_id=1, voicemail_id=2)

        notifier.dissociated(user_voicemail)

        sysconf_command_association_updated.assert_called_once_with(user_voicemail)
        bus_event_dissociated.assert_called_once_with(user_voicemail)
Beispiel #3
0
    def test_validate_association_when_user_does_not_exist(self, user_get):
        user_voicemail = UserVoicemail(user_id=1, voicemail_id=2)

        user_get.side_effect = ElementNotExistsError('user',
                                                     id=user_voicemail.user_id)
        self.assertRaises(NonexistentParametersError,
                          validator.validate_association, user_voicemail)
        user_get.assert_called_once_with(user_voicemail.user_id)
Beispiel #4
0
    def test_validate_association_voicemail_when_user_has_no_line(
            self, find_all_by_user_id, voicemail_get, user_get):
        user_voicemail = UserVoicemail(user_id=1, voicemail_id=2)

        find_all_by_user_id.return_value = []

        self.assertRaises(InvalidParametersError,
                          validator.validate_association, user_voicemail)
        find_all_by_user_id.assert_called_once_with(user_voicemail.user_id)
Beispiel #5
0
    def test_dissociate_voicemail(self, user_voicemail_dissociate, get_by_user_id):
        user_voicemail = UserVoicemail(user_id=1, voicemail_id=2)
        get_by_user_id.return_value = user_voicemail

        result = self.app.delete(BASE_URL % user_voicemail.user_id)

        self.assert_response_for_delete(result)
        get_by_user_id.assert_called_once_with(user_voicemail.user_id)
        user_voicemail_dissociate.assert_called_once_with(user_voicemail)
Beispiel #6
0
    def test_associate_with_sip_line_when_voicemail_disabled(self):
        extension = '1000'
        user_id, line_id, protocol_id = self.prepare_user_and_line(extension, 'sip')
        voicemail_id = self.prepare_voicemail(extension)

        user_voicemail = UserVoicemail(user_id=user_id, voicemail_id=voicemail_id, enabled=False)
        user_voicemail_dao.associate(user_voicemail)

        self.assert_user_was_associated_with_voicemail(user_id, voicemail_id, enabled=False)
        self.assert_sip_line_was_associated_with_voicemail(protocol_id, voicemail_id)
Beispiel #7
0
    def test_get_voicemail_associated_to_a_user(self, user_voicemail_get_by_user_id):
        user_voicemail = UserVoicemail(voicemail_id=1,
                                       user_id=2)
        user_voicemail_get_by_user_id.return_value = user_voicemail

        expected_result = self.build_item(user_voicemail)

        result = self.app.get(BASE_URL % user_voicemail.user_id)

        self.assert_response_for_get(result, expected_result)
Beispiel #8
0
    def test_associate_with_sip_line_when_secondary_user(self):
        extension = '1000'
        main_user_id, secondary_user_id, line_id, protocol_id = self.prepare_main_and_secondary_user(extension, 'sip')
        voicemail_id = self.prepare_voicemail(extension)

        user_voicemail = UserVoicemail(user_id=secondary_user_id, voicemail_id=voicemail_id)
        user_voicemail_dao.associate(user_voicemail)

        self.assert_user_was_associated_with_voicemail(secondary_user_id, voicemail_id, enabled=True)
        self.assert_sip_line_was_not_associated_with_voicemail(protocol_id, voicemail_id)
Beispiel #9
0
    def test_dissociate_from_user_with_sccp_line(self):
        extension = '1000'
        voicemail = self.prepare_voicemail(extension)
        user_id, _, _ = self.prepare_user_and_line(extension, voicemail, 'sccp')

        user_voicemail = UserVoicemail(user_id=user_id, voicemail_id=voicemail.uniqueid)
        user_voicemail_dao.dissociate(user_voicemail)

        self.assert_user_was_dissociated_from_voicemail(user_id)
        self.assert_sccp_line_was_dissociated_from_voicemail(extension)
Beispiel #10
0
    def test_bus_event_dissociated(self, send_bus_command, UserVoiceailDissociatedEvent):
        new_event = UserVoiceailDissociatedEvent.return_value = Mock()

        user_voicemail = UserVoicemail(user_id=1, voicemail_id=2)

        notifier.bus_event_dissociated(user_voicemail)

        UserVoiceailDissociatedEvent.assert_called_once_with(user_voicemail.user_id,
                                                             user_voicemail.voicemail_id,
                                                             False)
        send_bus_command.assert_called_once_with(new_event)
Beispiel #11
0
    def test_dissociate_from_secondary_user_with_sip_line(self):
        extension_main = '1000'
        extension_secondary = '1001'
        voicemail_main = self.prepare_voicemail(extension_main)
        voicemail_secondary = self.prepare_voicemail(extension_secondary)
        _, secondary_user_id, _, protocol_id = self.prepare_main_and_secondary_user(extension_main, voicemail_main, voicemail_secondary, 'sip')

        user_voicemail = UserVoicemail(user_id=secondary_user_id, voicemail_id=voicemail_secondary.uniqueid)
        user_voicemail_dao.dissociate(user_voicemail)

        self.assert_user_was_dissociated_from_voicemail(secondary_user_id)
        self.assert_sip_line_was_not_dissociated_from_voicemail(protocol_id, voicemail_main)
Beispiel #12
0
    def test_associate_voicemail(self, user_voicemail_associate):
        user_voicemail = UserVoicemail(user_id=1, voicemail_id=2, enabled=True)
        user_voicemail_associate.return_value = user_voicemail

        expected_result = self.build_item(user_voicemail)

        data = {'voicemail_id': user_voicemail.voicemail_id}
        data_serialized = self._serialize_encode(data)

        result = self.app.post(BASE_URL % user_voicemail.user_id, data=data_serialized)

        self.assert_response_for_create(result, expected_result)
        user_voicemail_associate.assert_called_once_with(user_voicemail)
Beispiel #13
0
    def test_validate_association_voicemail_when_user_already_has_a_voicemail(
            self, voicemail_get_by_user_id, find_all_by_user_id, voicemail_get,
            user_get):
        user_voicemail = UserVoicemail(user_id=1, voicemail_id=2)

        find_all_by_user_id.return_value = [Mock(UserLine)]
        voicemail_get_by_user_id.side_effect = Mock(UserVoicemail)

        self.assertRaises(InvalidParametersError,
                          validator.validate_association, user_voicemail)
        voicemail_get_by_user_id.assert_called_once_with(
            user_voicemail.user_id)
        find_all_by_user_id.assert_called_once_with(user_voicemail.user_id)
Beispiel #14
0
    def test_validate_association(self, voicemail_get_by_user_id,
                                  find_all_by_user_id, voicemail_get,
                                  user_get):
        user_voicemail = UserVoicemail(user_id=1, voicemail_id=2)

        find_all_by_user_id.return_value = [Mock(UserLine)]
        voicemail_get_by_user_id.side_effect = ElementNotExistsError(
            'user_voicemail', user_id=user_voicemail.user_id)

        validator.validate_association(user_voicemail)
        user_get.assert_called_once_with(user_voicemail.user_id)
        voicemail_get.assert_called_once_with(user_voicemail.voicemail_id)
        find_all_by_user_id.assert_called_once_with(user_voicemail.user_id)
        voicemail_get_by_user_id.assert_called_once_with(
            user_voicemail.user_id)
Beispiel #15
0
    def test_send_sysconf_command_association_updated(self, find_all_by_user_id, exec_request_handlers):
        user_voicemail = UserVoicemail(user_id=1, voicemail_id=2)
        user_line_1 = Mock(UserLine, line_id=3)
        user_line_2 = Mock(UserLine, line_id=4)

        find_all_by_user_id.return_value = [user_line_1, user_line_2]

        expected_sysconf_command = {
            'ctibus': ['xivo[user,edit,1]', 'xivo[phone,edit,3]', 'xivo[phone,edit,4]'],
            'dird': [],
            'ipbx': ['sip reload'],
            'agentbus': []
        }

        notifier.sysconf_command_association_updated(user_voicemail)

        exec_request_handlers.assert_called_once_with(expected_sysconf_command)
        find_all_by_user_id.assert_called_once_with(user_voicemail.user_id)
Beispiel #16
0
    def test_validate_association_missing_parameters(self):
        user_voicemail = UserVoicemail()

        self.assertRaises(MissingParametersError,
                          validator.validate_association, user_voicemail)
Beispiel #17
0
    def test_validate_association_wrong_parameter_type_for_enabled(self):
        user_voicemail = UserVoicemail(user_id=1, voicemail_id=2, enabled=1)

        self.assertRaises(InvalidParametersError,
                          validator.validate_association, user_voicemail)