Example #1
0
    def validate_we_are_not_creating_a_group_under_the_same_extension(
            self, user, line):
        main_line_extension = line_extension_dao.find_by_line_id(line.id)
        if not main_line_extension:
            return

        lines_reachable_from_extension = set(
            line_extension.line_id
            for line_extension in line_extension_dao.find_all_by(
                extension_id=main_line_extension.extension_id))

        users_reachable_from_extension = set(
            user_line.user_id for line_id in lines_reachable_from_extension
            for user_line in user_line_dao.find_all_by(line_id=line_id,
                                                       main_user=True))
        users_reachable_from_extension.add(user.id)

        if len(users_reachable_from_extension) == 1:
            return
        elif len(lines_reachable_from_extension) == 1:
            return
        else:
            lines_reachable_from_extension.remove(line.id)
            faulty_line_id = lines_reachable_from_extension.pop()
            raise errors.resource_associated(
                'Line',
                'Extension',
                line_id=faulty_line_id,
                extension_id=main_line_extension.extension_id,
            )
Example #2
0
def validate_line_not_associated_to_extension(line_extension):
    line_extension = line_extension_dao.find_by_line_id(line_extension.line_id)
    if line_extension:
        raise errors.resource_associated('Line',
                                         'Extension',
                                         line_id=line_extension.line_id,
                                         extension_id=line_extension.extension_id)
Example #3
0
    def test_find_by_line_id_with_multiple_users(self):
        main_ule = self.add_user_line_with_exten()
        secondary_ule = self.prepare_secondary_user_associated(main_ule)

        line_extension = dao.find_by_line_id(secondary_ule.line_id)

        assert_that(line_extension.line_id, equal_to(main_ule.line_id))
        assert_that(line_extension.extension_id, equal_to(main_ule.extension_id))
Example #4
0
    def test_find_by_line_id(self):
        line = self.add_line()
        extension = self.add_extension()
        expected = self.add_line_extension(line_id=line.id,
                                           extension_id=extension.id)

        line_extension = dao.find_by_line_id(expected.line_id)

        assert_that(line_extension, equal_to(expected))
Example #5
0
    def test_find_by_line_id_no_line(self):
        result = dao.find_by_line_id(1)

        assert_that(result, none())
Example #6
0
def find_extension(line_id):
    line_extension = line_extension_dao.find_by_line_id(line_id)
    if line_extension:
        return extension_dao.get(line_extension.extension_id)
    return None
Example #7
0
def find_by_line_id(line_id):
    return line_extension_dao.find_by_line_id(line_id)
Example #8
0
    def test_find_by_line_id_with_extension(self):
        expected = self.add_user_line_with_exten()

        line_extension = dao.find_by_line_id(expected.line_id)

        assert_that(line_extension, equal_to(expected))
Example #9
0
    def test_find_by_line_id_no_extension(self):
        user_line_row = self.add_user_line_without_exten()

        result = dao.find_by_line_id(user_line_row.line_id)

        assert_that(result, none())
Example #10
0
    def test_find_by_line_id_no_line(self):
        result = dao.find_by_line_id(1)

        assert_that(result, none())