コード例 #1
0
ファイル: test_dao.py プロジェクト: wazo-platform/xivo-dao
    def test_given_one_template_with_func_key_then_returns_one_result(self):
        destination_row = self.create_user_func_key()
        template = self.prepare_template(
            destination_row, FuncKeyDestUser(user_id=destination_row.user_id))

        expected = SearchResult(1, [template])

        self.assert_search_returns_result(expected)
コード例 #2
0
ファイル: test_dao.py プロジェクト: wazo-platform/xivo-dao
    def test_given_template_has_user_func_key_when_getting_then_returns_user_func_key(
            self):
        destination_row = self.create_user_func_key()
        expected = self.prepare_template(
            destination_row, FuncKeyDestUser(user_id=destination_row.user_id))

        result = dao.get(expected.id)

        assert_that(expected, equal_to(result))
コード例 #3
0
ファイル: test_dao.py プロジェクト: wazo-platform/xivo-dao
    def test_given_no_user_func_key_when_created_then_create_new_user_func_key(
            self):
        user = self.add_user()

        dest_user_count = (self.session.query(FuncKeyDestUser).filter(
            FuncKeyDestUser.user_id == user.id).count())
        assert_that(dest_user_count, equal_to(0))

        template = self.build_template_with_key(
            FuncKeyDestUser(user_id=user.id))
        dao.create(template)

        template = self.build_template_with_key(
            FuncKeyDestUser(user_id=user.id))
        dao.create(template)

        dest_user_count = (self.session.query(FuncKeyDestUser).filter(
            FuncKeyDestUser.user_id == user.id).count())
        assert_that(dest_user_count, equal_to(1))
コード例 #4
0
ファイル: test_dao.py プロジェクト: wazo-platform/xivo-dao
    def test_given_template_has_user_func_key_when_creating_then_creates_mapping(
            self):
        destination_row = self.create_user_func_key()
        template = self.build_template_with_key(
            FuncKeyDestUser(user_id=destination_row.user_id))

        result = dao.create(template)

        self.assert_mapping_has_destination('user', destination_row)
        assert_that(result.keys[1].id, equal_to(destination_row.func_key_id))
コード例 #5
0
ファイル: test_dao.py プロジェクト: wazo-platform/xivo-dao
    def test_given_func_key_removed_when_editing_then_removes_func_key(self):
        destination_row = self.create_user_func_key()
        template = self.prepare_template(
            destination_row, FuncKeyDestUser(user_id=destination_row.user_id))

        template.keys = {}

        dao.edit(template)

        self.assert_template_empty(template.id)
コード例 #6
0
ファイル: test_dao.py プロジェクト: wazo-platform/xivo-dao
    def test_given_multi_template_is_associated_to_user_when_deleting_template(
            self):
        user = self.add_user()
        template = self.build_template_with_key(
            FuncKeyDestUser(user_id=user.id))
        dao.create(template)

        template = self.build_template_with_key(
            FuncKeyDestUser(user_id=user.id))
        dao.create(template)

        template = self.build_template_with_key(
            FuncKeyDestUser(user_id=user.id))
        dao.create(template)

        dao.delete(template)

        dest_user_count = (self.session.query(FuncKeyDestUser).filter(
            FuncKeyDestUser.user_id == user.id).count())
        assert_that(dest_user_count, equal_to(1))
コード例 #7
0
ファイル: test_dao.py プロジェクト: wazo-platform/xivo-dao
    def test_given_template_is_public_then_func_keys_are_inherited(self):
        destination_row = self.create_user_func_key()
        expected = self.prepare_template(
            destination_row,
            FuncKeyDestUser(user_id=destination_row.user_id),
            private=False)
        expected.keys[1].inherited = True

        result = dao.get(expected.id)

        assert_that(expected, equal_to(result))
コード例 #8
0
ファイル: test_dao.py プロジェクト: wazo-platform/xivo-dao
    def test_given_template_has_func_key_when_deleting_then_deletes_mappings(
            self):
        destination_row = self.create_user_func_key()
        template = self.prepare_template(
            destination_row, FuncKeyDestUser(user_id=destination_row.user_id))

        dao.delete(template)

        count = (self.session.query(FuncKeyMapping).filter(
            FuncKeyMapping.template_id == template.id).count())

        assert_that(count, equal_to(0))
コード例 #9
0
ファイル: test_dao.py プロジェクト: wazo-platform/xivo-dao
    def test_given_template_has_func_key_when_creating_then_blf_is_activated_by_default(
            self):
        destination_row = self.create_user_func_key()
        template = self.build_template_with_key(
            FuncKeyDestUser(user_id=destination_row.user_id))

        dao.create(template)

        mapping_row = (self.session.query(FuncKeyMapping).filter(
            FuncKeyMapping.func_key_id == destination_row.func_key_id).first())

        assert_that(mapping_row.blf, equal_to(True))
コード例 #10
0
    def find_or_create(self, destination):
        destination_row = (self.session.query(FuncKeyDestUser).filter(
            FuncKeyDestUser.user_id == destination.user_id).first())

        if not destination_row:
            func_key_row = self.create_func_key(self.TYPE_ID,
                                                self.DESTINATION_TYPE_ID)
            destination_row = FuncKeyDestUser(func_key_id=func_key_row.id,
                                              user_id=destination.user_id)
            self.session.add(destination_row)
            self.session.flush()

        return destination_row
コード例 #11
0
ファイル: test_dao.py プロジェクト: wazo-platform/xivo-dao
    def test_given_func_key_modified_when_editing_then_updates_func_key(self):
        destination_row = self.create_user_func_key()
        template = self.prepare_template(
            destination_row, FuncKeyDestUser(user_id=destination_row.user_id))

        template.keys[1].blf = False
        template.keys[1].label = 'mylabel'

        dao.edit(template)

        mapping = (self.session.query(FuncKeyMapping).filter(
            FuncKeyMapping.template_id == template.id).first())

        assert_that(mapping.blf, equal_to(False))
        assert_that(mapping.label, equal_to('mylabel'))
        assert_that(mapping.position, equal_to(1))
コード例 #12
0
ファイル: test_dao.py プロジェクト: wazo-platform/xivo-dao
    def test_given_destination_replaced_when_editing_then_replaces_destination(
            self):
        first_destination_row = self.create_user_func_key()
        updated_destination_row = self.create_queue_func_key()

        template = self.prepare_template(
            first_destination_row,
            FuncKeyDestUser(user_id=first_destination_row.user_id))

        updated_destination = FuncKeyDestQueue(
            queue_id=updated_destination_row.queue_id)
        template.keys[1].destination = updated_destination

        dao.edit(template)

        mapping = (self.session.query(FuncKeyMapping).filter(
            FuncKeyMapping.template_id == template.id).first())

        assert_that(mapping.func_key_id,
                    equal_to(updated_destination_row.func_key_id))
        assert_that(mapping.destination_type_id,
                    equal_to(updated_destination_row.destination_type_id))
        assert_that(mapping.position, equal_to(1))