def test_get_expired_disabled(db):
    """Test get first active with future date."""
    row = Ann(**announcements['expired'])
    db.session.add(row)
    row = Ann(**announcements['disabled'])
    db.session.add(row)
    db.session.commit()

    assert Ann.get_for('/') is None
    assert Ann.get_for('/other') is None
    assert Ann.get_for('/deposit') is None
def test_get_with_specific_path_date(db):
    """Test get first active with specific path and date."""
    row = Ann(**announcements['disabled'])
    db.session.add(row)
    row = Ann(**announcements['deposit_only'])
    db.session.add(row)
    db.session.commit()

    assert Ann.get_for('/deposit').message == 'deposit_only'
    assert Ann.get_for('/deposit/other').message == 'deposit_only'
    assert Ann.get_for('/') is None
    assert Ann.get_for('/other') is None
def test_get_with_path_date(db):
    """Test get first active with with path and date."""
    row = Ann(**announcements['everywhere'])
    db.session.add(row)
    row = Ann(**announcements['with_end_date'])
    db.session.add(row)
    row = Ann(**announcements['disabled'])
    db.session.add(row)
    db.session.commit()

    assert Ann.get_for('/').message == 'everywhere'
    assert Ann.get_for('/deposit').message == 'everywhere'
Beispiel #4
0
def get_announcement():
    """."""
    path = request.args.get('pathname', None)

    result = {}
    if path:
        first = Announcement.get_for(path)
        if first:
            result = {'message': first.message, 'style': first.style}

    return jsonify(result)
def test_disable_expired(db):
    """Test clean up old announcement but still active."""
    row = Ann(**announcements['everywhere'])
    db.session.add(row)
    row = Ann(**announcements['expired'])
    db.session.add(row)
    row = Ann(**announcements['with_end_date'])
    db.session.add(row)
    row = Ann(**announcements['sub_deposit_only'])
    db.session.add(row)
    db.session.commit()

    assert Ann.query.filter(Ann.active.is_(True)).count() == 4

    Ann.disable_expired()

    assert Ann.query.filter(Ann.active.is_(True)).count() == 3
    anns = Ann.query.all()
    assert anns[0].message == 'everywhere'
    assert anns[1].message == 'with_end_date'
    assert anns[2].message == 'sub_deposit_only'