예제 #1
0
파일: test.py 프로젝트: vitrun/santa
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
예제 #2
0
파일: test.py 프로젝트: vitrun/santa
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
예제 #3
0
파일: test.py 프로젝트: vitrun/santa
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
예제 #4
0
 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))