当前位置: 首页>>代码示例>>Python>>正文


Python membership.Membership类代码示例

本文整理汇总了Python中membership.Membership的典型用法代码示例。如果您正苦于以下问题:Python Membership类的具体用法?Python Membership怎么用?Python Membership使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Membership类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BaseTest

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()
开发者ID:hackerdojo,项目名称:hd-signup,代码行数:30,代码来源:test_billing.py

示例2: post

  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.")
开发者ID:hackerdojo,项目名称:hd-signup,代码行数:25,代码来源:cron.py

示例3: MembershipTest

class MembershipTest(unittest.TestCase):

    def setUp(self):
        """Setup method to instance an object of Membership class """
        code = 9
        name = "Gold"
        discount = 10
        self.membership = Membership(code, name, discount)
        self.test_membership = Membership(5, "Platinum", 5)
        
    def test_create_membership(self):
        """Test if an instance is created with the required data"""
        self.assertIsInstance(self.test_membership, Membership)
        
    def test_set_code_of_membership(self):
        """Test to update the membership code"""
        other_code = 10
        self.test_membership.set_code(other_code)
        self.assertEqual(other_code, self.test_membership.get_code())
        
    def test_set_name_of_membership(self):
        """ Test to update the membership name"""
        other_name = "Platinum"
        self.test_membership.set_name(other_name)
        self.assertEqual(other_name, self.test_membership.get_name())
        
    def test_set_discont_of_membership(self):
        """ Test to update the membership discount"""
        other_discount = 11
        self.test_membership.set_discount(other_discount)
        self.assertEqual(other_discount, self.test_membership.get_discount())
开发者ID:grettarocha,项目名称:DEVFUNDA,代码行数:31,代码来源:membership_test.py

示例4: post

    def post(self):
        user = users.get_current_user()
        if not user:
            self.redirect(users.create_login_url("/key"))
            return
        account = Membership.all().filter("username =", user.nickname().split("@")[0]).get()
        if not account or not account.spreedly_token or account.status != "active":
            message = "Error #1982, which should never happen."
            internal = True
            self.response.out.write(self.render("templates/error.html", locals()))
            return
        is_park = self.request.get("ispark")
        if is_park == "True":  # checks if user input is a parking pass number or an rfid number
            pass_to_add = self.request.get("parking_pass")
            try:  # tests if there are only numbers in the parking pass
                float(pass_to_add)
            except ValueError:
                message = '<p>A Parking Pass may only contain numbers.</p><a href="/key">Try Again</a>'
                internal = False
                self.response.out.write(self.render("templates/error.html", locals()))
                return
            account.parking_pass = pass_to_add

            logging.debug("Setting parking pass for %s to %s." % (account.full_name(), account.parking_pass))

            db.put(account)
            self.response.out.write(self.render("templates/pass_ok.html", locals()))  # outputs the parking number
        else:
            rfid_tag = self.request.get("rfid_tag").strip()
            description = self.request.get("description").strip()
            if rfid_tag.isdigit():
                if Membership.all().filter("rfid_tag =", rfid_tag).get():
                    message = "<p>That RFID tag is in use by someone else.</p>"
                    internal = False
                    self.response.out.write(self.render("templates/error.html", locals()))
                    return
                if not description:
                    message = "<p>Please enter a reason why you are associating a replacement RFID key.  Please hit BACK and try again.</p>"
                    internal = False
                    self.response.out.write(self.render("templates/error.html", locals()))
                    return
                account.rfid_tag = rfid_tag

                logging.debug("Setting RFID for %s to %s." % (account.full_name(), account.rfid_tag))

                account.put()
                bc = BadgeChange(rfid_tag=rfid_tag, username=account.username, description=description)
                bc.put()
                self.response.out.write(self.render("templates/key_ok.html", locals()))
                return
            else:
                message = "<p>That RFID ID seemed invalid. Hit back and try again.</p>"
                internal = False
                self.response.out.write(self.render("templates/error.html", locals()))
                return
开发者ID:hackerdojo,项目名称:hd-signup,代码行数:55,代码来源:main.py

示例5: test_discount

  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))
开发者ID:hackerdojo,项目名称:hd-signup,代码行数:53,代码来源:test_main.py

示例6: test_failure_if_account

  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)
开发者ID:itstehkman,项目名称:hd-signup,代码行数:13,代码来源:test_main.py

示例7: setUp

  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"}
开发者ID:itstehkman,项目名称:hd-signup,代码行数:14,代码来源:test_main.py

示例8: post

    def post(self, ids=None):
        subscriber_ids = self.request.get('subscriber_ids').split(',')
        c = Config()
        s = spreedly.Spreedly(c.SPREEDLY_ACCOUNT, token=c.SPREEDLY_APIKEY)
        for id in subscriber_ids:
            subscriber = s.subscriber_details(sub_id=int(id))
            logging.debug("customer_id: "+ subscriber['customer-id'])
            member = Membership.get_by_id(int(subscriber['customer-id']))
            if member:
                if member.status == 'paypal':
                    mail.send_mail(sender=EMAIL_FROM,
                        to=PAYPAL_EMAIL,
                        subject="Please cancel PayPal subscription for %s" % member.full_name(),
                        body=member.email)
                member.status = 'active' if subscriber['active'] == 'true' else 'suspended'
                if member.status == 'active' and not member.username:
                    taskqueue.add(url='/tasks/create_user', method='POST', params={'hash': member.hash}, countdown=3)
                if member.status == 'active' and member.unsubscribe_reason:
                    member.unsubscribe_reason = None
                member.spreedly_token = subscriber['token']
                member.plan = subscriber['feature-level'] or member.plan
                if not subscriber['email']:
                  subscriber['email'] = "[email protected]"
                member.email = subscriber['email']                
                member.put()
                # TODO: After a few months (now() = 06.13.2011), only suspend/restore if status CHANGED
                # As of right now, we can't trust previous status, so lets take action on each call to /update
                if member.status == 'active' and member.username:
                    logging.info("Restoring User: "+member.username)
                    self.restore(member.username)
                if member.status == 'suspended' and member.username:
                    logging.info("Suspending User: "+member.username)
                    self.suspend(member.username)

        self.response.out.write("ok")
开发者ID:martinlschumann,项目名称:hd-signup,代码行数:35,代码来源:main.py

示例9: post

 def post(self):
     user = Membership.get_by_id(int(self.request.get("user")))
     try:
       mail.send_mail(sender=Config().EMAIL_FROM,
           to=user.email,
           subject="Hi again -- from Hacker Dojo!",
           body="Hi %s,"
           "\nOur fancy membership system noted that you started filling"
           " out the Membership Signup form, but didn't complete it."
           "\nWell -- We'd love to have you as a member!"
           "\nHacker Dojo has grown by leaps and bounds in recent years."
           " Give us a try?"
           "\nIf you would like to become a member of Hacker Dojo, just"
           " complete the signup process at http://signup.hackerdojo.com"
           "\nIf you don't want to sign up -- please give us anonymous"
           " feedback so we know how we can do better!  URL:"
           " http://bit.ly/jJAGYM"
           "\nCheers!\nHacker Dojo"
           "\n\nPS: Please ignore this e-mail if you already signed up --"
           " you might have started signing up twice or something :)"
           " PPS: This is an automated e-mail and we're now deleting your"
           " e-mail address from the signup application." % (user.full_name)
       )
     except:
       noop = True
     user.delete()
开发者ID:itstehkman,项目名称:hd-signup,代码行数:26,代码来源:main.py

示例10: setUp

 def setUp(self):
     """Setup method to instance an object of Membership class """
     code = 9
     name = "Gold"
     discount = 10
     self.membership = Membership(code, name, discount)
     self.test_membership = Membership(5, "Platinum", 5)
开发者ID:grettarocha,项目名称:DEVFUNDA,代码行数:7,代码来源:membership_test.py

示例11: test_user_suspending

  def test_user_suspending(self):
    user = Membership.get_by_email("[email protected]")
    # The next one should suspend us.
    user.signins = Config().LITE_VISITS - 1
    user.put()

    params = {"email": "[email protected]"}
    response = self.test_app.post("/api/v1/signin", params)
    result = json.loads(response.body)

    self.assertEqual(200, response.status_int)
    self.assertEqual(0, result["visits_remaining"])

    user = Membership.get_by_email("[email protected]m")
    self.assertEqual(Config().LITE_VISITS, user.signins)
    self.assertEqual("no_visits", user.status)
开发者ID:hackerdojo,项目名称:hd-signup,代码行数:16,代码来源:test_user_api.py

示例12: test_create_user

  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)
开发者ID:hackerdojo,项目名称:hd-signup,代码行数:25,代码来源:test_tasks.py

示例13: get

  def get(self):
    user = users.get_current_user()
    if not user:
      self.redirect(users.create_login_url(self.request.uri))
      return

    member = Membership.get_by_email(user.email())
    if not member:
      # User is not (yet) a member.
      self.redirect("/")
      return
    else:
      # Open billing information.
      url = member.spreedly_url()
      plan = Plan.get_by_name(member.plan)
      if plan.legacy:
        # Show the legacy plan warning.
        current = plan.get_legacy_pair()
        self.response.out.write(self.render(
            "templates/billing_popup.html",
            url=url, legacy=plan, current=current))
        return
      else:
        self.redirect(url)
        return
开发者ID:nasebanal,项目名称:hd-signup,代码行数:25,代码来源:billing.py

示例14: get

 def get(self):
   countdown = 0
   for membership in Membership.all().filter("status =", None):
     if (datetime.datetime.now().date() - membership.created.date()).days > 1:
       countdown += 90
       self.response.out.write("bye %s " % (membership.email))
       taskqueue.add(url="/tasks/clean_row", params={"user": membership.key().id()}, countdown=countdown)
开发者ID:hackerdojo,项目名称:hd-signup,代码行数:7,代码来源:cron.py

示例15: get

 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()))
开发者ID:hackerdojo,项目名称:hd-signup,代码行数:8,代码来源:main.py


注:本文中的membership.Membership类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。