Beispiel #1
0
def create_submission(userid, title="", rating=ratings.GENERAL.code, unixtime=arrow.get(1),
                      description="", folderid=None, subtype=0, settings=None):
    """ Creates a new submission, and returns its ID. """
    submission = add_entity(content.Submission(
        userid=userid, rating=rating, title=title, unixtime=unixtime, content=description,
        folderid=folderid, subtype=subtype, sorttime=arrow.get(0), settings=settings))
    return submission.submitid
Beispiel #2
0
def test_user_of_age_can_not_use_rating(age, rating):
    """
    Various age/rating combinations are invalid and do raise an exception.
    """
    user = user_with_age(age)
    sub = content.Submission(owner=user)
    with pytest.raises(exceptions.RatingExceeded):
        sub.rating = rating
Beispiel #3
0
def test_user_of_age_can_use_rating(age, rating):
    """
    Various age/rating combinations are valid and don't raise an exception.
    """
    user = user_with_age(age)
    sub = content.Submission(owner=user)
    sub.rating = rating
    assert sub.rating == rating
Beispiel #4
0
def test_warn_on_rating_assignment_with_no_owner(recwarn):
    """
    A warning is emitted if the rating is set on a submission before the owner
    is set.
    """
    sub = content.Submission()
    sub.rating = ratings.GENERAL
    warning = recwarn.pop(RuntimeWarning)
    assert warning.message.args[
        0] == 'tried to set the rating on a Submission without an owner'
Beispiel #5
0
def make_submission(db, settings=()):
    """
    Create a new submission.

    A new user is also created to be the owner of the submission. Both the user
    objects and the submission object are added to the session.

    Returns:
        Submission: The Submission object created.
    """
    owner = make_user(db)
    sub = content.Submission(
        owner=owner, title='', content='', subtype=1, rating=ratings.GENERAL,
        unixtime=arrow.get(0), sorttime=arrow.get(0), settings=None)
    if settings:
        sub.settings.mutable_settings.update(settings)
    db.add(sub)
    db.flush()
    return sub