示例#1
0
def receive(request):
    """
    Receives the receipt from the client and maybe fires off a check of that
    receipt if needed.
    """
    if request.method != "POST":
        return http.HttpResponseNotAllowed(["POST"])

    receipt = request.raw_post_data
    if not receipt:
        return http.HttpResponseBadRequest()

    hash_ = hashlib.md5(receipt).hexdigest()
    log.info("Receipt received: %s, %s" % (hash_, request.META["REMOTE_ADDR"]))

    obj, created = Receipt.objects.get_or_create(hash=hash_)
    expired = not obj.checked or (obj.checked + timedelta(seconds=CHECK_INTERVAL)) < now()

    if obj.allow and expired:
        result = check(obj, receipt)
    else:
        result = obj.get_status()

    response = http.HttpResponse(json.dumps({"status": result}), content_type="application/json")
    response["Access-Control-Allow-Origin"] = "*"
    response["Access-Control-Allow-Methods"] = "POST"
    return response
示例#2
0
 def test_error(self, verify):
     verify.side_effect = VerificationError
     check(self.receipt, 'abc')
     assert self.receipt.get_status() == 'error'
示例#3
0
 def test_data_error(self, verify):
     verify.return_value = {'?': '?'}
     check(self.receipt, 'abc')
     assert self.receipt.get_status() == 'error'
示例#4
0
 def test_ok(self, verify):
     verify.return_value = {'status': 'ok'}
     check(self.receipt, 'abc')
     assert self.receipt.get_status() == 'ok'