sdkloom 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +239 -2
- package/kits/allowed-sources.json +24 -0
- package/kits/csharp/kit.json +6 -0
- package/kits/csharp/src/Runtime/Client.cs +295 -0
- package/kits/csharp/src/Runtime/Context.cs +216 -0
- package/kits/csharp/src/Runtime/Errors.cs +121 -0
- package/kits/csharp/src/Runtime/Http.cs +218 -0
- package/kits/csharp/src/Runtime/Json.cs +650 -0
- package/kits/csharp/src/Runtime/Lang.cs +212 -0
- package/kits/csharp/src/Runtime/Models.cs +206 -0
- package/kits/csharp/src/Runtime/Multipart.cs +108 -0
- package/kits/csharp/src/Runtime/Pagination.cs +122 -0
- package/kits/csharp/src/Runtime/Sse.cs +197 -0
- package/kits/csharp/src/Runtime/Testing.cs +375 -0
- package/kits/csharp/src/Runtime/Transport.cs +212 -0
- package/kits/csharp/src/Runtime/Wait.cs +57 -0
- package/kits/csharp/src/Runtime/Webhooks.cs +148 -0
- package/kits/csharp/tests/ClientTests.cs +128 -0
- package/kits/csharp/tests/HttpTests.cs +44 -0
- package/kits/csharp/tests/JsonTests.cs +132 -0
- package/kits/csharp/tests/LangTests.cs +57 -0
- package/kits/csharp/tests/MultipartTests.cs +31 -0
- package/kits/csharp/tests/PaginationTests.cs +93 -0
- package/kits/csharp/tests/SseTests.cs +122 -0
- package/kits/csharp/tests/TestRunner.cs +93 -0
- package/kits/csharp/tests/TestingTests.cs +80 -0
- package/kits/csharp/tests/TransportTests.cs +145 -0
- package/kits/csharp/tests/WaitTests.cs +39 -0
- package/kits/csharp/tests/WebhooksTests.cs +46 -0
- package/kits/csharp/versions.json +12 -0
- package/kits/go/kit.json +6 -0
- package/kits/go/src/sdkruntime/client.go +322 -0
- package/kits/go/src/sdkruntime/context.go +207 -0
- package/kits/go/src/sdkruntime/errors.go +74 -0
- package/kits/go/src/sdkruntime/http.go +261 -0
- package/kits/go/src/sdkruntime/json.go +527 -0
- package/kits/go/src/sdkruntime/lang.go +462 -0
- package/kits/go/src/sdkruntime/multipart.go +75 -0
- package/kits/go/src/sdkruntime/pagination.go +150 -0
- package/kits/go/src/sdkruntime/sse.go +267 -0
- package/kits/go/src/sdkruntime/testing.go +343 -0
- package/kits/go/src/sdkruntime/transport.go +168 -0
- package/kits/go/src/sdkruntime/wait.go +49 -0
- package/kits/go/src/sdkruntime/webhooks.go +129 -0
- package/kits/go/tests/client_test.go +185 -0
- package/kits/go/tests/http_test.go +78 -0
- package/kits/go/tests/json_test.go +127 -0
- package/kits/go/tests/lang_test.go +98 -0
- package/kits/go/tests/multipart_test.go +29 -0
- package/kits/go/tests/pagination_test.go +69 -0
- package/kits/go/tests/sse_test.go +129 -0
- package/kits/go/tests/testing_test.go +121 -0
- package/kits/go/tests/transport_test.go +133 -0
- package/kits/go/tests/wait_test.go +46 -0
- package/kits/go/tests/webhooks_test.go +62 -0
- package/kits/go/versions.json +12 -0
- package/kits/java/kit.json +6 -0
- package/kits/java/src/dev/sdkloom/runtime/ApiException.java +63 -0
- package/kits/java/src/dev/sdkloom/runtime/ArgumentException.java +24 -0
- package/kits/java/src/dev/sdkloom/runtime/Assert.java +72 -0
- package/kits/java/src/dev/sdkloom/runtime/ClientRuntime.java +220 -0
- package/kits/java/src/dev/sdkloom/runtime/Clock.java +39 -0
- package/kits/java/src/dev/sdkloom/runtime/Context.java +79 -0
- package/kits/java/src/dev/sdkloom/runtime/Decode.java +200 -0
- package/kits/java/src/dev/sdkloom/runtime/DecodeException.java +26 -0
- package/kits/java/src/dev/sdkloom/runtime/Decoder.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/Emitter.java +56 -0
- package/kits/java/src/dev/sdkloom/runtime/ErrorFactory.java +18 -0
- package/kits/java/src/dev/sdkloom/runtime/EventListener.java +20 -0
- package/kits/java/src/dev/sdkloom/runtime/EventStream.java +232 -0
- package/kits/java/src/dev/sdkloom/runtime/FakeClock.java +37 -0
- package/kits/java/src/dev/sdkloom/runtime/Headers.java +42 -0
- package/kits/java/src/dev/sdkloom/runtime/HttpRequest.java +88 -0
- package/kits/java/src/dev/sdkloom/runtime/HttpResponse.java +69 -0
- package/kits/java/src/dev/sdkloom/runtime/JdkTransport.java +97 -0
- package/kits/java/src/dev/sdkloom/runtime/Js.java +230 -0
- package/kits/java/src/dev/sdkloom/runtime/Json.java +281 -0
- package/kits/java/src/dev/sdkloom/runtime/JsonValue.java +15 -0
- package/kits/java/src/dev/sdkloom/runtime/Links.java +62 -0
- package/kits/java/src/dev/sdkloom/runtime/Middleware.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/MiddlewareEntry.java +43 -0
- package/kits/java/src/dev/sdkloom/runtime/MockRoute.java +111 -0
- package/kits/java/src/dev/sdkloom/runtime/MockTransport.java +62 -0
- package/kits/java/src/dev/sdkloom/runtime/MultipartForm.java +111 -0
- package/kits/java/src/dev/sdkloom/runtime/Next.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationInfo.java +35 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationMock.java +105 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationSpec.java +125 -0
- package/kits/java/src/dev/sdkloom/runtime/Pages.java +55 -0
- package/kits/java/src/dev/sdkloom/runtime/Pipeline.java +29 -0
- package/kits/java/src/dev/sdkloom/runtime/RawResult.java +31 -0
- package/kits/java/src/dev/sdkloom/runtime/RecordedEvent.java +36 -0
- package/kits/java/src/dev/sdkloom/runtime/SdkInfo.java +38 -0
- package/kits/java/src/dev/sdkloom/runtime/SendOptions.java +34 -0
- package/kits/java/src/dev/sdkloom/runtime/ServerSentEvent.java +58 -0
- package/kits/java/src/dev/sdkloom/runtime/State.java +58 -0
- package/kits/java/src/dev/sdkloom/runtime/Test.java +21 -0
- package/kits/java/src/dev/sdkloom/runtime/TestRunner.java +63 -0
- package/kits/java/src/dev/sdkloom/runtime/Transport.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/TransportException.java +30 -0
- package/kits/java/src/dev/sdkloom/runtime/UrlConnectionTransport.java +195 -0
- package/kits/java/src/dev/sdkloom/runtime/Urls.java +116 -0
- package/kits/java/src/dev/sdkloom/runtime/Waits.java +53 -0
- package/kits/java/src/dev/sdkloom/runtime/WebhookSignatureException.java +24 -0
- package/kits/java/src/dev/sdkloom/runtime/Webhooks.java +146 -0
- package/kits/java/tests/dev/sdkloom/runtime/ClientTest.java +266 -0
- package/kits/java/tests/dev/sdkloom/runtime/EventStreamTest.java +131 -0
- package/kits/java/tests/dev/sdkloom/runtime/HttpTest.java +95 -0
- package/kits/java/tests/dev/sdkloom/runtime/JdkTransportTest.java +12 -0
- package/kits/java/tests/dev/sdkloom/runtime/JsTest.java +102 -0
- package/kits/java/tests/dev/sdkloom/runtime/JsonTest.java +87 -0
- package/kits/java/tests/dev/sdkloom/runtime/LinksTest.java +22 -0
- package/kits/java/tests/dev/sdkloom/runtime/MultipartFormTest.java +30 -0
- package/kits/java/tests/dev/sdkloom/runtime/PagesTest.java +75 -0
- package/kits/java/tests/dev/sdkloom/runtime/TestData.java +53 -0
- package/kits/java/tests/dev/sdkloom/runtime/TestingTest.java +156 -0
- package/kits/java/tests/dev/sdkloom/runtime/TransportContract.java +201 -0
- package/kits/java/tests/dev/sdkloom/runtime/UrlConnectionTransportTest.java +49 -0
- package/kits/java/tests/dev/sdkloom/runtime/WaitsTest.java +43 -0
- package/kits/java/tests/dev/sdkloom/runtime/WebhooksTest.java +45 -0
- package/kits/java/versions.json +41 -0
- package/kits/python/kit.json +6 -0
- package/kits/python/src/sdkloom_runtime/__init__.py +1 -0
- package/kits/python/src/sdkloom_runtime/client.py +232 -0
- package/kits/python/src/sdkloom_runtime/compat.py +195 -0
- package/kits/python/src/sdkloom_runtime/context.py +134 -0
- package/kits/python/src/sdkloom_runtime/errors.py +65 -0
- package/kits/python/src/sdkloom_runtime/http.py +192 -0
- package/kits/python/src/sdkloom_runtime/lang.py +207 -0
- package/kits/python/src/sdkloom_runtime/models.py +221 -0
- package/kits/python/src/sdkloom_runtime/multipart.py +69 -0
- package/kits/python/src/sdkloom_runtime/pagination.py +61 -0
- package/kits/python/src/sdkloom_runtime/pipeline.py +39 -0
- package/kits/python/src/sdkloom_runtime/sse.py +121 -0
- package/kits/python/src/sdkloom_runtime/testing.py +224 -0
- package/kits/python/src/sdkloom_runtime/transport.py +120 -0
- package/kits/python/src/sdkloom_runtime/wait.py +44 -0
- package/kits/python/src/sdkloom_runtime/webhooks.py +84 -0
- package/kits/python/tests/support.py +28 -0
- package/kits/python/tests/test_client.py +275 -0
- package/kits/python/tests/test_compat.py +87 -0
- package/kits/python/tests/test_http.py +94 -0
- package/kits/python/tests/test_lang.py +104 -0
- package/kits/python/tests/test_models.py +110 -0
- package/kits/python/tests/test_multipart.py +37 -0
- package/kits/python/tests/test_pagination.py +70 -0
- package/kits/python/tests/test_sse.py +61 -0
- package/kits/python/tests/test_testing.py +130 -0
- package/kits/python/tests/test_transport.py +124 -0
- package/kits/python/tests/test_wait.py +46 -0
- package/kits/python/tests/test_webhooks.py +57 -0
- package/kits/python/versions.json +33 -0
- package/kits/rust/kit.json +6 -0
- package/kits/rust/src/runtime/client.rs +212 -0
- package/kits/rust/src/runtime/context.rs +182 -0
- package/kits/rust/src/runtime/crypto.rs +84 -0
- package/kits/rust/src/runtime/errors.rs +147 -0
- package/kits/rust/src/runtime/http.rs +248 -0
- package/kits/rust/src/runtime/json.rs +424 -0
- package/kits/rust/src/runtime/lang.rs +296 -0
- package/kits/rust/src/runtime/mod.rs +30 -0
- package/kits/rust/src/runtime/models.rs +266 -0
- package/kits/rust/src/runtime/multipart.rs +81 -0
- package/kits/rust/src/runtime/pagination.rs +117 -0
- package/kits/rust/src/runtime/sse.rs +195 -0
- package/kits/rust/src/runtime/testing.rs +308 -0
- package/kits/rust/src/runtime/transport.rs +324 -0
- package/kits/rust/src/runtime/wait.rs +29 -0
- package/kits/rust/src/runtime/webhooks.rs +142 -0
- package/kits/rust/tests/client.rs +152 -0
- package/kits/rust/tests/http.rs +44 -0
- package/kits/rust/tests/json.rs +82 -0
- package/kits/rust/tests/lang.rs +74 -0
- package/kits/rust/tests/multipart.rs +21 -0
- package/kits/rust/tests/pagination.rs +61 -0
- package/kits/rust/tests/sse.rs +77 -0
- package/kits/rust/tests/testing.rs +90 -0
- package/kits/rust/tests/transport.rs +218 -0
- package/kits/rust/tests/wait.rs +32 -0
- package/kits/rust/tests/webhooks.rs +73 -0
- package/kits/rust/versions.json +6 -0
- package/kits/typescript/kit.json +6 -0
- package/kits/typescript/src/client.ts +223 -0
- package/kits/typescript/src/context.ts +108 -0
- package/kits/typescript/src/errors.ts +63 -0
- package/kits/typescript/src/helpers.ts +49 -0
- package/kits/typescript/src/http.ts +192 -0
- package/kits/typescript/src/models.ts +139 -0
- package/kits/typescript/src/multipart.ts +66 -0
- package/kits/typescript/src/pagination.ts +54 -0
- package/kits/typescript/src/pipeline.ts +25 -0
- package/kits/typescript/src/sse.ts +102 -0
- package/kits/typescript/src/testing.ts +217 -0
- package/kits/typescript/src/transport.ts +101 -0
- package/kits/typescript/src/wait.ts +36 -0
- package/kits/typescript/src/webhooks.ts +168 -0
- package/kits/typescript/tests/client.test.ts +269 -0
- package/kits/typescript/tests/helpers.test.ts +27 -0
- package/kits/typescript/tests/http.test.ts +80 -0
- package/kits/typescript/tests/models.test.ts +71 -0
- package/kits/typescript/tests/multipart.test.ts +28 -0
- package/kits/typescript/tests/pagination.test.ts +76 -0
- package/kits/typescript/tests/sse.test.ts +82 -0
- package/kits/typescript/tests/testing.test.ts +103 -0
- package/kits/typescript/tests/transport.test.ts +127 -0
- package/kits/typescript/tests/wait.test.ts +31 -0
- package/kits/typescript/tests/webhooks.test.ts +53 -0
- package/kits/typescript/versions.json +15 -0
- package/package.json +37 -4
- package/packages/cli/recipes/apiKeyHeader.ts +16 -0
- package/packages/cli/recipes/apiVersionHeader.ts +16 -0
- package/packages/cli/recipes/basic.ts +13 -0
- package/packages/cli/recipes/bearer.ts +10 -0
- package/packages/cli/recipes/hmacSign.ts +23 -0
- package/packages/cli/recipes/idempotencyKey.ts +19 -0
- package/packages/cli/recipes/oauthClientCredentials.ts +50 -0
- package/packages/cli/recipes/retry.ts +42 -0
- package/packages/cli/recipes/timing.ts +12 -0
- package/packages/cli/recipes/userAgent.ts +8 -0
- package/packages/cli/src/build.js +93 -0
- package/packages/cli/src/commands/build.js +31 -0
- package/packages/cli/src/commands/conformance-check.js +50 -0
- package/packages/cli/src/commands/contract.js +181 -0
- package/packages/cli/src/commands/diff.js +113 -0
- package/packages/cli/src/commands/doctor.js +43 -0
- package/packages/cli/src/commands/import-openapi.js +42 -0
- package/packages/cli/src/commands/init.js +27 -0
- package/packages/cli/src/commands/kit-check.js +145 -0
- package/packages/cli/src/commands/publish.js +81 -0
- package/packages/cli/src/commands/recipe.js +49 -0
- package/packages/cli/src/commands/record.js +181 -0
- package/packages/cli/src/commands/serve.js +156 -0
- package/packages/cli/src/commands/spec-check.js +57 -0
- package/packages/cli/src/commands/test.js +177 -0
- package/packages/cli/src/commands/variants.js +32 -0
- package/packages/cli/src/commands/verify.js +57 -0
- package/packages/cli/src/commands/version.js +63 -0
- package/packages/cli/src/containers.js +82 -0
- package/packages/cli/src/coverage.js +72 -0
- package/packages/cli/src/git.js +25 -0
- package/packages/cli/src/io.js +50 -0
- package/packages/cli/src/java/ScenarioHarness.java +297 -0
- package/packages/cli/src/java/SchemaRoundTrip.java +63 -0
- package/packages/cli/src/java.js +70 -0
- package/packages/cli/src/js/harness.mjs +120 -0
- package/packages/cli/src/kits.js +103 -0
- package/packages/cli/src/languages/csharp.js +274 -0
- package/packages/cli/src/languages/go.js +185 -0
- package/packages/cli/src/languages/index.js +18 -0
- package/packages/cli/src/languages/java.js +187 -0
- package/packages/cli/src/languages/python.js +120 -0
- package/packages/cli/src/languages/rust.js +189 -0
- package/packages/cli/src/languages/types.js +93 -0
- package/packages/cli/src/languages/typescript.js +112 -0
- package/packages/cli/src/main.js +13 -0
- package/packages/cli/src/packaging.js +39 -0
- package/packages/cli/src/portability.js +45 -0
- package/packages/cli/src/profiles.js +55 -0
- package/packages/cli/src/project.js +56 -0
- package/packages/cli/src/python/scenario_harness.py +162 -0
- package/packages/cli/src/python/schema_roundtrip.py +42 -0
- package/packages/cli/src/registries.js +214 -0
- package/packages/cli/src/resolve-core.js +39 -0
- package/packages/cli/src/run.js +133 -0
- package/packages/cli/src/runtimes.js +61 -0
- package/packages/cli/src/scenarios-java.js +82 -0
- package/packages/cli/src/scenarios-javascript.js +54 -0
- package/packages/cli/src/scenarios-python.js +90 -0
- package/packages/cli/src/scenarios.js +183 -0
- package/packages/cli/src/schema.js +84 -0
- package/packages/cli/src/templates.js +85 -0
- package/packages/cli/src/toolchains.js +68 -0
- package/packages/cli/src/transpiled-tests.js +92 -0
- package/packages/codegen/src/canonical-json.js +31 -0
- package/packages/codegen/src/capabilities.js +50 -0
- package/packages/codegen/src/code-writer.js +54 -0
- package/packages/codegen/src/file-tree.js +25 -0
- package/packages/codegen/src/hash.js +6 -0
- package/packages/codegen/src/index.js +16 -0
- package/packages/codegen/src/lock.js +106 -0
- package/packages/conformance/src/case.js +143 -0
- package/packages/conformance/src/checks.js +40 -0
- package/packages/conformance/src/index.js +3 -0
- package/packages/conformance/src/matrix.js +48 -0
- package/packages/conformance/src/suite.js +48 -0
- package/packages/differ/src/diff.js +500 -0
- package/packages/differ/src/index.js +3 -0
- package/packages/differ/src/notes.js +112 -0
- package/packages/differ/src/support.js +34 -0
- package/packages/gen-csharp/src/emit-client.js +397 -0
- package/packages/gen-csharp/src/emit-harness.js +333 -0
- package/packages/gen-csharp/src/emit-mock.js +111 -0
- package/packages/gen-csharp/src/emit-models.js +119 -0
- package/packages/gen-csharp/src/emit-webhooks.js +57 -0
- package/packages/gen-csharp/src/generate.js +245 -0
- package/packages/gen-csharp/src/index.js +5 -0
- package/packages/gen-csharp/src/names.js +284 -0
- package/packages/gen-go/src/emit-client.js +405 -0
- package/packages/gen-go/src/emit-harness.js +294 -0
- package/packages/gen-go/src/emit-mock.js +112 -0
- package/packages/gen-go/src/emit-models.js +146 -0
- package/packages/gen-go/src/emit-webhooks.js +58 -0
- package/packages/gen-go/src/generate.js +205 -0
- package/packages/gen-go/src/index.js +5 -0
- package/packages/gen-go/src/names.js +197 -0
- package/packages/gen-java/src/emit-client.js +441 -0
- package/packages/gen-java/src/emit-models.js +342 -0
- package/packages/gen-java/src/emit-testing.js +123 -0
- package/packages/gen-java/src/emit-webhooks.js +70 -0
- package/packages/gen-java/src/generate.js +244 -0
- package/packages/gen-java/src/index.js +4 -0
- package/packages/gen-java/src/names.js +197 -0
- package/packages/gen-python/src/emit-client.js +272 -0
- package/packages/gen-python/src/emit-models.js +139 -0
- package/packages/gen-python/src/emit-testing.js +93 -0
- package/packages/gen-python/src/emit-webhooks.js +48 -0
- package/packages/gen-python/src/generate.js +237 -0
- package/packages/gen-python/src/index.js +2 -0
- package/packages/gen-python/src/names.js +161 -0
- package/packages/gen-python/src/style.js +67 -0
- package/packages/gen-rust/src/emit-client.js +379 -0
- package/packages/gen-rust/src/emit-harness.js +278 -0
- package/packages/gen-rust/src/emit-mock.js +121 -0
- package/packages/gen-rust/src/emit-models.js +117 -0
- package/packages/gen-rust/src/emit-webhooks.js +58 -0
- package/packages/gen-rust/src/generate.js +243 -0
- package/packages/gen-rust/src/index.js +5 -0
- package/packages/gen-rust/src/names.js +223 -0
- package/packages/gen-typescript/src/emit-client.js +434 -0
- package/packages/gen-typescript/src/emit-models.js +93 -0
- package/packages/gen-typescript/src/emit-package.js +90 -0
- package/packages/gen-typescript/src/emit-testing.js +138 -0
- package/packages/gen-typescript/src/emit-webhooks.js +52 -0
- package/packages/gen-typescript/src/generate.js +70 -0
- package/packages/gen-typescript/src/index.js +3 -0
- package/packages/gen-typescript/src/naming.js +64 -0
- package/packages/gen-typescript/src/runtime.js +81 -0
- package/packages/gen-typescript/src/types.js +136 -0
- package/packages/ir/src/api-surface.js +22 -0
- package/packages/ir/src/checks.js +52 -0
- package/packages/ir/src/index.js +32 -0
- package/packages/ir/src/ir.js +214 -0
- package/packages/ir/src/pages.js +18 -0
- package/packages/ir/src/validate-ir.js +462 -0
- package/packages/ir/src/validate-types.js +140 -0
- package/packages/kit/src/block-parser.js +196 -0
- package/packages/kit/src/index.js +15 -0
- package/packages/kit/src/kit-check.js +203 -0
- package/packages/kit/src/sources.js +53 -0
- package/packages/kit/src/version-policy.js +133 -0
- package/packages/kit/src/version-range.js +132 -0
- package/packages/openapi/src/import.js +292 -0
- package/packages/openapi/src/index.js +1 -0
- package/packages/openapi/src/names.js +50 -0
- package/packages/openapi/src/schemas.js +264 -0
- package/packages/packager/src/archive.js +106 -0
- package/packages/packager/src/crate.js +39 -0
- package/packages/packager/src/gomodule.js +11 -0
- package/packages/packager/src/index.js +9 -0
- package/packages/packager/src/maven.js +85 -0
- package/packages/packager/src/metadata.js +34 -0
- package/packages/packager/src/npm.js +71 -0
- package/packages/packager/src/nuget.js +78 -0
- package/packages/packager/src/sbom.js +56 -0
- package/packages/packager/src/wheel.js +62 -0
- package/packages/spec/src/index.js +11 -0
- package/packages/spec/src/requirements.js +139 -0
- package/packages/transpile/src/ast.js +51 -0
- package/packages/transpile/src/check.js +669 -0
- package/packages/transpile/src/emit-csharp.js +469 -0
- package/packages/transpile/src/emit-go.js +529 -0
- package/packages/transpile/src/emit-java.js +360 -0
- package/packages/transpile/src/emit-python.js +320 -0
- package/packages/transpile/src/emit-rust.js +499 -0
- package/packages/transpile/src/errors.js +15 -0
- package/packages/transpile/src/index.js +13 -0
- package/packages/transpile/src/lexer.js +161 -0
- package/packages/transpile/src/parser.js +543 -0
- package/packages/transpile/src/tests/ast.js +46 -0
- package/packages/transpile/src/tests/parse.js +376 -0
- package/packages/transpile/src/tests/translate.js +849 -0
- package/packages/transpile/src/transpile.js +57 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# @requirement SDKL-JSON-001
|
|
3
|
+
# @requirement SDKL-JSON-002
|
|
4
|
+
# @requirement SDKL-JSON-003
|
|
5
|
+
# @requirement SDKL-JSON-004
|
|
6
|
+
from __future__ import absolute_import, division, unicode_literals
|
|
7
|
+
|
|
8
|
+
import unittest
|
|
9
|
+
from collections import OrderedDict
|
|
10
|
+
from decimal import Decimal
|
|
11
|
+
|
|
12
|
+
import support # noqa: E402,F401 - puts the kit on the path
|
|
13
|
+
|
|
14
|
+
from sdkloom_runtime.models import ( # noqa: E402
|
|
15
|
+
UNSET,
|
|
16
|
+
DecodeError,
|
|
17
|
+
as_boolean,
|
|
18
|
+
as_decimal,
|
|
19
|
+
as_enum,
|
|
20
|
+
as_integer,
|
|
21
|
+
as_list,
|
|
22
|
+
as_map,
|
|
23
|
+
as_number,
|
|
24
|
+
as_object,
|
|
25
|
+
as_string,
|
|
26
|
+
encode_json,
|
|
27
|
+
with_tag,
|
|
28
|
+
field,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class DecodeTests(unittest.TestCase):
|
|
33
|
+
def test_objects_keep_fields_they_do_not_know(self):
|
|
34
|
+
self.assertEqual(as_object({"a": 1, "extra": "x"}, "$"), {"a": 1, "extra": "x"})
|
|
35
|
+
|
|
36
|
+
def test_enums_keep_values_they_do_not_know(self):
|
|
37
|
+
self.assertEqual(as_enum("EUR", "$.currency", ["TRY", "USD"]), "EUR")
|
|
38
|
+
with self.assertRaisesRegex(DecodeError, r"\$\.currency: expected one of TRY, USD, got number 1"):
|
|
39
|
+
as_enum(1, "$.currency", ["TRY", "USD"])
|
|
40
|
+
|
|
41
|
+
def test_errors_name_the_path_the_expected_type_and_the_value(self):
|
|
42
|
+
cases = [
|
|
43
|
+
(as_string, 1, r"\$: expected a string, got number 1"),
|
|
44
|
+
(as_integer, 1.5, r"\$: expected an integer, got number 1\.5"),
|
|
45
|
+
(as_integer, True, r"\$: expected an integer, got boolean true"),
|
|
46
|
+
(as_number, "1", r'\$: expected a number, got string "1"'),
|
|
47
|
+
(as_boolean, None, r"\$: expected a boolean, got null"),
|
|
48
|
+
(as_object, [], r"\$: expected an object, got array"),
|
|
49
|
+
]
|
|
50
|
+
for decode, value, message in cases:
|
|
51
|
+
with self.assertRaisesRegex(DecodeError, message):
|
|
52
|
+
decode(value, "$")
|
|
53
|
+
self.assertEqual(as_integer(2.0, "$"), 2)
|
|
54
|
+
self.assertEqual(as_number(1.5, "$"), 1.5)
|
|
55
|
+
self.assertIs(as_boolean(False, "$"), False)
|
|
56
|
+
|
|
57
|
+
def test_decimals_accept_strings_and_numbers(self):
|
|
58
|
+
self.assertEqual(as_decimal("10.50", "$"), Decimal("10.50"))
|
|
59
|
+
self.assertEqual(as_decimal(10.5, "$"), Decimal("10.5"))
|
|
60
|
+
with self.assertRaisesRegex(DecodeError, r'\$\.amount: expected a decimal, got string "1e3x"'):
|
|
61
|
+
as_decimal("1e3x", "$.amount")
|
|
62
|
+
|
|
63
|
+
def test_lists_and_maps_decode_every_item_with_its_path(self):
|
|
64
|
+
self.assertEqual(as_list([1, 2], "$.l", as_integer), [1, 2])
|
|
65
|
+
with self.assertRaisesRegex(DecodeError, r"\$\.l\[1\]: expected an integer"):
|
|
66
|
+
as_list([1, "x"], "$.l", as_integer)
|
|
67
|
+
self.assertEqual(as_map({"a": 1}, "$.m", as_integer), {"a": 1})
|
|
68
|
+
with self.assertRaisesRegex(DecodeError, r"\$\.m\.a: expected an integer"):
|
|
69
|
+
as_map({"a": "x"}, "$.m", as_integer)
|
|
70
|
+
|
|
71
|
+
def test_optional_and_nullable_are_independent(self):
|
|
72
|
+
obj = as_object({"a": None}, "$")
|
|
73
|
+
|
|
74
|
+
self.assertIsNone(field(obj, "a", "$", as_string, optional=False, nullable=True))
|
|
75
|
+
# Many servers send null for a field they leave out: for an optional field that cannot be null it is UNSET.
|
|
76
|
+
self.assertIs(field(obj, "a", "$", as_string, optional=True, nullable=False), UNSET)
|
|
77
|
+
with self.assertRaisesRegex(DecodeError, r"\$\.a: expected a string, got null"):
|
|
78
|
+
field(obj, "a", "$", as_string, optional=False, nullable=False)
|
|
79
|
+
self.assertIs(field(obj, "b", "$", as_string, optional=True, nullable=False), UNSET)
|
|
80
|
+
with self.assertRaisesRegex(DecodeError, r"\$\.b: is required"):
|
|
81
|
+
field(obj, "b", "$", as_string, optional=False, nullable=True)
|
|
82
|
+
|
|
83
|
+
def test_unset_is_a_falsy_singleton(self):
|
|
84
|
+
self.assertFalse(UNSET)
|
|
85
|
+
self.assertEqual(repr(UNSET), "UNSET")
|
|
86
|
+
self.assertIs(type(UNSET)(), UNSET)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class EncodeTests(unittest.TestCase):
|
|
90
|
+
def test_a_union_variant_gets_its_tag_after_its_fields(self):
|
|
91
|
+
tagged = with_tag(OrderedDict([("brand", "visa"), ("type", "old")]), "type", "card")
|
|
92
|
+
|
|
93
|
+
self.assertEqual(list(tagged.items()), [("brand", "visa"), ("type", "card")])
|
|
94
|
+
|
|
95
|
+
def test_drops_unset_fields_and_writes_utf8(self):
|
|
96
|
+
# An OrderedDict, so the expected text is the same on Python 2.7, whose dicts have no order.
|
|
97
|
+
encoded = encode_json(OrderedDict([("a", 1), ("b", UNSET), ("c", "ş"), ("d", Decimal("1.50")), ("e", None)]))
|
|
98
|
+
|
|
99
|
+
self.assertEqual(encoded, '{"a":1,"c":"ş","d":"1.50","e":null}'.encode("utf-8"))
|
|
100
|
+
|
|
101
|
+
def test_uses_to_json_of_models(self):
|
|
102
|
+
class Model:
|
|
103
|
+
def to_json(self):
|
|
104
|
+
return {"x": Decimal("2"), "y": UNSET}
|
|
105
|
+
|
|
106
|
+
self.assertEqual(encode_json([Model()]), b'[{"x":"2"}]')
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if __name__ == "__main__":
|
|
110
|
+
unittest.main()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# @requirement SDKL-HTTP-005
|
|
3
|
+
from __future__ import absolute_import, division, unicode_literals
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
import unittest
|
|
7
|
+
|
|
8
|
+
import support # noqa: E402,F401 - puts the kit on the path
|
|
9
|
+
|
|
10
|
+
from sdkloom_runtime.multipart import MultipartForm, encode_multipart # noqa: E402
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class MultipartTest(unittest.TestCase):
|
|
14
|
+
def test_encodes_fields_and_files_in_order_with_dispositions_and_the_closing_boundary(self):
|
|
15
|
+
form = MultipartForm().field("title", "Q4 \u00fc").file("report", 'q4 "final".csv', "text/csv", b"a,b\r\n1,2")
|
|
16
|
+
content, content_type = encode_multipart(form, "b0undary")
|
|
17
|
+
|
|
18
|
+
self.assertEqual(content_type, "multipart/form-data; boundary=b0undary")
|
|
19
|
+
self.assertEqual(
|
|
20
|
+
content.decode("utf-8"),
|
|
21
|
+
'--b0undary\r\nContent-Disposition: form-data; name="title"\r\n\r\nQ4 \u00fc\r\n'
|
|
22
|
+
+ '--b0undary\r\nContent-Disposition: form-data; name="report"; filename="q4 %22final%22.csv"\r\nContent-Type: text/csv\r\n\r\na,b\r\n1,2\r\n'
|
|
23
|
+
+ "--b0undary--\r\n",
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
def test_a_form_is_immutable_and_the_default_boundary_is_random(self):
|
|
27
|
+
empty = MultipartForm()
|
|
28
|
+
one = empty.field("a", "1")
|
|
29
|
+
first = encode_multipart(one)[1]
|
|
30
|
+
|
|
31
|
+
self.assertEqual((len(empty.parts), len(one.parts)), (0, 1))
|
|
32
|
+
self.assertTrue(re.match(r"^multipart/form-data; boundary=sdkloom-[0-9a-f-]{36}$", first), first)
|
|
33
|
+
self.assertNotEqual(first, encode_multipart(one)[1])
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
unittest.main()
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @requirement SDKL-PAGE-001
|
|
2
|
+
from __future__ import absolute_import, division, unicode_literals
|
|
3
|
+
|
|
4
|
+
import unittest
|
|
5
|
+
|
|
6
|
+
import support # noqa: E402,F401 - puts the kit on the path
|
|
7
|
+
|
|
8
|
+
from sdkloom_runtime.pagination import paginate # noqa: E402
|
|
9
|
+
|
|
10
|
+
PAGES = {"": ([1, 2], "b"), "b": ([3], "c"), "c": ([], None)}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class PaginateTests(unittest.TestCase):
|
|
14
|
+
def test_yields_every_item_page_by_page_until_next_is_none(self):
|
|
15
|
+
fetched = []
|
|
16
|
+
|
|
17
|
+
def fetch(cursor):
|
|
18
|
+
fetched.append(cursor)
|
|
19
|
+
return PAGES[cursor]
|
|
20
|
+
|
|
21
|
+
items = list(paginate("", fetch, lambda page: page[0], lambda cursor, page, found: page[1]))
|
|
22
|
+
|
|
23
|
+
self.assertEqual(items, [1, 2, 3])
|
|
24
|
+
self.assertEqual(fetched, ["", "b", "c"])
|
|
25
|
+
|
|
26
|
+
def test_fetches_lazily_and_stops_when_the_caller_stops(self):
|
|
27
|
+
calls = []
|
|
28
|
+
|
|
29
|
+
def fetch(offset):
|
|
30
|
+
calls.append(offset)
|
|
31
|
+
return [offset, offset + 1]
|
|
32
|
+
|
|
33
|
+
pages = paginate(0, fetch, lambda page: page, lambda offset, page, found: offset + len(found))
|
|
34
|
+
self.assertEqual(calls, [])
|
|
35
|
+
for item in pages:
|
|
36
|
+
if item == 2:
|
|
37
|
+
break
|
|
38
|
+
self.assertEqual(calls, [0, 2])
|
|
39
|
+
|
|
40
|
+
def test_an_error_fetching_a_page_ends_the_iteration_with_that_error(self):
|
|
41
|
+
def fetch(page):
|
|
42
|
+
if page == 2:
|
|
43
|
+
raise ValueError("page 2 failed")
|
|
44
|
+
return [page]
|
|
45
|
+
|
|
46
|
+
seen = []
|
|
47
|
+
with self.assertRaisesRegex(ValueError, "page 2 failed"):
|
|
48
|
+
for item in paginate(1, fetch, lambda page: page, lambda page, _page, found: page + 1):
|
|
49
|
+
seen.append(item)
|
|
50
|
+
self.assertEqual(seen, [1])
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class NextLinkTest(unittest.TestCase):
|
|
55
|
+
def test_reads_rel_next_quoted_or_not_among_several_types_in_any_case(self):
|
|
56
|
+
from sdkloom_runtime.client import resolve_url
|
|
57
|
+
from sdkloom_runtime.pagination import next_link
|
|
58
|
+
|
|
59
|
+
self.assertEqual(next_link('<https://a.test/x?page=2&s=a,b>; rel="next", <https://a.test/x?page=9>; rel="last"'), "https://a.test/x?page=2&s=a,b")
|
|
60
|
+
self.assertEqual(next_link('<https://a.test/x?page=1>; rel="prev first", <https://a.test/x?page=3>; REL="Next last"'), "https://a.test/x?page=3")
|
|
61
|
+
self.assertEqual(next_link("</x?page=4>; title=more; rel=next"), "/x?page=4")
|
|
62
|
+
self.assertIsNone(next_link('<https://a.test/x?page=1>; rel="prev"'))
|
|
63
|
+
self.assertIsNone(next_link(None))
|
|
64
|
+
self.assertEqual(resolve_url("https://a.test/v1/", "/v1/x?page=2"), "https://a.test/v1/x?page=2")
|
|
65
|
+
self.assertEqual(resolve_url("https://a.test/v1", "x?page=2"), "https://a.test/v1/x?page=2")
|
|
66
|
+
self.assertEqual(resolve_url("https://a.test/v1", "https://b.test/y"), "https://b.test/y")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
unittest.main()
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# @requirement SDKL-SSE-001
|
|
3
|
+
from __future__ import absolute_import, division, unicode_literals
|
|
4
|
+
|
|
5
|
+
import unittest
|
|
6
|
+
|
|
7
|
+
import support # noqa: E402,F401 - puts the kit on the path
|
|
8
|
+
|
|
9
|
+
from sdkloom_runtime.models import DecodeError
|
|
10
|
+
from sdkloom_runtime.sse import ServerSentEvent, decode_events, encode_events, parse_events
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def chunks(*parts):
|
|
14
|
+
return [part.encode("utf-8") for part in parts]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ParseEventsTest(unittest.TestCase):
|
|
18
|
+
def test_types_multi_line_data_ids_that_carry_over_comments_and_every_line_ending(self):
|
|
19
|
+
stream = "\uFEFF: comment\r\nevent: created\r\ndata: {\"a\":1}\r\nid: 7\r\n\r\ndata:first\ndata: second\n\nretry: 10\rdata: spaced\r\r"
|
|
20
|
+
self.assertEqual(
|
|
21
|
+
list(parse_events(chunks(stream))),
|
|
22
|
+
[ServerSentEvent("created", "7", '{"a":1}'), ServerSentEvent("message", "7", "first\nsecond"), ServerSentEvent("message", "7", " spaced")],
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
def test_lines_and_characters_split_across_chunks_and_an_unfinished_event_at_the_end(self):
|
|
26
|
+
euro = "data: €\r\n\r\n".encode("utf-8")
|
|
27
|
+
parts = [euro[:7], euro[7:10], euro[10:], b"data: dropped\n"]
|
|
28
|
+
self.assertEqual(list(parse_events(parts)), [ServerSentEvent("message", "", "€")])
|
|
29
|
+
|
|
30
|
+
def test_an_event_with_no_data_is_not_dispatched_and_a_field_without_a_colon_has_an_empty_value(self):
|
|
31
|
+
self.assertEqual(
|
|
32
|
+
list(parse_events(chunks("event: ping\n\ndata\n\nid\ndata: x\n\n"))),
|
|
33
|
+
[ServerSentEvent("message", "", ""), ServerSentEvent("message", "", "x")],
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
def test_yields_an_event_before_the_stream_ends(self):
|
|
37
|
+
def slow():
|
|
38
|
+
yield b"data: one\n\n"
|
|
39
|
+
raise AssertionError("read past the first event")
|
|
40
|
+
|
|
41
|
+
self.assertEqual(next(parse_events(slow())).data, "one")
|
|
42
|
+
|
|
43
|
+
def test_decodes_json_data_keeps_text_without_a_decoder_and_fails_on_data_that_is_not_json(self):
|
|
44
|
+
typed = decode_events(parse_events(chunks('data: {"n": 2}\n\n')), lambda value, path: value["n"] * 10)
|
|
45
|
+
text = decode_events(parse_events(chunks("data: plain\n\n")), None)
|
|
46
|
+
self.assertEqual(list(typed), [ServerSentEvent("message", "", 20)])
|
|
47
|
+
self.assertEqual(list(text), [ServerSentEvent("message", "", "plain")])
|
|
48
|
+
with self.assertRaises(DecodeError) as raised:
|
|
49
|
+
list(decode_events(parse_events(chunks("data: {nope\n\n")), lambda value, path: value))
|
|
50
|
+
self.assertTrue(str(raised.exception).startswith("$: the event data is not JSON"))
|
|
51
|
+
|
|
52
|
+
def test_encode_events_writes_what_parse_events_reads_back(self):
|
|
53
|
+
events = [ServerSentEvent("created", "1", {"note": "two\nlines"}), ServerSentEvent("message", "", "first line\nsecond line")]
|
|
54
|
+
self.assertEqual(
|
|
55
|
+
list(parse_events([encode_events(events)])),
|
|
56
|
+
[ServerSentEvent("created", "1", '{"note":"two\\nlines"}'), ServerSentEvent("message", "1", "first line\nsecond line")],
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if __name__ == "__main__":
|
|
61
|
+
unittest.main()
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# @requirement SDKL-MOCK-001
|
|
2
|
+
# @requirement SDKL-MOCK-002
|
|
3
|
+
from __future__ import absolute_import, division, unicode_literals
|
|
4
|
+
|
|
5
|
+
import unittest
|
|
6
|
+
|
|
7
|
+
import support # noqa: E402,F401 - puts the kit on the path
|
|
8
|
+
|
|
9
|
+
from sdkloom_runtime.http import HttpRequest # noqa: E402
|
|
10
|
+
from sdkloom_runtime.models import DecodeError, as_object, as_string # noqa: E402
|
|
11
|
+
from sdkloom_runtime.testing import FakeClock, MockTransport, OperationMock # noqa: E402
|
|
12
|
+
from sdkloom_runtime.transport import SendOptions # noqa: E402
|
|
13
|
+
|
|
14
|
+
BASE = "http://mock.sdkloom.invalid"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def decode_order(value, path):
|
|
18
|
+
obj = as_object(value, path)
|
|
19
|
+
return {"id": as_string(obj.get("id"), path + ".id")}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def get(path):
|
|
23
|
+
return HttpRequest("GET", BASE + path)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class MockTransportTests(unittest.TestCase):
|
|
27
|
+
def test_fails_a_request_no_route_answers(self):
|
|
28
|
+
with self.assertRaisesRegex(AssertionError, r"no mock for GET /x"):
|
|
29
|
+
MockTransport().send(get("/x?y=1"), SendOptions())
|
|
30
|
+
|
|
31
|
+
def test_routes_match_path_templates_and_record_calls(self):
|
|
32
|
+
transport = MockTransport()
|
|
33
|
+
route = transport.route("GET", "/orders/{id}").reply(status=200, json={"id": "1"})
|
|
34
|
+
response = transport.send(get("/orders/42"), SendOptions())
|
|
35
|
+
|
|
36
|
+
self.assertEqual(response.status, 200)
|
|
37
|
+
self.assertEqual(response.json(), {"id": "1"})
|
|
38
|
+
self.assertEqual(len(route.calls), 1)
|
|
39
|
+
self.assertEqual(transport.calls[0].url, BASE + "/orders/42")
|
|
40
|
+
with self.assertRaisesRegex(AssertionError, r"no mock for GET /orders/42/items"):
|
|
41
|
+
transport.send(get("/orders/42/items"), SendOptions())
|
|
42
|
+
|
|
43
|
+
def test_answers_come_in_order_and_the_last_repeats(self):
|
|
44
|
+
transport = MockTransport()
|
|
45
|
+
transport.route("GET", "/x").reply(status=503).reply(status=200)
|
|
46
|
+
|
|
47
|
+
self.assertEqual([transport.send(get("/x"), SendOptions()).status for _ in range(3)], [503, 200, 200])
|
|
48
|
+
|
|
49
|
+
def test_a_route_with_answers_beats_a_later_one_without(self):
|
|
50
|
+
transport = MockTransport()
|
|
51
|
+
transport.route("GET", "/users/me").reply(status=200)
|
|
52
|
+
by_id = transport.route("GET", "/users/{id}")
|
|
53
|
+
|
|
54
|
+
self.assertEqual(transport.send(get("/users/me"), SendOptions()).status, 200)
|
|
55
|
+
with self.assertRaisesRegex(AssertionError, r"mock for GET /users/\{id\} has no answer"):
|
|
56
|
+
transport.send(get("/users/7"), SendOptions())
|
|
57
|
+
by_id.reply(status=204)
|
|
58
|
+
self.assertEqual(transport.send(get("/users/me"), SendOptions()).status, 204)
|
|
59
|
+
|
|
60
|
+
def test_a_route_without_answers_fails_clearly(self):
|
|
61
|
+
transport = MockTransport()
|
|
62
|
+
transport.route("GET", "/orders/{id}")
|
|
63
|
+
|
|
64
|
+
with self.assertRaisesRegex(AssertionError, r"mock for GET /orders/\{id\} has no answer"):
|
|
65
|
+
transport.send(get("/orders/1"), SendOptions())
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class OperationMockTests(unittest.TestCase):
|
|
69
|
+
def test_text_is_answered_as_json_and_bytearray_as_raw_bytes(self):
|
|
70
|
+
transport = MockTransport()
|
|
71
|
+
mock = OperationMock("getName", transport.route("GET", "/name"))
|
|
72
|
+
|
|
73
|
+
mock.returns(str("abc"))
|
|
74
|
+
self.assertEqual(transport.send(HttpRequest("GET", "https://a.test/name"), SendOptions()).body, b'"abc"')
|
|
75
|
+
mock.returns(bytearray(b"raw"))
|
|
76
|
+
self.assertEqual(transport.send(HttpRequest("GET", "https://a.test/name"), SendOptions()).body, b"raw")
|
|
77
|
+
|
|
78
|
+
def test_validates_values_fails_raises_and_records_calls(self):
|
|
79
|
+
transport = MockTransport()
|
|
80
|
+
mock = OperationMock("getOrder", transport.route("GET", "/orders/{id}"), decode_order)
|
|
81
|
+
|
|
82
|
+
with self.assertRaises(DecodeError) as caught:
|
|
83
|
+
mock.returns({"id": 1})
|
|
84
|
+
self.assertEqual(caught.exception.path, "$.id")
|
|
85
|
+
self.assertIs(mock.then, mock)
|
|
86
|
+
mock.returns({"id": "a"}).then.fails(404, {"message": "no"}).then.raises(RuntimeError("boom"))
|
|
87
|
+
|
|
88
|
+
self.assertEqual(transport.send(get("/orders/1"), SendOptions()).json(), {"id": "a"})
|
|
89
|
+
failed = transport.send(get("/orders/1"), SendOptions())
|
|
90
|
+
self.assertEqual((failed.status, failed.json()), (404, {"message": "no"}))
|
|
91
|
+
with self.assertRaisesRegex(RuntimeError, "boom"):
|
|
92
|
+
transport.send(get("/orders/1"), SendOptions())
|
|
93
|
+
self.assertEqual(len(mock.calls), 3)
|
|
94
|
+
|
|
95
|
+
def test_when_answers_only_matching_requests(self):
|
|
96
|
+
transport = MockTransport()
|
|
97
|
+
mock = OperationMock("getOrder", transport.route("GET", "/orders/{id}"), decode_order)
|
|
98
|
+
mock.returns({"id": "normal"})
|
|
99
|
+
mock.when(lambda request: request.url.endswith("/special")).returns({"id": "special"})
|
|
100
|
+
|
|
101
|
+
self.assertEqual(transport.send(get("/orders/special"), SendOptions()).json(), {"id": "special"})
|
|
102
|
+
self.assertEqual(transport.send(get("/orders/1"), SendOptions()).json(), {"id": "normal"})
|
|
103
|
+
|
|
104
|
+
def test_an_encoder_turns_values_into_their_wire_form_before_they_are_checked_and_sent(self):
|
|
105
|
+
transport = MockTransport()
|
|
106
|
+
mock = OperationMock("getOrder", transport.route("GET", "/orders/{id}"), decode_order, lambda value: {"id": value["id"].upper()})
|
|
107
|
+
mock.returns({"id": "a"})
|
|
108
|
+
mock.when(lambda request: request.url.endswith("/special")).returns({"id": "b"})
|
|
109
|
+
|
|
110
|
+
self.assertEqual(transport.send(get("/orders/1"), SendOptions()).json(), {"id": "A"})
|
|
111
|
+
self.assertEqual(transport.send(get("/orders/special"), SendOptions()).json(), {"id": "B"})
|
|
112
|
+
|
|
113
|
+
def test_bytes_are_returned_as_the_body(self):
|
|
114
|
+
transport = MockTransport()
|
|
115
|
+
OperationMock("download", transport.route("GET", "/f")).returns(bytearray(b"\x01\x02")) # bytearray: bytes on 2.7 too
|
|
116
|
+
|
|
117
|
+
self.assertEqual(transport.send(get("/f"), SendOptions()).body, b"\x01\x02")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class FakeClockTests(unittest.TestCase):
|
|
121
|
+
def test_moves_only_when_slept_or_advanced(self):
|
|
122
|
+
clock = FakeClock()
|
|
123
|
+
self.assertEqual(clock.now(), 0)
|
|
124
|
+
clock.sleep(100)
|
|
125
|
+
clock.advance(50)
|
|
126
|
+
self.assertEqual(clock.now(), 150)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
if __name__ == "__main__":
|
|
130
|
+
unittest.main()
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# @requirement SDKL-HTTP-004
|
|
2
|
+
from __future__ import absolute_import, division, unicode_literals
|
|
3
|
+
|
|
4
|
+
import socket
|
|
5
|
+
import ssl
|
|
6
|
+
import threading
|
|
7
|
+
import time
|
|
8
|
+
import unittest
|
|
9
|
+
|
|
10
|
+
import support # noqa: E402,F401 - puts the kit on the path
|
|
11
|
+
from support import BaseHTTPRequestHandler, ThreadingHTTPServer # noqa: E402
|
|
12
|
+
|
|
13
|
+
from sdkloom_runtime.errors import TransportError # noqa: E402
|
|
14
|
+
from sdkloom_runtime.http import HttpRequest # noqa: E402
|
|
15
|
+
from sdkloom_runtime.transport import SendOptions, UrllibTransport # noqa: E402
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
RELEASE = threading.Event()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Handler(BaseHTTPRequestHandler):
|
|
22
|
+
def do_POST(self):
|
|
23
|
+
body = self.rfile.read(int(self.headers.get("content-length") or 0))
|
|
24
|
+
self.send_response(201)
|
|
25
|
+
self.send_header("x-echo", self.headers.get("x-test", ""))
|
|
26
|
+
self.send_header("x-method", self.command)
|
|
27
|
+
self.end_headers()
|
|
28
|
+
self.wfile.write(b"got:" + body)
|
|
29
|
+
|
|
30
|
+
def do_GET(self):
|
|
31
|
+
if self.path == "/hang-up":
|
|
32
|
+
self.close_connection = True
|
|
33
|
+
self.wfile.flush()
|
|
34
|
+
self.connection.shutdown(socket.SHUT_RDWR)
|
|
35
|
+
return
|
|
36
|
+
if self.path == "/slow":
|
|
37
|
+
time.sleep(0.5)
|
|
38
|
+
if self.path == "/events":
|
|
39
|
+
# HTTP/1.0 style: no length, the body ends when the connection closes.
|
|
40
|
+
self.send_response(200)
|
|
41
|
+
self.send_header("content-type", "text/event-stream")
|
|
42
|
+
self.end_headers()
|
|
43
|
+
self.wfile.write(b"data: one\n\n")
|
|
44
|
+
self.wfile.flush()
|
|
45
|
+
RELEASE.wait(30)
|
|
46
|
+
self.wfile.write(b"data: two\n\n")
|
|
47
|
+
self.close_connection = True
|
|
48
|
+
return
|
|
49
|
+
status, body = (404, b'{"message":"no"}') if self.path == "/missing" else (200, self.path.encode("utf-8"))
|
|
50
|
+
self.send_response(status)
|
|
51
|
+
self.end_headers()
|
|
52
|
+
self.wfile.write(body)
|
|
53
|
+
|
|
54
|
+
def log_message(self, *args):
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class TransportTests(unittest.TestCase):
|
|
59
|
+
@classmethod
|
|
60
|
+
def setUpClass(cls):
|
|
61
|
+
cls.server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
|
|
62
|
+
cls.base = "http://127.0.0.1:%d" % cls.server.server_address[1]
|
|
63
|
+
thread = threading.Thread(target=cls.server.serve_forever)
|
|
64
|
+
thread.daemon = True
|
|
65
|
+
thread.start()
|
|
66
|
+
|
|
67
|
+
@classmethod
|
|
68
|
+
def tearDownClass(cls):
|
|
69
|
+
cls.server.shutdown()
|
|
70
|
+
cls.server.server_close()
|
|
71
|
+
|
|
72
|
+
def test_stream_hands_over_a_successful_body_as_it_arrives_and_still_reads_an_error_body(self):
|
|
73
|
+
response = UrllibTransport()(HttpRequest("GET", self.base + "/events"), SendOptions(timeout_ms=30000, stream=True))
|
|
74
|
+
chunks = response.chunks()
|
|
75
|
+
first = next(chunks)
|
|
76
|
+
RELEASE.set()
|
|
77
|
+
rest = b"".join(chunks)
|
|
78
|
+
missing = UrllibTransport()(HttpRequest("GET", self.base + "/missing"), SendOptions(stream=True))
|
|
79
|
+
|
|
80
|
+
# Python 3 hands over what has arrived; Python 2.7 reads line by line.
|
|
81
|
+
self.assertEqual((response.status, response.body), (200, b""))
|
|
82
|
+
self.assertTrue(first.startswith(b"data: one\n"))
|
|
83
|
+
self.assertEqual(first + rest, b"data: one\n\ndata: two\n\n")
|
|
84
|
+
self.assertEqual((missing.status, missing.json()), (404, {"message": "no"}))
|
|
85
|
+
|
|
86
|
+
def test_sends_method_headers_and_body(self):
|
|
87
|
+
request = HttpRequest("POST", self.base + "/echo", (("x-test", "1"),), b"hi")
|
|
88
|
+
response = UrllibTransport()(request, SendOptions())
|
|
89
|
+
|
|
90
|
+
self.assertEqual(response.status, 201)
|
|
91
|
+
self.assertEqual(response.header("x-echo"), "1")
|
|
92
|
+
self.assertEqual(response.header("x-method"), "POST")
|
|
93
|
+
self.assertEqual(response.text(), "got:hi")
|
|
94
|
+
|
|
95
|
+
def test_an_error_status_is_a_response_not_a_failure(self):
|
|
96
|
+
response = UrllibTransport()(HttpRequest("GET", self.base + "/missing"), SendOptions())
|
|
97
|
+
|
|
98
|
+
self.assertEqual(response.status, 404)
|
|
99
|
+
self.assertEqual(response.json(), {"message": "no"})
|
|
100
|
+
|
|
101
|
+
def test_reports_a_timeout(self):
|
|
102
|
+
with self.assertRaises(TransportError) as caught:
|
|
103
|
+
UrllibTransport()(HttpRequest("GET", self.base + "/slow"), SendOptions(timeout_ms=50))
|
|
104
|
+
self.assertEqual(caught.exception.reason, "timeout")
|
|
105
|
+
|
|
106
|
+
def test_a_server_that_hangs_up_is_a_network_failure(self):
|
|
107
|
+
with self.assertRaises(TransportError) as caught:
|
|
108
|
+
UrllibTransport()(HttpRequest("GET", self.base + "/hang-up"), SendOptions())
|
|
109
|
+
self.assertEqual(caught.exception.reason, "network")
|
|
110
|
+
|
|
111
|
+
def test_reports_a_network_failure(self):
|
|
112
|
+
with self.assertRaises(TransportError) as caught:
|
|
113
|
+
UrllibTransport()(HttpRequest("GET", "http://127.0.0.1:1/"), SendOptions())
|
|
114
|
+
self.assertEqual(caught.exception.reason, "network")
|
|
115
|
+
|
|
116
|
+
def test_routes_requests_through_a_proxy(self):
|
|
117
|
+
transport = UrllibTransport(proxy=self.base, ssl_context=ssl.create_default_context())
|
|
118
|
+
response = transport(HttpRequest("GET", "http://api.example.invalid/proxied"), SendOptions())
|
|
119
|
+
|
|
120
|
+
self.assertEqual(response.text(), "http://api.example.invalid/proxied")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
if __name__ == "__main__":
|
|
124
|
+
unittest.main()
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @requirement SDKL-WAIT-001
|
|
2
|
+
from __future__ import absolute_import, division, unicode_literals
|
|
3
|
+
|
|
4
|
+
import unittest
|
|
5
|
+
|
|
6
|
+
import support # noqa: E402,F401 - puts the kit on the path
|
|
7
|
+
|
|
8
|
+
from sdkloom_runtime.testing import FakeClock # noqa: E402
|
|
9
|
+
from sdkloom_runtime.wait import WaitTimeoutError, wait_until # noqa: E402
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class WaitUntilTest(unittest.TestCase):
|
|
13
|
+
def test_polls_on_the_clock_until_done_and_returns_a_done_result_without_polling(self):
|
|
14
|
+
clock = FakeClock()
|
|
15
|
+
states = ["running", "running", "done"]
|
|
16
|
+
polled = []
|
|
17
|
+
|
|
18
|
+
def poll(current):
|
|
19
|
+
status = states.pop(0)
|
|
20
|
+
polled.append(status)
|
|
21
|
+
return {"status": status}
|
|
22
|
+
|
|
23
|
+
def never(current):
|
|
24
|
+
raise AssertionError("polled")
|
|
25
|
+
|
|
26
|
+
result = wait_until({"status": "pending"}, poll, lambda current: current["status"] == "done", clock, 500, 10000)
|
|
27
|
+
immediate = wait_until({"status": "done"}, never, lambda current: current["status"] == "done", clock, 500, 10000)
|
|
28
|
+
|
|
29
|
+
self.assertEqual((result, polled, clock.now()), ({"status": "done"}, ["running", "running", "done"], 1500))
|
|
30
|
+
self.assertEqual(immediate, {"status": "done"})
|
|
31
|
+
|
|
32
|
+
def test_raises_wait_timeout_error_keeping_the_last_result(self):
|
|
33
|
+
clock = FakeClock()
|
|
34
|
+
count = [0]
|
|
35
|
+
|
|
36
|
+
def poll(current):
|
|
37
|
+
count[0] += 1
|
|
38
|
+
return {"status": "running %d" % count[0]}
|
|
39
|
+
|
|
40
|
+
with self.assertRaises(WaitTimeoutError) as raised:
|
|
41
|
+
wait_until({"status": "pending"}, poll, lambda current: False, clock, 400, 1000)
|
|
42
|
+
self.assertEqual((raised.exception.last, raised.exception.name, clock.now()), ({"status": "running 2"}, "WaitTimeoutError", 800))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == "__main__":
|
|
46
|
+
unittest.main()
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @requirement SDKL-HOOK-001
|
|
2
|
+
from __future__ import absolute_import, division, unicode_literals
|
|
3
|
+
|
|
4
|
+
import hashlib
|
|
5
|
+
import hmac
|
|
6
|
+
import unittest
|
|
7
|
+
|
|
8
|
+
import support # noqa: E402,F401 - puts the kit on the path
|
|
9
|
+
|
|
10
|
+
from sdkloom_runtime.webhooks import WebhookSignatureError, verify_webhook # noqa: E402
|
|
11
|
+
|
|
12
|
+
STANDARD = {
|
|
13
|
+
"header": "webhook-signature",
|
|
14
|
+
"encoding": "base64",
|
|
15
|
+
"prefix": "v1,",
|
|
16
|
+
"separator": " ",
|
|
17
|
+
"signed": "{webhook-id}.{webhook-timestamp}.{body}",
|
|
18
|
+
"timestamp": {"header": "webhook-timestamp", "toleranceSeconds": 300},
|
|
19
|
+
"secret": "base64",
|
|
20
|
+
"secretPrefix": "whsec_",
|
|
21
|
+
}
|
|
22
|
+
SECRET = "whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw"
|
|
23
|
+
BODY = '{"test": 2432232314}'
|
|
24
|
+
HEADERS = {"Webhook-Id": "msg_p5jXN8AQM9LWM0D4loKWxJek", "webhook-timestamp": "1614265330", "webhook-signature": "v1,bad v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE="}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class VerifyWebhookTests(unittest.TestCase):
|
|
28
|
+
def test_verifies_the_standard_webhooks_example(self):
|
|
29
|
+
verify_webhook(STANDARD, BODY, HEADERS, SECRET, 1614265330)
|
|
30
|
+
verify_webhook(STANDARD, BODY.encode("utf-8"), HEADERS, SECRET, 1614265330 + 300)
|
|
31
|
+
|
|
32
|
+
def test_refuses_changes_wrong_secrets_old_timestamps_and_missing_headers(self):
|
|
33
|
+
cases = [
|
|
34
|
+
(BODY.replace("2", "3"), HEADERS, SECRET, 1614265330, "no signature matches"),
|
|
35
|
+
(BODY, HEADERS, "whsec_AAAA", 1614265330, "no signature matches"),
|
|
36
|
+
(BODY, HEADERS, SECRET, 1614265330 + 301, "more than 300 s from now"),
|
|
37
|
+
(BODY, {"webhook-timestamp": "1614265330"}, SECRET, 1614265330, "missing webhook-signature header"),
|
|
38
|
+
(BODY, {"webhook-signature": "v1,x"}, SECRET, 1614265330, "missing or invalid webhook-timestamp header"),
|
|
39
|
+
]
|
|
40
|
+
for body, headers, secret, now, message in cases:
|
|
41
|
+
with self.assertRaisesRegex(WebhookSignatureError, message):
|
|
42
|
+
verify_webhook(STANDARD, body, headers, secret, now)
|
|
43
|
+
self.assertEqual(WebhookSignatureError.name, "WebhookSignatureError")
|
|
44
|
+
|
|
45
|
+
def test_verifies_a_hex_signature_of_the_body_with_a_text_secret(self):
|
|
46
|
+
github = {"header": "x-hub-signature-256", "encoding": "hex", "prefix": "sha256=", "signed": "{body}", "secret": "text"}
|
|
47
|
+
body = '{"zen":"Design for failure."}'
|
|
48
|
+
signature = "sha256=" + hmac.new(b"It is a secret", body.encode("utf-8"), hashlib.sha256).hexdigest()
|
|
49
|
+
self.assertEqual(signature, "sha256=fb962995c1234ec94fb7a13c015a044d2d0ef7e076c0b619d419a8bf068cc218")
|
|
50
|
+
|
|
51
|
+
verify_webhook(github, body, {"x-hub-signature-256": signature}, "It is a secret", 0)
|
|
52
|
+
with self.assertRaises(WebhookSignatureError):
|
|
53
|
+
verify_webhook(github, body, {"x-hub-signature-256": signature.replace("sha256=", "sha1=")}, "It is a secret", 0)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
if __name__ == "__main__":
|
|
57
|
+
unittest.main()
|