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 _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 post(self): #: TODO. get from auth token try: user_id = int(self.get_argument('user_id')) envelope_id = int(self.get_argument('envelope_id')) secret = self.get_argument('secret') claim = Santa.claim_envelope(user_id, envelope_id, secret) self.done(data=claim.dic) except Exception as e: self.done(msg=str(e))