本文整理汇总了Python中membership.Membership.put方法的典型用法代码示例。如果您正苦于以下问题:Python Membership.put方法的具体用法?Python Membership.put怎么用?Python Membership.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类membership.Membership
的用法示例。
在下文中一共展示了Membership.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BaseTest
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
class BaseTest(unittest.TestCase):
def setUp(self):
# Set up testing for application.
self.test_app = webtest.TestApp(billing.app)
# Set up datastore for testing.
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_user_stub()
# Make some testing plans.
self.test_plan = plans.Plan("test", 0, 150, "This is a test plan.")
self.test_plan_legacy = plans.Plan("test_legacy", 1, 100,
"This is a test plan.",
legacy=self.test_plan)
# Make a test user.
self.user = Membership(email="[email protected]",
first_name="Testy", last_name="Testerson",
username="testy.testerson",
spreedly_token="notatoken", plan="test")
self.user.put()
# Simulate the user login.
self.testbed.setup_env(user_email=self.user.email, user_is_admin="0",
overwrite=True)
def tearDown(self):
self.testbed.deactivate()
示例2: post
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
def post(self):
if Config().is_dev:
# Only allow this if it's the dev server.
entry = self.request.body
logging.debug("Got new entry: " + entry)
entry = json.loads(entry)
# Change formatted date back into datetime.
for key in entry.keys():
if type(getattr(Membership, key)) == db.DateTimeProperty:
if not entry[key]:
# It could be None as well.
continue
entry[key] = pickle.loads(str(entry[key]))
# entry should have everything nicely in a dict...
member = Membership(**entry)
# Is this an update or a new model?
match = Membership.all().filter("email =", member.email).get()
if match:
# Replace the old one.
logging.debug("Found entry with same username. Replacing...")
db.delete(match)
member.put()
logging.debug("Put entry in datastore.")
示例3: test_legacy_pairing
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
def test_legacy_pairing(self):
self.plan1.member_limit = 2
user1 = Membership(first_name="Testy1", last_name="Testerson",
email="[email protected]", plan="plan1")
user1.put()
user2 = Membership(first_name="Testy2", last_name="Testerson",
email="[email protected]", plan="plan4")
user2.put()
self.assertTrue(self.plan1.is_full())
示例4: test_failure_if_account
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
def test_failure_if_account(self):
existing_user = Membership(first_name=self._TEST_PARAMS["first_name"],
last_name=self._TEST_PARAMS["last_name"],
email=self._TEST_PARAMS["email"],
spreedly_token=None,
username="testy.testerson",
password="notasecret")
existing_user.put()
response = self.test_app.post("/", self._TEST_PARAMS, expect_errors=True)
self.assertEqual(422, response.status_int)
self.assertIn("payment", response.body)
示例5: setUp
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
def setUp(self):
super(CreateUserTaskTest, self).setUp()
# Add a user to the datastore.
user = Membership(first_name="Testy", last_name="Testerson",
email="[email protected]", hash="notahash",
spreedly_token="notatoken", username="testy.testerson",
password="notasecret")
user.put()
self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
self.user_hash = user.hash
self.params = {"hash": self.user_hash, "username": "testy.testerson",
"password": "notasecret"}
示例6: test_signin_limit
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
def test_signin_limit(self):
self.plan1.signin_limit = 2
user = Membership(first_name="Testy", last_name="Testerson",
email="[email protected]", plan="plan1")
user.put()
# We should have all 2 signins left.
self.assertEqual(2, Plan.signins_remaining(user))
# Signin once.
user.signins = 1
user.put()
self.assertEqual(1, Plan.signins_remaining(user))
# Signin again.
user.signins = 2
user.put()
self.assertEqual(0, Plan.signins_remaining(user))
# Should never be less than zero.
user.signins = 3
user.put()
self.assertEqual(0, Plan.signins_remaining(user))
# Give ourselves unlimited signins!
self.plan1.signin_limit = None
self.assertEqual(None, Plan.signins_remaining(user))
示例7: setUp
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
def setUp(self):
super(AccountHandlerBase, self).setUp()
# Start by putting a user in the datastore.
user = Membership(first_name="Testy", last_name="Testerson",
email="[email protected]", plan=None,
status=None, hash="anunlikelyhash")
user.put()
self.user_hash = user.hash
# Add the plans we need.
Plan.all_plans = []
Plan.legacy_pairs = set()
self.test_plan = Plan("test", 0, 100, "A test plan.")
# Clear fake usernames between tests.
ProjectHandler.clear_usernames()
示例8: test_member_limit
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
def test_member_limit(self):
self.plan1.member_limit = 2
# Put some people in the datastore.
user1 = Membership(first_name="Testy1", last_name="Testerson",
email="[email protected]", plan="plan1")
user2 = Membership(first_name="Testy2", last_name="Testerson",
email="[email protected]", plan="plan1")
# The plan should not be full initially.
self.assertFalse(self.plan1.is_full())
# Adding one user should still not make it full.
user1.put()
self.assertFalse(self.plan1.is_full())
# Adding the other user should make it full.
user2.put()
self.assertTrue(self.plan1.is_full())
示例9: test_skip_if_account
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
def test_skip_if_account(self):
plan = Plan("test", 100, "This is a test plan.")
existing_user = Membership(first_name=self._TEST_PARAMS["first_name"],
last_name=self._TEST_PARAMS["last_name"],
email=self._TEST_PARAMS["email"],
spreedly_token=None,
username="testy.testerson",
password="notasecret",
plan=plan.name)
existing_user.put()
response = self.test_app.post("/", self._TEST_PARAMS)
self.assertEqual(302, response.status_int)
self.assertIn("subs.pinpayments.com", response.location)
self.assertIn(plan.plan_id, response.location)
self.assertIn(existing_user.username, response.location)
self.assertNotIn(existing_user.password, response.location)
示例10: ReactivatePlanHandlerTest
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
class ReactivatePlanHandlerTest(PlanSelectionTestBase):
def setUp(self):
super(ReactivatePlanHandlerTest, self).setUp()
# Add a user to test with.
self.user = Membership(first_name="Testy", last_name="Testerson",
email="[email protected]", plan="plan1",
spreedly_token="notatoken", hash="notahash",
username="testy.testerson")
self.user.put()
""" Tests that the page works properly when we give it the right things. """
def test_get(self):
response = self.test_app.get("/reactivate_plan/%s" % (self.user.hash))
self.assertEqual(200, response.status_int)
""" Tests that it fails when we give it a bad hash. """
def test_bad_hash(self):
response = self.test_app.get("/reactivate_plan/badhash", expect_errors=True)
self.assertEqual(422, response.status_int)
self.assertIn("Invalid reactivation link", response.body)
示例11: ApiTest
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
class ApiTest(unittest.TestCase):
def setUp(self):
# Set up testing for application.
self.test_app = webtest.TestApp(user_api.app)
# Set up datastore for testing.
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
# Create a new plan for testing.
Plan.all_plans = []
self.test_plan = Plan("test", 1, 100, "A test plan.", signin_limit = 10)
# Add a user to the datastore.
self.user = Membership(first_name="Daniel", last_name="Petti",
email="[email protected]", plan="test", username="daniel.petti")
self.user.put()
def tearDown(self):
self.testbed.deactivate()
示例12: BaseTest
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
class BaseTest(unittest.TestCase):
def setUp(self):
# Set up testing for application.
self.test_app = webtest.TestApp(tasks.app)
# Set up datastore for testing.
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_taskqueue_stub()
self.testbed.init_mail_stub()
self.testbed.init_memcache_stub()
# Add a user to the datastore.
self.user = Membership(first_name="Testy", last_name="Testerson",
email="[email protected]", hash="notahash",
spreedly_token="notatoken", username="testy.testerson",
password="notasecret")
self.user.put()
self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
def tearDown(self):
self.testbed.deactivate()
示例13: ResetSigninHandlerTest
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
class ResetSigninHandlerTest(unittest.TestCase):
def setUp(self):
# Set up testing application.
self.test_app = webtest.TestApp(cron.app)
# Set up datastore for testing.
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
# Add a user to the datastore.
self.user = Membership(first_name="Testy", last_name="Testerson",
email="[email protected]")
self.user.put()
""" Tests that the cron job restores users properly. """
def test_user_restore(self):
self.user.signins = Config().LITE_VISITS + 2
self.user.status = "no_visits"
self.user.put()
response = self.test_app.get("/cron/reset_signins")
self.assertEqual(200, response.status_int)
user = Membership.get_by_email("[email protected]")
self.assertEqual(0, user.signins)
self.assertEqual("active", user.status)
""" Tests that unused signins rollover properly. """
def test_rollover(self):
self.user.signins = Config().LITE_VISITS - 2
self.user.status = "active"
self.user.put()
response = self.test_app.get("/cron/reset_signins")
self.assertEqual(200, response.status_int)
user = Membership.get_by_email("[email protected]")
self.assertEqual(-2, user.signins)
self.assertEqual("active", user.status)
# Test that signins_remaining gives us the right number.
test_plan = Plan("test_lite", 1, 100, "A test plan",
signin_limit = Config().LITE_VISITS)
user.plan = "test_lite"
remaining = Plan.signins_remaining(user)
self.assertEqual(Config().LITE_VISITS + 2, remaining)
示例14: test_already_existing
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
def test_already_existing(self):
# Make a user in the datastore with the same email, but a different name so
# we can see whether it overrides.
existing_user = Membership(first_name="Michael", last_name="Scarn",
email=self._TEST_PARAMS["email"],
status="active")
existing_user.put()
# Because the user is active, it should prohibit us from overriding.
response = self.test_app.post("/", self._TEST_PARAMS, expect_errors=True)
self.assertEqual(422, response.status_int)
self.assertIn("already exists", response.body)
# User should stay the same.
user = Membership.get_by_email(self._TEST_PARAMS["email"])
self.assertEqual("Michael", user.first_name)
self.assertEqual("Scarn", user.last_name)
existing_user.status = "suspended"
existing_user.put()
# Even though the user is suspended, it should still prohibit us from
# overriding.
response = self.test_app.post("/", self._TEST_PARAMS, expect_errors=True)
self.assertEqual(422, response.status_int)
self.assertIn("suspended", response.body)
# User should stay the same.
user = Membership.get_by_email(self._TEST_PARAMS["email"])
self.assertEqual("Michael", user.first_name)
self.assertEqual("Scarn", user.last_name)
existing_user.status = None
existing_user.put()
# Now the user should get silently overriden.
response = self.test_app.post("/", self._TEST_PARAMS)
self.assertEqual(302, response.status_int)
# User should not stay the same.
user = Membership.get_by_email(self._TEST_PARAMS["email"])
self.assertEqual(self._TEST_PARAMS["first_name"], user.first_name)
self.assertEqual(self._TEST_PARAMS["last_name"], user.last_name)
示例15: post
# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import put [as 别名]
def post(self):
refer = self.request.get('refer')
first_name = self.request.get('first_name')
last_name = self.request.get('last_name')
twitter = self.request.get('twitter').lower().strip().strip('@')
email = self.request.get('email').lower().strip()
plan = self.request.get('plan', 'full')
# See if the referring user is valid.
try:
ref_first_name = refer.split()[0]
ref_last_name = refer.split()[1]
referred_user = db.GqlQuery("SELECT * FROM Membership \
WHERE first_name = :first_name AND last_name = :last_name",
first_name = ref_first_name,
last_name = ref_last_name).get()
except IndexError:
referred_user = None
if not first_name or not last_name or not email:
self.response.out.write(render('templates/main.html', {
'plan': plan, 'message': "Sorry, we need name and e-mail address."}))
elif (not referred_user and refer != ""):
self.response.out.write(render('templates/main.html', {
'plan': plan,
'message': "The person who referred you is not an active user."}))
else:
# this just runs a check twice. (there is no OR in GQL)
# first name, last name
existing_member = db.GqlQuery("SELECT * FROM Membership WHERE first_name = :first_name AND last_name = :last_name", first_name=first_name, last_name=last_name).get()
if existing_member:
membership = existing_member
# email
existing_member = db.GqlQuery("SELECT * FROM Membership WHERE email = :email", email=email).get()
if existing_member:
membership = existing_member
first_part = re.compile(r'[^\w]').sub('', first_name.split(' ')[0])
last_part = re.compile(r'[^\w]').sub('', last_name)
if len(first_part)+len(last_part) >= 15:
last_part = last_part[0]
username = '.'.join([first_part, last_part]).lower()
if username in fetch_usernames():
username = email.split('@')[0].lower()
# [email protected]
existing_member = db.GqlQuery("SELECT * FROM Membership WHERE email = :email", email='%[email protected]' % username).get()
if existing_member:
membership = existing_member
try:
membership
if membership.extra_dnd == True:
self.response.out.write("Error #237. Please contact [email protected]")
return
if membership.status == "suspended":
c = Config()
self.redirect(str("https://www.spreedly.com/%s/subscriber_accounts/%s" % (c.SPREEDLY_ACCOUNT, membership.spreedly_token)))
except NameError:
membership = None
# old code below
#existing_member = Membership.get_by_email(email)
#if existing_member and existing_member.status in [None, 'paypal']:
# existing_member.delete()
if membership is None:
if referred_user:
referuserid = referred_user.username
else:
referuserid = None
membership = Membership(
first_name=first_name, last_name=last_name, email=email,
plan=plan, twitter=twitter, referuserid=referuserid)
if self.request.get('paypal') == '1':
membership.status = 'paypal'
membership.hash = hashlib.md5(membership.email).hexdigest()
if '1337' in self.request.get('referrer').upper():
membership.referrer = re.sub("[^0-9]", "", self.request.get('referrer').upper())
else:
membership.referrer = self.request.get('referrer').replace('\n', ' ')
membership.put()
# if there is a membership, redirect here
if membership.status != "active":
#self.redirect(str('/account/%s' % membership.hash))
# HRD compatible hack, code taken from AccountHandler::get()
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()
if username in fetch_usernames():
username = membership.email.split('@')[0].lower()
if self.request.get('u'):
pick_username = True
message = escape(self.request.get('message'))
account_url = str('/account/%s' % membership.hash)
self.response.out.write(render('templates/account.html', locals()))
#.........这里部分代码省略.........