def test_create_directory_out_of_quota(flask_client): user = login(flask_client) for i in range(MAX_NB_DIRECTORY): Directory.create(name=f"test{i}", user_id=user.id, commit=True) assert Directory.count() == MAX_NB_DIRECTORY flask_client.post( url_for("dashboard.directory"), data={"form-name": "create", "name": "test"}, follow_redirects=True, ) # no new directory is created assert Directory.count() == MAX_NB_DIRECTORY
def compute_metric2() -> Metric2: now = arrow.now() _24h_ago = now.shift(days=-1) nb_referred_user_paid = 0 for user in User.filter(User.referral_id.isnot(None)): if user.is_paid(): nb_referred_user_paid += 1 return Metric2.create( date=now, # user stats nb_user=User.count(), nb_activated_user=User.filter_by(activated=True).count(), # subscription stats nb_premium=Subscription.filter( Subscription.cancelled.is_(False)).count(), nb_cancelled_premium=Subscription.filter( Subscription.cancelled.is_(True)).count(), # todo: filter by expires_date > now nb_apple_premium=AppleSubscription.count(), nb_manual_premium=ManualSubscription.filter( ManualSubscription.end_at > now, ManualSubscription.is_giveaway.is_(False), ).count(), nb_coinbase_premium=CoinbaseSubscription.filter( CoinbaseSubscription.end_at > now).count(), # referral stats nb_referred_user=User.filter(User.referral_id.isnot(None)).count(), nb_referred_user_paid=nb_referred_user_paid, nb_alias=Alias.count(), # email log stats nb_forward_last_24h=EmailLog.filter( EmailLog.created_at > _24h_ago).filter_by(bounced=False, is_spam=False, is_reply=False, blocked=False).count(), nb_bounced_last_24h=EmailLog.filter( EmailLog.created_at > _24h_ago).filter_by(bounced=True).count(), nb_total_bounced_last_24h=Bounce.filter( Bounce.created_at > _24h_ago).count(), nb_reply_last_24h=EmailLog.filter( EmailLog.created_at > _24h_ago).filter_by(is_reply=True).count(), nb_block_last_24h=EmailLog.filter( EmailLog.created_at > _24h_ago).filter_by(blocked=True).count(), # other stats nb_verified_custom_domain=CustomDomain.filter_by( verified=True).count(), nb_subdomain=CustomDomain.filter_by(is_sl_subdomain=True).count(), nb_directory=Directory.count(), nb_deleted_directory=DeletedDirectory.count(), nb_deleted_subdomain=DeletedSubdomain.count(), nb_app=Client.count(), commit=True, )