async def test_appstore_validate_sandbox():
    validator = AppStoreValidator(bundle_id="test-bundle-id", sandbox=True)
    assert validator is not None

    async def post_json(self, receipt):
        assert receipt == {
            "receipt-data": "test-receipt",
            "password": "******",
        }
        return {"status": 0}

    async def post_json_no_secret(self, receipt):
        assert receipt == {"receipt-data": "test-receipt"}
        assert receipt == {"receipt-data": "test-receipt"}
        return {"status": 0}

    with patch.object(AppStoreValidator, "post_json", new=post_json):
        await validator.validate(receipt="test-receipt",
                                 shared_secret="shared-secret")
        assert (
            validator.url == "https://sandbox.itunes.apple.com/verifyReceipt")

    with patch.object(AppStoreValidator, "post_json", new=post_json_no_secret):
        await validator.validate(receipt="test-receipt")
        assert (
            validator.url == "https://sandbox.itunes.apple.com/verifyReceipt")
async def test_appstore_auto_retry_wrong_env_request():
    validator = AppStoreValidator(
        bundle_id="test-bundle-id",
        sandbox=False,
        auto_retry_wrong_env_request=True,
    )
    assert validator is not None
    assert not validator.sandbox
    assert validator.auto_retry_wrong_env_request

    raw_response = {"status": 21007, "foo": "bar"}

    async def post_json(self, receipt):
        assert receipt == {
            "receipt-data": "test-receipt",
            "password": "******",
        }
        return raw_response

    with pytest.raises(InAppPyValidationError):
        with patch.object(AppStoreValidator, "post_json", new=post_json):
            await validator.validate(receipt="test-receipt",
                                     shared_secret="shared-secret")
            assert (
                validator.url == "https://buy.itunes.apple.com/verifyReceipt")
            assert validator.sandbox is True

    raw_response = {"status": 21008, "foo": "bar"}

    async def post_json(self, receipt):
        assert receipt == {
            "receipt-data": "test-receipt",
            "password": "******",
        }
        return raw_response

    with pytest.raises(InAppPyValidationError):
        with patch.object(AppStoreValidator, "post_json", new=post_json):
            await validator.validate(receipt="test-receipt",
                                     shared_secret="shared-secret")
            assert validator.sandbox is False
            assert (
                validator.url == "https://buy.itunes.apple.com/verifyReceipt")
示例#3
0
async def test_appstore_validate_attach_raw_response_to_the_exception():
    validator = AppStoreValidator(bundle_id="test-bundle-id")
    assert validator is not None

    raw_response = {"status": 21000, "foo": "bar"}

    async def post_json(self, receipt):
        assert receipt == {
            "receipt-data": "test-receipt",
            "password": "******"
        }
        return raw_response

    with pytest.raises(InAppPyValidationError) as ex:
        with patch.object(AppStoreValidator, "post_json", new=post_json):
            await validator.validate(receipt="test-receipt",
                                     shared_secret="shared-secret")
            assert validator.url == "https://buy.itunes.apple.com/verifyReceipt"
            assert ex.raw_response is not None
            assert ex.raw_response == raw_response
示例#4
0
def test_appstore_validator_initiation_raises_if_no_bundle_id():
    with pytest.raises(InAppPyValidationError):
        AppStoreValidator(bundle_id="")
示例#5
0
def test_appstore_validator_initiation_sandbox():
    validator = AppStoreValidator(bundle_id="test-bundle-id", sandbox=True)
    assert validator is not None
    assert validator.url == "https://sandbox.itunes.apple.com/verifyReceipt"
示例#6
0
def test_appstore_validator_initiation_simple():
    validator = AppStoreValidator(bundle_id="test-bundle-id")
    assert validator is not None
    assert validator.url == "https://buy.itunes.apple.com/verifyReceipt"
示例#7
0
def appstore_validator() -> AppStoreValidator:
    return AppStoreValidator()
示例#8
0
def appstore_validator_auto_retry_on_sandbox() -> AppStoreValidator:
    return AppStoreValidator(auto_retry_wrong_env_request=True)
示例#9
0
def appstore_validator_sandbox() -> AppStoreValidator:
    return AppStoreValidator(sandbox=True)