def _claim_all(num): total = 301 envelope = Santa.create_envelope(1, total, num) cents = [] for i in range(num): claim = Santa.claim_envelope(i, envelope.id, envelope.secret) cents.append(claim.cent) assert sum(cents) == total
def test_claim_twice(): """ 试图领两个应拋错 """ envelope = Santa.create_envelope(1, 300, 3) Santa.claim_envelope(1, envelope.id, envelope.secret) try: Santa.claim_envelope(1, envelope.id, envelope.secret) except Exception as e: assert type(e) == SimpleException
def test_insufficient(): """ 领光了应拋错 """ num = 5 envelope = Santa.create_envelope(1, 300, num) for i in range(num): Santa.claim_envelope(i, envelope.id, envelope.secret) try: Santa.claim_envelope(num, envelope.id, envelope.secret) except Exception as e: assert type(e) == SimpleException
def post(self): #: TODO. get from auth token try: user_id = int(self.get_argument('user_id')) cent = int(float(self.get_argument('money')) * 100) num = int(self.get_argument('num')) #: TODO. more argument check if num > cent: self.done(msg='num too large') return envelope = Santa.create_envelope(user_id, cent, num) self.done(envelope.dic) except Exception as e: self.done(msg=str(e))