Beispiel #1
0
 def subscribed(self, user):
     from models.user import UserSubscription
     try:
         UserSubscription.get(UserSubscription.user == user,
                              UserSubscription.subscription == self)
         return True
     except UserSubscription.DoesNotExist:
         return False
Beispiel #2
0
def test_user_subscriptions():
    seed_user = User.get()
    subscription = Subscription.get()

    # Query checking if the subscription is in the user.
    count_query = (UserSubscription.select()
                   .where(UserSubscription.user == seed_user,
                          UserSubscription.subscription == subscription))

    # Unsubscribe first (regardless of subscription).
    seed_user.unsubscribe(subscription)
    assert count_query.count() == 0
    assert subscription.num_subscribers() == 0

    # Resubscribe.
    seed_user.subscribe(subscription)
    assert count_query.count() == 1
    assert subscription.num_subscribers() == 1

    # Resubscribe again.
    seed_user.subscribe(subscription)
    assert count_query.count() == 1
    assert subscription.num_subscribers() == 1

    # Unsubscribe again.
    seed_user.unsubscribe(subscription)
    assert count_query.count() == 0
    assert subscription.num_subscribers() == 0
Beispiel #3
0
 def num_subscribers(self):
     from models.user import UserSubscription
     return (UserSubscription.select()
                             .where(UserSubscription.subscription == self)
                             .count())