Esempio n. 1
0
def create_submission_tag(tagid, targetid, settings=None):
    db = d.connect()
    db.add(
        content.SubmissionTag(tagid=tagid,
                              targetid=targetid,
                              settings=settings))
    db.flush()
Esempio n. 2
0
def create_submission_tag(tagid, targetid, settings=None):
    db = d.connect()
    db.add(
        content.SubmissionTag(tagid=tagid, targetid=targetid, settings=settings))
    db.flush()

    db.execute(
        'INSERT INTO submission_tags (submitid, tags) VALUES (:submission, ARRAY[:tag]) '
        'ON CONFLICT (submitid) DO UPDATE SET tags = submission_tags.tags || :tag',
        {'submission': targetid, 'tag': tagid})
Esempio n. 3
0
def test_set_tags_with_extant_tags(db):
    """
    ``set_tags`` will use extant Tag rows.
    """
    sub = make_submission(db)
    db.add_all([
        content.SubmissionTag(tag=t, targetid=sub.submitid)
        for t in ['spam', 'eggs']
    ])
    db.add(content.Tag(title='sausage'))
    db.flush()
    sub.set_tags(['spam', 'eggs', 'sausage'])
    db.flush()
    all_tags = content.SubmissionTag.query.all()
    assert sorted(t.tag for t in all_tags) == ['eggs', 'sausage', 'spam']
Esempio n. 4
0
def test_set_tags(db, tags_before, tags_after, done_by_artist):
    """
    ``set_tags`` will add and remove tags as appropriate on a submission.
    """
    sub = make_submission(db)
    tags_before = convert_artist_tags(tags_before)
    tags_after = convert_artist_tags(tags_after)
    db.add_all([
        content.SubmissionTag(tag=t, settings=s, targetid=sub.submitid)
        for t, s in tags_before
    ])
    db.flush()
    sub.set_tags([t for t, _ in tags_after], done_by_artist=done_by_artist)
    db.flush()
    all_tags = content.SubmissionTag.query.all()
    assert sorted((t.tag, t.settings.settings) for t in all_tags) == sorted(
        (t, s.settings) for t, s in tags_after)
Esempio n. 5
0
def create_submission_tag(tagid, targetid, settings=None):
    db = d.connect()
    db.add(
        content.SubmissionTag(tagid=tagid,
                              targetid=targetid,
                              settings=settings))
    db.flush()

    try:
        db.execute(
            'INSERT INTO submission_tags (submitid, tags) VALUES (:submission, ARRAY[:tag])',
            {
                'submission': targetid,
                'tag': tagid
            })
    except exc.DBAPIError:
        result = db.execute(
            'UPDATE submission_tags SET tags = tags || :tag WHERE submitid = :submission',
            {
                'submission': targetid,
                'tag': tagid
            })

        assert result.rowcount == 1