Esempio n. 1
0
    def test_validate_association_when_user_has_a_different_line(self,
                                                                 user_line_find_all_by_user_id,
                                                                 line_get,
                                                                 user_get):
        user_line = UserLine(user_id=1, line_id=2)
        existing_user_line = UserLine(user_id=1, line_id=3)

        user_line_find_all_by_user_id.return_value = [existing_user_line]

        self.assertRaises(InvalidParametersError, validator.validate_association, user_line)
        user_line_find_all_by_user_id.assert_called_once_with(user_line.user_id)
Esempio n. 2
0
    def test_get_by_user_id_and_line_id(self, user_line_get_by_user_id):
        user_id = 123
        line_id = 42
        expected_result = UserLine(user_id=user_id, line_id=line_id)
        user_line_get_by_user_id.return_value = UserLine(user_id=user_id,
                                                         line_id=line_id)

        result = user_line_services.get_by_user_id_and_line_id(
            user_id, line_id)

        user_line_get_by_user_id.assert_called_once_with(user_id, line_id)
        assert_that(result, equal_to(expected_result))
Esempio n. 3
0
    def test_associate_main_user(self, validate_association,
                                 associate_user_line, notifier_associated,
                                 dao_find_main_user_line):
        user_line = UserLine(user_id=1, line_id=2)
        expected_user_line = UserLine(user_id=1, line_id=2, main_user=True)

        dao_find_main_user_line.return_value = user_line

        result = user_line_services.associate(user_line)

        assert_that(result, equal_to(expected_user_line))
        validate_association.assert_called_once_with(user_line)
        associate_user_line.assert_called_once_with(expected_user_line)
        notifier_associated.assert_called_once_with(expected_user_line)
Esempio n. 4
0
    def test_associate_secondary_user_with_line(self):
        main_user = self.add_user()
        secondary_user = self.add_user()
        line = self.add_line()

        self.add_user_line(user_id=main_user.id,
                           line_id=line.id,
                           extension_id=None,
                           main_user=True,
                           main_line=True)

        secondary_user_line = UserLine(user_id=secondary_user.id,
                                       line_id=line.id,
                                       main_user=False,
                                       main_line=True)

        user_line_dao.associate(secondary_user_line)

        result = (self.session.query(UserLineSchema).filter(
            UserLineSchema.line_id == line.id).all())

        assert_that(
            result,
            contains_inanyorder(
                all_of(has_property('user_id', main_user.id),
                       has_property('line_id', line.id),
                       has_property('extension_id', None),
                       has_property('main_user', True),
                       has_property('main_line', True)),
                all_of(has_property('user_id', secondary_user.id),
                       has_property('line_id', line.id),
                       has_property('extension_id', None),
                       has_property('main_user', False),
                       has_property('main_line', True))))
Esempio n. 5
0
    def test_associate_user_not_exist_with_line(self):
        line = self.add_line()

        user_line = UserLine(user_id=41, line_id=line.id)

        self.assertRaises(ElementCreationError, user_line_dao.associate,
                          user_line)
Esempio n. 6
0
    def test_associate_user_with_line_not_exist(self):
        user = self.add_user()

        user_line = UserLine(user_id=user.id, line_id=42)

        self.assertRaises(ElementCreationError, user_line_dao.associate,
                          user_line)
Esempio n. 7
0
    def test_associate_with_main_user_already_associated_to_this_line(
            self, validate_association, associate_user_line,
            notifier_associated, dao_find_main_user_line):
        main_user_line = UserLine(user_id=1, line_id=2)
        secondary_user_line = UserLine(user_id=2, line_id=2)

        expected_user_line = UserLine(user_id=2, line_id=2, main_user=False)

        dao_find_main_user_line.return_value = main_user_line

        result = user_line_services.associate(secondary_user_line)

        assert_that(result, equal_to(expected_user_line))
        validate_association.assert_called_once_with(secondary_user_line)
        associate_user_line.assert_called_once_with(expected_user_line)
        notifier_associated.assert_called_once_with(expected_user_line)
Esempio n. 8
0
    def test_dissociated(self, bus_event_dissociated,
                         sysconf_command_association_updated):
        user_line = UserLine(user_id=1, line_id=2)

        notifier.dissociated(user_line)

        sysconf_command_association_updated.assert_called_once_with(user_line)
        bus_event_dissociated.assert_called_once_with(user_line)
Esempio n. 9
0
    def test_associate(self, validate_association, associate_user_line,
                       notifier_associated):
        user_line = UserLine(user_id=1, line_id=2)

        result = user_line_services.associate(user_line)

        assert_that(result, equal_to(user_line))
        validate_association.assert_called_once_with(user_line)
        associate_user_line.assert_called_once_with(user_line)
        notifier_associated.assert_called_once_with(user_line)
Esempio n. 10
0
    def test_dict_to_model(self):
        user_id = 1
        line_id = 2
        data = {'line_id': line_id}

        expected = UserLine(user_id=user_id, line_id=line_id)

        formatter = UserLineFormatter()
        result = formatter.dict_to_model(data, user_id)

        assert_that(result, equal_to(expected))
Esempio n. 11
0
    def test_bus_event_dissociated(self, send_bus_command,
                                   UserLineDissociatedEvent):
        new_event = UserLineDissociatedEvent.return_value = Mock()

        user_line = UserLine(user_id=1, line_id=2)

        notifier.bus_event_dissociated(user_line)

        UserLineDissociatedEvent.assert_called_once_with(
            user_line.user_id, user_line.line_id, True, True)
        send_bus_command.assert_called_once_with(new_event)
Esempio n. 12
0
    def prepare_secondary_user_line(self, main_user_line):
        user_row = self.add_user()
        self.add_user_line(user_id=user_row.id,
                           line_id=main_user_line.line_id,
                           extension_id=main_user_line.extension_id,
                           main_user=False,
                           main_line=True)

        return UserLine(user_id=user_row.id,
                        line_id=main_user_line.id,
                        main_user=False)
Esempio n. 13
0
    def test_validate_association(self,
                                  user_line_find_all_by_user_id,
                                  line_get,
                                  user_get):
        user_line = UserLine(user_id=1, line_id=2)

        user_line_find_all_by_user_id.return_value = []

        validator.validate_association(user_line)
        user_get.assert_called_once_with(user_line.user_id)
        line_get.assert_called_once_with(user_line.line_id)
        user_line_find_all_by_user_id.assert_called_once_with(user_line.user_id)
Esempio n. 14
0
    def test_associate_user_with_line(self):
        user = self.add_user()
        line = self.add_line()

        user_line = UserLine(user_id=user.id, line_id=line.id)

        expected_user_line = user_line_dao.associate(user_line)

        result = (self.session.query(UserLineSchema).filter(
            UserLineSchema.id == expected_user_line.id).first())

        assert_that(result.user_id, equal_to(user_line.user_id))
        assert_that(result.line_id, equal_to(user_line.line_id))
        assert_that(result.extension_id, none())
        assert_that(result.main_user, equal_to(True))
        assert_that(result.main_line, equal_to(True))
Esempio n. 15
0
    def test_validate_dissociation_main_user_with_secondary_user(self,
                                                                 user_dao_get,
                                                                 line_dao_get,
                                                                 user_line_dao_find_all_by_user_id,
                                                                 line_has_secondary_user):
        user_line = UserLine(user_id=3,
                             line_id=4,
                             main_user=True)

        user_line_dao_find_all_by_user_id.return_value = [user_line]
        line_has_secondary_user.return_value = True

        self.assertRaises(InvalidParametersError, validator.validate_dissociation, user_line)
        user_dao_get.assert_called_once_with(user_line.user_id)
        line_dao_get.assert_called_once_with(user_line.line_id)
        user_line_dao_find_all_by_user_id.assert_called_once_with(user_line.user_id)
        line_has_secondary_user.assert_called_once_with(user_line)
Esempio n. 16
0
    def test_validate_dissociation(self,
                                   user_dao_get,
                                   line_dao_get,
                                   user_line_dao_find_all_by_user_id,
                                   line_has_secondary_user,
                                   validate_no_device):
        user_line = UserLine(user_id=3,
                             line_id=4,
                             main_user=True)

        user_line_dao_find_all_by_user_id.return_value = [user_line]
        line_has_secondary_user.return_value = False

        validator.validate_dissociation(user_line)
        user_dao_get.assert_called_once_with(user_line.user_id)
        line_dao_get.assert_called_once_with(user_line.line_id)
        user_line_dao_find_all_by_user_id.assert_called_once_with(user_line.user_id)
        line_has_secondary_user.assert_called_once_with(user_line)
        validate_no_device.assert_called_once_with(user_line.line_id)
Esempio n. 17
0
    def test_associate_main_user_with_line_and_extension(self):
        user = self.add_user()
        line = self.add_line()
        extension = self.add_extension()
        user_line_row = self.add_user_line(line_id=line.id,
                                           extension_id=extension.id)

        user_line = UserLine(user_id=user.id, line_id=line.id)

        user_line_dao.associate(user_line)

        result = self.session.query(UserLineSchema).filter(
            UserLineSchema.id == user_line_row.id).first()

        assert_that(
            result,
            all_of(has_property('user_id', user.id),
                   has_property('line_id', line.id),
                   has_property('extension_id', extension.id),
                   has_property('main_user', True),
                   has_property('main_line', True)))
Esempio n. 18
0
    def test_send_sysconf_command_association_updated(self,
                                                      find_all_by_user_id,
                                                      exec_request_handlers):
        user_line = UserLine(user_id=1, line_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': ['dialplan reload', 'sip reload'],
            'agentbus': []
        }

        notifier.sysconf_command_association_updated(user_line)

        exec_request_handlers.assert_called_once_with(expected_sysconf_command)
        find_all_by_user_id.assert_called_once_with(user_line.user_id)
Esempio n. 19
0
    def test_associate_secondary_user_with_line_and_extension(self):
        main_user = self.add_user()
        secondary_user = self.add_user()
        line = self.add_line()
        extension = self.add_extension()

        main_user_line_row = self.add_user_line(user_id=main_user.id,
                                                line_id=line.id,
                                                extension_id=extension.id,
                                                main_user=True,
                                                main_line=True)

        user_line = UserLine(user_id=secondary_user.id,
                             line_id=line.id,
                             main_user=False)

        user_line_dao.associate(user_line)

        main_row = (self.session.query(UserLineSchema).filter(
            UserLineSchema.id == main_user_line_row.id).first())

        secondary_row = (self.session.query(UserLineSchema).filter(
            UserLineSchema.line_id == line.id).filter(
                UserLineSchema.user_id == secondary_user.id).first())

        assert_that(
            main_row,
            all_of(has_property('user_id', main_user.id),
                   has_property('line_id', line.id),
                   has_property('extension_id', extension.id),
                   has_property('main_user', True),
                   has_property('main_line', True)))

        assert_that(
            secondary_row,
            all_of(has_property('user_id', secondary_user.id),
                   has_property('line_id', line.id),
                   has_property('extension_id', extension.id),
                   has_property('main_user', False),
                   has_property('main_line', True)))
Esempio n. 20
0
    def test_validate_association_missing_parameters(self):
        user_line = UserLine()

        self.assertRaises(MissingParametersError, validator.validate_association, user_line)
Esempio n. 21
0
    def test_associate_user_not_exist_with_line_not_exist(self):
        user_line = UserLine(user_id=41, line_id=12)

        self.assertRaises(ElementCreationError, user_line_dao.associate,
                          user_line)
Esempio n. 22
0
 def setUp(self):
     super(TestUserLineActions, self).setUp()
     self.user_line = UserLine(user_id=1, line_id=2)
Esempio n. 23
0
 def prepare_user_line(self, user_line_row):
     return UserLine(user_id=user_line_row.user_id,
                     line_id=user_line_row.line_id,
                     main_user=user_line_row.main_user,
                     main_line=user_line_row.main_line)
Esempio n. 24
0
    def test_validate_association_when_line_does_not_exist(self, line_get, user_get):
        user_line = UserLine(user_id=1, line_id=2)

        line_get.side_effect = ElementNotExistsError('line', id=user_line.line_id)
        self.assertRaises(NonexistentParametersError, validator.validate_association, user_line)
        line_get.assert_called_once_with(user_line.line_id)