def test_bad_plan(self): # If we give it a nonexistent plan, it should ignore it. query = urllib.urlencode({"plan": "badplan"}) response = self.test_app.get("/?" + query) self.assertEqual(200, response.status_int) self.assertIn("value=\"choose\"", response.body) # If we give it a plan that is not available, it should show us an error. unavailable_plan = Plan("test_plan", 1, 100, "A test plan.", admin_only=True) query = urllib.urlencode({"plan": unavailable_plan.name}) response = self.test_app.get("/?" + query, expect_errors=True) self.assertEqual(422, response.status_int) self.assertIn(unavailable_plan.name, response.body) self.assertIn("is not available", response.body) # If we're logged in as an admin, though, it should let us. self.testbed.setup_env(user_email=self._TEST_PARAMS["email"], user_is_admin="1", overwrite=True) query = urllib.urlencode({"plan": unavailable_plan.name}) response = self.test_app.get("/?" + query) self.assertEqual(200, response.status_int)
def setUp(self): # Create and activate testbed instance. self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() # Clear all the real plans. Plan.all_plans = [] Plan.legacy_pairs.clear() # Make some test plans. self.plan1 = Plan("plan1", 25, "Test plan 1") self.plan2 = Plan("plan2", 50, "Test plan 2", selectable=False) self.plan3 = Plan("plan3", 100, "Test plan 3", full=True) self.plan4 = Plan("plan4", 75, "Test plan 4", legacy=self.plan1) self.plan5 = Plan("plan5", 100, "Test plan 5", admin_only=True)
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=Config().LITE_VISITS) # Add a user to the datastore. self.user = Membership(first_name="Daniel", last_name="Petti", email="*****@*****.**", plan="test", username="******", status="active") self.user.put()
def setUp(self): super(PlanSelectionTestBase, self).setUp() # Clear all the real plans. Plan.all_plans = [] # Make a couple of plans to test with. self.plan1 = Plan("plan1", 101, "", human_name="First Plan") self.plan2 = Plan("plan2", 102, "", human_name="Second Plan") self.plan3 = Plan("plan3", 103, "", selectable=False, human_name="Third Plan") # Will always be full. self.plan4 = Plan("plan4", 104, "", member_limit=0, human_name="Fourth Plan")
def test_skip_if_account(self): plan = Plan("test", 0, 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="******", password="******", 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)
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("*****@*****.**") 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)
def setUp(self): super(AccountHandlerBase, self).setUp() # Start by putting a user in the datastore. user = Membership(first_name="Testy", last_name="Testerson", email="*****@*****.**", 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()