本文整理汇总了Python中membership.Membership.get_by_hash方法的典型用法代码示例。如果您正苦于以下问题:Python Membership.get_by_hash方法的具体用法?Python Membership.get_by_hash怎么用?Python Membership.get_by_hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类membership.Membership
的用法示例。
在下文中一共展示了Membership.get_by_hash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_discount
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def test_discount(self):
# A unique number on all the giftcards.
serial = "1678"
# A "correct" hash, based on what the actual code does.
correct_hash = hashlib.sha1(serial + self.code).hexdigest()
correct_hash = re.sub("[a-f]", "", correct_hash)[:8]
gift_code = "1337" + serial + correct_hash
print "Using test gift code: %s" % (gift_code)
# Now try using this code.
user = Membership.get_by_hash(self.user_hash)
user.referrer = gift_code
user.put()
response = self.test_app.post("/account/" + self.user_hash,
self._TEST_PARAMS)
self.assertEqual(302, response.status_int)
# We should have a record of the used code.
codes = main.UsedCode.all().run()
for code in codes:
# We should only have one code in there.
self.assertEqual(gift_code, code.code)
self.assertEqual("[email protected]", code.email)
self.assertEqual("OK", code.extra)
user = Membership.get_by_hash(self.user_hash)
user.username = None
user.put()
# Try to use the same code again.
response = self.test_app.post("/account/" + self.user_hash,
self._TEST_PARAMS, expect_errors=True)
self.assertEqual(422, response.status_int)
self.assertIn("already been used", response.body)
# Now we should have individual records of the same code being used twice.
codes = main.UsedCode.all().run()
# Turn the iterator into a list.
codes = [code for code in codes]
self.assertEqual(gift_code, codes[0].code)
self.assertEqual(gift_code, codes[1].code)
self.assertEqual("[email protected]", codes[0].email)
self.assertEqual("[email protected]", codes[1].email)
if codes[0].extra == "OK":
# The other one should be the duplicate.
self.assertEqual("2nd+ attempt", codes[1].extra)
elif codes[0].extra == "2nd+ attempt":
# The other one should be the good one.
self.assertEqual("OK", codes[1].extra)
else:
fail("Got unexpected extra '%s'." % (codes[0].extra))
示例2: test_create_user
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def test_create_user(self):
response = self.test_app.post("/tasks/create_user", self.params)
self.assertEqual(200, response.status_int)
# Check that it's sending the right parameters to the domain app.
self.assertIn("username=testy.testerson", response.body)
self.assertIn("password=notasecret", response.body)
self.assertIn("first_name=Testy", response.body)
self.assertIn("last_name=Testerson", response.body)
user = Membership.get_by_hash(self.user_hash)
# Check that the user ended up with a username.
self.assertEqual("testy.testerson", user.username)
# Check that domain_user got set.
self.assertTrue(user.domain_user)
# Check that the password got cleared.
self.assertEqual(None, user.password)
# Check that it sent the right email.
messages = self.mail_stub.get_sent_messages(to="[email protected]")
self.assertEqual(1, len(messages))
# It should give the user this data.
body = str(messages[0].body)
self.assertIn(user.username, body)
示例3: get
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def get(self, hash):
member = Membership.get_by_hash(hash)
conf = Config()
if member:
success_html = urlfetch.fetch(conf.SUCCESS_HTML_URL).content
success_html = success_html.replace("joining!", "joining, %s!" % member.first_name)
is_prod = conf.is_prod
self.response.out.write(self.render("templates/success.html", locals()))
示例4: get
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def get(self, hash):
member = Membership.get_by_hash(hash)
c = Config()
if member:
success_html = urlfetch.fetch(SUCCESS_HTML_URL).content
success_html = success_html.replace('joining!', 'joining, %s!' % member.first_name)
is_prod = c.is_prod
self.response.out.write(render('templates/success.html', locals()))
示例5: test_retry_no_token
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def test_retry_no_token(self):
# Make a user with no token.
user = Membership.get_by_hash(self.user_hash)
user.spreedly_token=None
user.put()
# Try to create an account for this user.
response = self.test_app.post("/tasks/create_user", self.params)
self.assertEqual(200, response.status_int)
# We should have a new task now.
taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
tasks = taskqueue_stub.GetTasks("default")
self.assertEqual(1, len(tasks))
# The user shouldn't have a domain account yet.
user = Membership.get_by_hash(self.user_hash)
self.assertFalse(user.domain_user)
示例6: test_get
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def test_get(self):
query = urllib.urlencode({"plan": "newhive"})
response = self.test_app.get("/account/%s?%s" % (self.user_hash, query))
self.assertEqual(200, response.status_int)
# Our username should be templated in.
self.assertIn("testy.testerson", response.body)
user = Membership.get_by_hash(self.user_hash)
self.assertEqual("newhive", user.plan)
示例7: test_post
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def test_post(self):
query = urllib.urlencode(self._TEST_PARAMS)
response = self.test_app.post("/account/" + self.user_hash, query)
self.assertEqual(302, response.status_int)
user = Membership.get_by_hash(self.user_hash)
# We should be redirected to a personal spreedly page.
self.assertIn("subs.pinpayments.com", response.location)
self.assertIn(self.test_plan.plan_id, response.location)
self.assertIn(str(user.key().id()), response.location)
self.assertIn("testy.testerson", response.location)
# The account information should be in the datastore.
user = Membership.get_by_hash(self.user_hash)
self.assertEqual("testy.testerson", user.username)
self.assertEqual("notasecret", user.password)
# We shouldn't have a domain account yet.
self.assertFalse(user.domain_user)
示例8: test_already_active
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def test_already_active(self):
user = Membership.get_by_hash(self.user_hash)
user.status = "active"
user.put()
query = urllib.urlencode(self._TEST_PARAMS)
response = self.test_app.post("/account/" + self.user_hash, query)
self.assertEqual(302, response.status_int)
self.assertIn("success", response.location)
self.assertIn(self.user_hash, response.location)
示例9: test_bad_length_code
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def test_bad_length_code(self):
code = "133712345"
user = Membership.get_by_hash(self.user_hash)
user.referrer = code
user.put()
response = self.test_app.post("/account/" + self.user_hash,
self._TEST_PARAMS, expect_errors=True)
self.assertEqual(422, response.status_int)
self.assertIn("must be 16 digits", response.body)
示例10: test_invalid_code
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def test_invalid_code(self):
code = "1337424242424242"
user = Membership.get_by_hash(self.user_hash)
user.referrer = code
user.put()
response = self.test_app.post("/account/" + self.user_hash,
self._TEST_PARAMS, expect_errors=True)
self.assertEqual(422, response.status_int)
self.assertIn("code was invalid", response.body)
示例11: get
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def get(self, hash):
membership = Membership.get_by_hash(hash)
if not membership:
self.response.set_status(422)
self.response.out.write("Unknown member hash.")
logging.error("Could not find member with hash '%s'." % (hash))
return
# Save the plan they want.
plan = self.request.get("plan", "newfull")
membership.plan = plan
membership.put()
if ((membership.username and membership.password) and not \
membership.spreedly_token):
# We've filled out our account information, but we never started a
# subscription. (This could be reached by going back and trying to
# change our plan after we were already taken to the PinPayments
# page.) In this case, just pass them through to PinPayments.
query_str = urllib.urlencode({"first_name": membership.first_name,
"last_name": membership.last_name,
"email": membership.email,
"return_url": "http://%s/success/%s" % \
(self.request.host, membership.hash)})
self.redirect(membership.new_subscribe_url(query_str))
# steal this part to detect if they registered with hacker dojo email above
first_part = re.compile(r"[^\w]").sub("", membership.first_name.split(" ")[0]) # First word of first name
last_part = re.compile(r"[^\w]").sub("", membership.last_name)
if len(first_part)+len(last_part) >= 15:
last_part = last_part[0] # Just last initial
username = ".".join([first_part, last_part]).lower()
usernames = self.fetch_usernames()
if usernames == None:
# Error page is already rendered.
return
if username in usernames:
# Duplicate username. Use the first part of the email instead.
username = membership.email.split("@")[0].lower()
user_number = 0
base_username = username
while username in usernames:
# Still a duplicate. Add a number.
user_number += 1
username = "%s%d" % (base_username, user_number)
if self.request.get("pick_username"):
pick_username = True
account_url = str("/account/%s" % membership.hash)
self.response.out.write(self.render("templates/account.html", locals()))
示例12: post
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def post(self):
def fail(exception):
logging.error("CreateUserTask failed: %s" % exception)
mail.send_mail(sender=EMAIL_FROM,
to=INTERNAL_DEV_EMAIL,
subject="[%s] CreateUserTask failure" % APP_NAME,
body=str(exception))
def retry(countdown=3):
retries = int(self.request.get('retries', 0)) + 1
if retries <= 5:
taskqueue.add(url='/tasks/create_user', method='POST', countdown=countdown,
params={'hash': self.request.get('hash'), 'retries': retries})
else:
fail(Exception("Too many retries for %s" % self.request.get('hash')))
c = Config()
user_hash = self.request.get('hash')
membership = Membership.get_by_hash(user_hash)
if membership is None or membership.username:
return
if not membership.spreedly_token:
logging.warn("CreateUserTask: No spreedly token yet, retrying")
return retry(300)
try:
username, password = memcache.get(hashlib.sha1(membership.hash+c.SPREEDLY_APIKEY).hexdigest()).split(':')
except (AttributeError, ValueError):
return fail(Exception("Account information expired for %s" % membership.email))
try:
url = 'http://%s/users' % DOMAIN_HOST
payload = urllib.urlencode({
'username': username,
'password': password,
'first_name': membership.first_name,
'last_name': membership.last_name,
'secret': keymaster.get('api'),
})
logging.info("CreateUserTask: About to create user: "+username)
logging.info("CreateUserTask: URL: "+url)
logging.info("CreateUserTask: Payload: "+payload)
resp = urlfetch.fetch(url, method='POST', payload=payload, deadline=120)
membership.username = username
membership.put()
logging.warn("CreateUserTask: I think that worked: HTTP "+str(resp.status_code))
# Send the welcome email.
SuccessHandler.send_email(membership)
except urlfetch.DownloadError, e:
logging.warn("CreateUserTask: API response error or timeout, retrying")
return retry()
示例13: get
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def get(self, user_hash):
member = Membership.get_by_hash(user_hash)
if not member:
# Hash is invalid.
logging.error("Invalid hash '%s'." % (user_hash))
error = self.render("templates/error.html",
message="Invalid reactivation link.")
self.response.out.write(error)
self.response.set_status(422)
return
self._plan_switch_page(member)
示例14: test_already_entered
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def test_already_entered(self):
user = Membership.get_by_hash(self.user_hash)
user.username = "testy.testerson"
user.password = "notasecret"
user.spreedly_token = None
user.put()
response = self.test_app.get("/account/" + self.user_hash,
self._TEST_PARAMS)
# We should be redirected to a personal spreedly page.
self.assertEqual(302, response.status_int)
self.assertIn("subs.pinpayments.com", response.location)
self.assertIn(self.test_plan.plan_id, response.location)
self.assertIn(str(user.key().id()), response.location)
self.assertIn("testy.testerson", response.location)
示例15: test_trivial_failures
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import get_by_hash [as 别名]
def test_trivial_failures(self):
# Give it a bad hash.
bad_params = {"hash": "badhash"}
response = self.test_app.post("/tasks/create_user", bad_params,
expect_errors=True)
self.assertEqual(422, response.status_int)
# Give it a user with a username already.
user = Membership.get_by_hash(self.user_hash)
user.username = "testy.testerson"
user.put()
response = self.test_app.post("/tasks/create_user", self.params)
# This should be okay, because we don't want PinPayments to think it needs
# to retry the call.
self.assertEqual(200, response.status_int)