Ejemplo n.º 1
0
def test_get_tag_siblings_for_used_with_others(tag_factory, post_factory):
    tag1 = tag_factory(names=['t1'])
    tag2 = tag_factory(names=['t2'])
    post = post_factory()
    post.tags = [tag1, tag2]
    db.session.add_all([post, tag1, tag2])
    db.session.flush()
    _assert_tag_siblings(tags.get_tag_siblings(tag1), [('t2', 1)])
    _assert_tag_siblings(tags.get_tag_siblings(tag2), [('t1', 1)])
Ejemplo n.º 2
0
def test_get_tag_siblings_for_used_with_others(tag_factory, post_factory):
    tag1 = tag_factory(names=['t1'])
    tag2 = tag_factory(names=['t2'])
    post = post_factory()
    post.tags = [tag1, tag2]
    db.session.add_all([post, tag1, tag2])
    db.session.flush()
    _assert_tag_siblings(tags.get_tag_siblings(tag1), [('t2', 1)])
    _assert_tag_siblings(tags.get_tag_siblings(tag2), [('t1', 1)])
Ejemplo n.º 3
0
def test_get_tag_siblings_for_used_alone(tag_factory, post_factory):
    tag = tag_factory(names=['tag'])
    post = post_factory()
    post.tags = [tag]
    db.session.add_all([post, tag])
    db.session.flush()
    _assert_tag_siblings(tags.get_tag_siblings(tag), [])
Ejemplo n.º 4
0
def test_get_tag_siblings_for_used_alone(tag_factory, post_factory):
    tag = tag_factory(names=['tag'])
    post = post_factory()
    post.tags = [tag]
    db.session.add_all([post, tag])
    db.session.flush()
    _assert_tag_siblings(tags.get_tag_siblings(tag), [])
Ejemplo n.º 5
0
def test_get_tag_siblings_used_for_multiple_others(tag_factory, post_factory):
    tag1 = tag_factory(names=['t1'])
    tag2 = tag_factory(names=['t2'])
    tag3 = tag_factory(names=['t3'])
    post1 = post_factory()
    post2 = post_factory()
    post3 = post_factory()
    post4 = post_factory()
    post1.tags = [tag1, tag2, tag3]
    post2.tags = [tag1, tag3]
    post3.tags = [tag2]
    post4.tags = [tag2]
    db.session.add_all([post1, post2, post3, post4, tag1, tag2, tag3])
    db.session.flush()
    _assert_tag_siblings(tags.get_tag_siblings(tag1), [('t3', 2), ('t2', 1)])
    _assert_tag_siblings(tags.get_tag_siblings(tag2), [('t1', 1), ('t3', 1)])
    # even though tag2 is used more widely, tag1 is more relevant to tag3
    _assert_tag_siblings(tags.get_tag_siblings(tag3), [('t1', 2), ('t2', 1)])
Ejemplo n.º 6
0
def test_get_tag_siblings_used_for_multiple_others(tag_factory, post_factory):
    tag1 = tag_factory(names=['t1'])
    tag2 = tag_factory(names=['t2'])
    tag3 = tag_factory(names=['t3'])
    post1 = post_factory()
    post2 = post_factory()
    post3 = post_factory()
    post4 = post_factory()
    post1.tags = [tag1, tag2, tag3]
    post2.tags = [tag1, tag3]
    post3.tags = [tag2]
    post4.tags = [tag2]
    db.session.add_all([post1, post2, post3, post4, tag1, tag2, tag3])
    db.session.flush()
    _assert_tag_siblings(tags.get_tag_siblings(tag1), [('t3', 2), ('t2', 1)])
    _assert_tag_siblings(tags.get_tag_siblings(tag2), [('t1', 1), ('t3', 1)])
    # even though tag2 is used more widely, tag1 is more relevant to tag3
    _assert_tag_siblings(tags.get_tag_siblings(tag3), [('t1', 2), ('t2', 1)])
Ejemplo n.º 7
0
def get_tag_siblings(ctx, params):
    auth.verify_privilege(ctx.user, 'tags:view')
    tag = tags.get_tag_by_name(params['tag_name'])
    result = tags.get_tag_siblings(tag)
    serialized_siblings = []
    for sibling, occurrences in result:
        serialized_siblings.append({
            'tag': _serialize(ctx, sibling),
            'occurrences': occurrences
        })
    return {'results': serialized_siblings}
Ejemplo n.º 8
0
 def get(self, ctx, tag_name):
     auth.verify_privilege(ctx.user, 'tags:view')
     tag = tags.get_tag_by_name(tag_name)
     result = tags.get_tag_siblings(tag)
     serialized_siblings = []
     for sibling, occurrences in result:
         serialized_siblings.append({
             'tag': tags.serialize_tag(sibling),
             'occurrences': occurrences
         })
     return {'siblings': serialized_siblings}
Ejemplo n.º 9
0
 def get(self, ctx, tag_name):
     auth.verify_privilege(ctx.user, 'tags:view')
     tag = tags.get_tag_by_name(tag_name)
     result = tags.get_tag_siblings(tag)
     serialized_siblings = []
     for sibling, occurrences in result:
         serialized_siblings.append({
             'tag': tags.serialize_tag(sibling),
             'occurrences': occurrences
         })
     return {'siblings': serialized_siblings}
Ejemplo n.º 10
0
def get_tag_siblings(
        ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    auth.verify_privilege(ctx.user, 'tags:view')
    tag = _get_tag(params)
    result = tags.get_tag_siblings(tag)
    serialized_siblings = []
    for sibling, occurrences in result:
        serialized_siblings.append({
            'tag': _serialize(ctx, sibling),
            'occurrences': occurrences
        })
    return {'results': serialized_siblings}
Ejemplo n.º 11
0
def get_tag_siblings(ctx: rest.Context, params: Dict[str,
                                                     str]) -> rest.Response:
    auth.verify_privilege(ctx.user, "tags:view")
    tag = _get_tag(params)
    result = tags.get_tag_siblings(tag)
    serialized_siblings = []
    for sibling, occurrences in result:
        serialized_siblings.append({
            "tag": _serialize(ctx, sibling),
            "occurrences": occurrences
        })
    return {"results": serialized_siblings}
Ejemplo n.º 12
0
def test_get_tag_siblings_for_unused(tag_factory):
    tag = tag_factory(names=['tag'])
    db.session.add(tag)
    db.session.flush()
    _assert_tag_siblings(tags.get_tag_siblings(tag), [])
Ejemplo n.º 13
0
def test_get_tag_siblings_for_unused(tag_factory):
    tag = tag_factory(names=['tag'])
    db.session.add(tag)
    db.session.flush()
    _assert_tag_siblings(tags.get_tag_siblings(tag), [])