Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Python D1 binding test. #1999

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cloudflare/internal/test/d1/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ wd_test(
args = ["--experimental"],
data = glob(["*.js"]),
)

wd_test(
src = "python-d1-api-test.wd-test",
args = ["--experimental"],
data = glob(["*.py", "*.js"]),
)
37 changes: 37 additions & 0 deletions src/cloudflare/internal/test/d1/d1-api-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2023 Cloudflare, Inc.
# Licensed under the Apache 2.0 license found in the LICENSE file or at:
# https://opensource.org/licenses/Apache-2.0

def assertSuccess(ret):
# D1 operations return an object with a `success` field.
assert ret.success

async def test(context, env):
DB = env.d1

assertSuccess(
await DB.prepare(
"""CREATE TABLE users
(
user_id INTEGER PRIMARY KEY,
name TEXT,
home TEXT,
features TEXT,
land_based BOOLEAN
);
"""
).run()
)

result = await DB.prepare(
"""
INSERT INTO users (name, home, features, land_based) VALUES
('Albert Ross', 'sky', 'wingspan', false),
('Al Dente', 'bowl', 'mouthfeel', true)
RETURNING *
"""
).all()

assertSuccess(result)
assert len(result.results) == 2
assert result.results[0].name == "Albert Ross"
44 changes: 44 additions & 0 deletions src/cloudflare/internal/test/d1/python-d1-api-test.wd-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Workerd = import "/workerd/workerd.capnp";

const unitTests :Workerd.Config = (
services = [
( name = "TEST_TMPDIR", disk = (writable = true) ),
( name = "d1-api-test",
worker = (
modules = [
(name = "worker.py", pythonModule = embed "d1-api-test.py")
],
compatibilityDate = "2023-01-15",
compatibilityFlags = ["nodejs_compat", "python_workers"],
bindings = [
(
name = "d1",
wrapped = (
moduleName = "cloudflare-internal:d1-api",
innerBindings = [(
name = "fetcher",
service = "d1-mock"
)],
)
)
],
)
),
( name = "d1-mock",
worker = (
compatibilityDate = "2023-01-15",
compatibilityFlags = ["experimental", "nodejs_compat"],
modules = [
(name = "worker", esModule = embed "d1-mock.js")
],
durableObjectNamespaces = [
(className = "D1MockDO", uniqueKey = "210bd0cbd803ef7883a1ee9d86cce06e"),
],
durableObjectStorage = (localDisk = "TEST_TMPDIR"),
bindings = [
(name = "db", durableObjectNamespace = "D1MockDO"),
],
)
)
]
);
Loading