def testApiKeyModel(self): dal = EmptyDal() model = ApiKeyModel(dal, None) has_quota = model.has_available_quota("NobodysHashedKey", 1) self.assertFalse(has_quota) # Should silently succeed if no matching key is found model.subtract_quota("NobodysHashedKey", 1) self.assertFalse(dal.subtract_called)
def testModel(self): dal = CustomDal() model = ApiKeyModel(dal, None) yesterday = date.today() - timedelta(days=1) dal.insert_api_key( "*****@*****.**", "JacksHashedKey", yesterday, remaining_quota=0) model.maybe_reset_available_quota("JacksHashedKey") details = dal.get_key_details()
def requestkeypost(dal, mailer): """Handle submit of form where user can request an API key.""" email = request.form["email"] email_regex = re.compile(r"[^\s]+@[^\s]+\.[^\s]+") if not email_regex.match(email): return render_template("web/invalidemail.html") model = ApiKeyModel(dal, mailer) if model.has_api_key(email): return render_template("web/alreadyhavekey.html") model.create_and_send_api_key(email) return render_template("web/requestedkey.html")