Пример #1
0
    def test_gets_by_tag_id(self):
        name = "tag"
        author = "test"
        type = target_type = TAG_TYPE_PROJECT_ISSUE
        target_id = 3
        tag_name = TagName.add(name, author, target_type, target_id)
        assert tag_name.name == name

        author_id = 2
        type_id1 = 1
        type_id2 = 2
        type_id3 = 3
        tag1 = Tag.add(tag_name.id, type, type_id1, author_id, target_id)
        tag2 = Tag.add(tag_name.id, type, type_id2, author_id, target_id)
        tag3 = Tag.add(tag_name.id, type, type_id3, author_id, target_id)

        assert tag1.tag_id == tag2.tag_id == tag3.tag_id

        tags = Tag.gets_by_tag_id(tag_name.id)

        assert len(tags) == 3

        type_ids = [t.type_id for t in tags]
        assert type_id1 in type_ids
        assert type_id2 in type_ids
        assert type_id3 in type_ids
Пример #2
0
    def test_gets_by_tag_id(self):
        name = "tag"
        author = "test"
        type = target_type = TAG_TYPE_PROJECT_ISSUE
        target_id = 3
        tag_name = TagName.add(name, author, target_type, target_id)
        assert tag_name.name == name

        author_id = 2
        type_id1 = 1
        type_id2 = 2
        type_id3 = 3
        tag1 = Tag.add(tag_name.id, type, type_id1, author_id, target_id)
        tag2 = Tag.add(tag_name.id, type, type_id2, author_id, target_id)
        tag3 = Tag.add(tag_name.id, type, type_id3, author_id, target_id)

        assert tag1.tag_id == tag2.tag_id == tag3.tag_id

        tags = Tag.gets_by_tag_id(tag_name.id)

        assert len(tags) == 3

        type_ids = [t.type_id for t in tags]
        assert type_id1 in type_ids
        assert type_id2 in type_ids
        assert type_id3 in type_ids
Пример #3
0
 def test_delete(self):
     tag1 = Tag.add(1, TAG_TYPE_PROJECT_ISSUE, 1, 'test1', 2)
     tag2 = Tag.add(2, TAG_TYPE_PROJECT_ISSUE, 1, 'test2', 2)
     tag3 = Tag.add(1, TAG_TYPE_PROJECT_ISSUE, 2, 'test3', 2)
     tag2.delete()
     tag = Tag.get_by_type_id_and_tag_id(TAG_TYPE_PROJECT_ISSUE, 1, 2)
     assert tag is None
Пример #4
0
 def test_delete(self):
     tag1 = Tag.add(1, TAG_TYPE_PROJECT_ISSUE, 1, 'test1', 2)
     tag2 = Tag.add(2, TAG_TYPE_PROJECT_ISSUE, 1, 'test2', 2)
     tag3 = Tag.add(1, TAG_TYPE_PROJECT_ISSUE, 2, 'test3', 2)
     tag2.delete()
     tag = Tag.get_by_type_id_and_tag_id(TAG_TYPE_PROJECT_ISSUE, 1, 2)
     assert tag is None
Пример #5
0
 def add_tag(self, tag, type, target_id, author=None):
     author_id = author if author else self.creator_id
     # create tag if not exists
     tag_name = TagName.get_by_name_and_target_id(tag, type, target_id)
     if not tag_name:
         tag_name = TagName.add(tag, author_id, type, target_id)
     if not tag_name:
         return
     # add tag to issue if not already be added
     issue_tag = Tag.get_by_type_id_and_tag_id(
         type, self.issue_id, tag_name.id)
     if issue_tag:
         return
     Tag.add_to_issue(
         tag_name.id, type, self.issue_id, author_id, target_id)
Пример #6
0
 def add_tag(self, tag, type, target_id, author=None):
     author_id = author if author else self.creator_id
     # create tag if not exists
     tag_name = TagName.get_by_name_and_target_id(tag, type, target_id)
     if not tag_name:
         tag_name = TagName.add(tag, author_id, type, target_id)
     if not tag_name:
         return
     # add tag to issue if not already be added
     issue_tag = Tag.get_by_type_id_and_tag_id(type, self.issue_id,
                                               tag_name.id)
     if issue_tag:
         return
     Tag.add_to_issue(tag_name.id, type, self.issue_id, author_id,
                      target_id)
Пример #7
0
    def test_get(self):
        tag1 = Tag.add(1, TAG_TYPE_PROJECT_ISSUE, 1, 'test1', 3)
        tag2 = Tag.add(2, TAG_TYPE_PROJECT_ISSUE, 1, 'test2', 3)
        tag3 = Tag.add(1, TAG_TYPE_PROJECT_ISSUE, 2, 'test3', 3)

        tag = Tag.get_by_type_id_and_tag_id(TAG_TYPE_PROJECT_ISSUE, 1, 1)
        assert isinstance(tag, Tag)
        assert tag.tag_id == 1
        assert tag.type == TAG_TYPE_PROJECT_ISSUE
        assert tag.type_id == 1
        assert tag.author_id == 'test1'
        assert tag.target_id == 3

        tags = Tag.gets_by_issue_id(1, TAG_TYPE_PROJECT_ISSUE)
        assert all([isinstance(t, Tag) for t in tags])
        assert len(tags) == 2
Пример #8
0
    def _q_index(self, request):
        if self.name == 'issues':
            return request.redirect(self.team.url)

        user = request.user
        team = self.team
        page = request.get_form_var('page', 1)
        state = request.get_form_var('state', 'open')
        order = get_order_type(request, 'fair_issues_order')

        all_issues = []

        selected_tag_names = request.get_form_var('tags', '')
        if selected_tag_names:
            selected_tag_names = selected_tag_names.split(',')
            issue_ids = Tag.get_type_ids_by_names_and_target_id(
                TAG_TYPE_FAIR_ISSUE,
                selected_tag_names,
                team.id)
            all_issues = self.cls.gets_by_issue_ids(issue_ids, state)
        else:
            all_issues = self.cls.gets_by_target(team.id, state, order=order)

        n_team_issue = len(all_issues)
        show_tags = team.get_group_tags(selected_tag_names)
        is_closed_tab = None if state == 'open' else True
        n_pages = 1
        return st('/fair.html', **locals())
Пример #9
0
    def _q_index(self, request):
        user = request.user
        team = self.team
        page = request.get_form_var('page', 1)
        state = request.get_form_var("state", "open")
        order = get_order_type(request, 'team_issues_order')

        team_issues = []

        selected_tag_names = request.get_form_var('tags', '')
        if selected_tag_names:
            selected_tag_names = selected_tag_names.split(',')
            issue_ids = Tag.get_type_ids_by_names_and_target_id(
                TAG_TYPE_TEAM_ISSUE,
                selected_tag_names,
                team.id)
            team_issues = self.cls.gets_by_issue_ids(issue_ids, state)
        else:
            team_issues = self.cls.gets_by_target(team.id, state, order=order)

        n_team_issue = len(team_issues)
        show_tags = team.get_group_tags(selected_tag_names)
        is_closed_tab = None if state == "open" else True
        n_pages = 1
        # TODO: 分页
        return st('issue/team_issues.html', **locals())
Пример #10
0
 def test_add(self):
     tag = Tag.add(1, 1, 1, 'test', 3)
     assert tag.tag_id == 1
     assert tag.type == 1
     assert tag.type_id == 1
     assert tag.author_id == 'test'
     assert tag.target_id == 3
Пример #11
0
 def test_add(self):
     tag = Tag.add(1, 1, 1, 'test', 3)
     assert tag.tag_id == 1
     assert tag.type == 1
     assert tag.type_id == 1
     assert tag.author_id == 'test'
     assert tag.target_id == 3
Пример #12
0
    def _q_index(self, request):
        if self.name == 'issues':
            return request.redirect(self.team.url)

        user = request.user
        team = self.team
        page = request.get_form_var('page', 1)
        state = request.get_form_var('state', 'open')
        order = get_order_type(request, 'fair_issues_order')

        all_issues = []

        selected_tag_names = request.get_form_var('tags', '')
        if selected_tag_names:
            selected_tag_names = selected_tag_names.split(',')
            issue_ids = Tag.get_type_ids_by_names_and_target_id(
                TAG_TYPE_FAIR_ISSUE,
                selected_tag_names,
                team.id)
            all_issues = self.cls.gets_by_issue_ids(issue_ids, state)
        else:
            all_issues = self.cls.gets_by_target(team.id, state, order=order)

        n_team_issue = len(all_issues)
        show_tags = team.get_group_tags(selected_tag_names)
        is_closed_tab = None if state == 'open' else True
        n_pages = 1
        return st('/fair.html', **locals())
Пример #13
0
 def remove_tag(self, tag, type, target_id):
     # check if tag exists
     tag_name = TagName.get_by_name_and_target_id(tag, type, target_id)
     if not tag_name:
         return
     # delete tag relationship if exists
     issue_tag = Tag.get_by_type_id_and_tag_id(
         type, self.issue_id, tag_name.id)
     if issue_tag:
         issue_tag.delete()
Пример #14
0
 def remove_tag(self, tag, type, target_id):
     # check if tag exists
     tag_name = TagName.get_by_name_and_target_id(tag, type, target_id)
     if not tag_name:
         return
     # delete tag relationship if exists
     issue_tag = Tag.get_by_type_id_and_tag_id(type, self.issue_id,
                                               tag_name.id)
     if issue_tag:
         issue_tag.delete()
Пример #15
0
    def test_get(self):
        tags = Tag.gets()
        for tag in tags:
            tag.delete()
        Tag.add(1, TAG_TYPE_PROJECT_ISSUE, 1, 'test1', 3)
        Tag.add(2, TAG_TYPE_PROJECT_ISSUE, 1, 'test2', 3)
        Tag.add(1, TAG_TYPE_PROJECT_ISSUE, 2, 'test3', 3)

        tag = Tag.get_by_type_id_and_tag_id(TAG_TYPE_PROJECT_ISSUE, 1, 1)
        assert isinstance(tag, Tag)
        assert tag.tag_id == 1
        assert tag.type == TAG_TYPE_PROJECT_ISSUE
        assert tag.type_id == 1
        assert tag.author_id == 'test1'
        assert tag.target_id == 3

        tags = Tag.gets_by_issue_id(1, TAG_TYPE_PROJECT_ISSUE)
        assert all([isinstance(t, Tag) for t in tags])
        assert len(tags) == 2
Пример #16
0
    def test_get_type_ids_by_names_and_target_id(self):
        name1 = "tag"
        author = "test"
        type = target_type = TAG_TYPE_PROJECT_ISSUE
        target_id = 3
        tag_name1 = TagName.add(name1, author, target_type, target_id)
        assert tag_name1.name == name1

        author_id = 2
        type_id1 = 1
        type_id2 = 2
        type_id3 = 3
        tag1 = Tag.add(tag_name1.id, type, type_id1, author_id, target_id)
        tag2 = Tag.add(tag_name1.id, type, type_id2, author_id, target_id)
        tag3 = Tag.add(tag_name1.id, type, type_id3, author_id, target_id)

        assert tag1.tag_id == tag2.tag_id == tag3.tag_id

        type_ids = Tag.get_type_ids_by_names_and_target_id(
            type, [name1], target_id)

        assert len(type_ids) == 3
        assert type_id1 in type_ids
        assert type_id2 in type_ids
        assert type_id3 in type_ids

        name2 = "tag2"
        tag_name2 = TagName.add(name2, author, target_type, target_id)
        assert tag_name2.name == name2

        type_id4 = 4
        tag3 = Tag.add(tag_name2.id, type, type_id3, author_id, target_id)
        tag4 = Tag.add(tag_name2.id, type, type_id4, author_id, target_id)

        type_ids = Tag.get_type_ids_by_names_and_target_id(
            type, [name1, name2], target_id)

        print type_ids
        assert len(type_ids) == 1
        assert type_id3 in type_ids
Пример #17
0
    def test_get_type_ids_by_names_and_target_id(self):
        name1 = "tag"
        author = "test"
        type = target_type = TAG_TYPE_PROJECT_ISSUE
        target_id = 3
        tag_name1 = TagName.add(name1, author, target_type, target_id)
        assert tag_name1.name == name1

        author_id = 2
        type_id1 = 1
        type_id2 = 2
        type_id3 = 3
        tag1 = Tag.add(tag_name1.id, type, type_id1, author_id, target_id)
        tag2 = Tag.add(tag_name1.id, type, type_id2, author_id, target_id)
        tag3 = Tag.add(tag_name1.id, type, type_id3, author_id, target_id)

        assert tag1.tag_id == tag2.tag_id == tag3.tag_id

        type_ids = Tag.get_type_ids_by_names_and_target_id(
            type, [name1], target_id)

        assert len(type_ids) == 3
        assert type_id1 in type_ids
        assert type_id2 in type_ids
        assert type_id3 in type_ids

        name2 = "tag2"
        tag_name2 = TagName.add(name2, author, target_type, target_id)
        assert tag_name2.name == name2

        type_id4 = 4
        tag3 = Tag.add(tag_name2.id, type, type_id3, author_id, target_id)
        tag4 = Tag.add(tag_name2.id, type, type_id4, author_id, target_id)

        type_ids = Tag.get_type_ids_by_names_and_target_id(
            type, [name1, name2], target_id)

        print type_ids
        assert len(type_ids) == 1
        assert type_id3 in type_ids
Пример #18
0
 def tags(self):
     return Tag.gets_by_issue_id(self.issue_id, self.tag_type)
Пример #19
0
 def tags(self):
     return Tag.gets_by_issue_id(self.issue_id, self.tag_type)