def test_user_rss_url_etag(session, client): entries = EntryFactory.create_batch(5) author1 = AuthorFactory() author1.entries.extend(entries) user = UserFactory(active=True) user.userfeed.private = False sub1 = Subscription(user=user, author=author1) sub1.save() h = Headers() h.add("If-None-Match", None) response1 = client.get(url_for("users.user_feed", user_id=user.id), headers=h) assert response1.status_code == 200 etag = response1.headers.get("ETag") assert response1.data assert ( response1.headers.get("Content-Type") == "application/atom+xml; charset=utf-8" ) h.add("If-None-Match", etag) response2 = client.get(url_for("users.user_feed", user_id=user.id), headers=h) assert response2.status_code == 304 etag2 = response2.headers.get("ETag") assert etag2 == etag assert not response2.data
def subscribe(author_id): """ Create a Subscription to an author """ author = Author.query.get_or_404(author_id) sub = ( db.session.query(Subscription) .filter( Subscription.user_id == current_user.id, Subscription.author_id == author.id ) .first() ) if not sub: sub = Subscription(user=current_user, author=author, active=True) app.logger.info("%s created", sub) else: sub.active = True app.logger.info("%s set to active", sub) if not sub.periods: sub.add_period(PERIOD.DAILY) sub.save() update_user_rss.send(bp, users=[current_user]) flash( f"Successfully created a {sub.period_string()} Email Subscription to {author.name}", ALERT.SUCCESS, ) return redirect_back("authors.authors")
def subscribe(author_id): author = Author.query.get_or_404(author_id) sub = Subscription.query.filter( Subscription.user_id == current_user.id, Subscription.author_id == author.id).first() if not sub: sub = Subscription(user=current_user, author=author, active=True) app.logger.info(u'Subscription {0} created'.format(sub)) else: sub.active = True app.logger.info(u'Subscription {0} set to active'.format(sub)) if not sub.periods: sub.add_period(PERIOD.DAILY) sub.save() flash(u'Successfully created a {0} Email Subscription to {1}'.format( sub.period_string(), author.name), ALERT.SUCCESS) return redirect_back('authors.authors')