Skip to content
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
2 changes: 1 addition & 1 deletion packages/django-cf/django_cf/db/backends/do/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def run_query(self, query, params=None) -> CFResult:
stmt = db.exec(proc_query)

try:
response = stmt.raw().toArray().to_py()
response = stmt.raw().toArray()
result = CFResult.from_object(
query, params, response, stmt.rowsRead, stmt.rowsWritten
)
Expand Down
6 changes: 3 additions & 3 deletions packages/django-cf/django_cf/storage/r2.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def exists(self, name):
full_path = self._full_path(name)
try:
bucket = self._get_bucket()
result = self._run_sync(bucket.head(full_path)).to_py()
result = self._run_sync(bucket.head(full_path))
return result is not None
except Exception:
return False
Expand Down Expand Up @@ -199,7 +199,7 @@ def size(self, name):
full_path = self._full_path(name)
try:
bucket = self._get_bucket()
metadata = self._run_sync(bucket.head(full_path)).to_py()
metadata = self._run_sync(bucket.head(full_path))
if metadata and hasattr(metadata, "size"):
return metadata.size
return 0
Expand Down Expand Up @@ -246,7 +246,7 @@ def get_modified_time(self, name):
full_path = self._full_path(name)
try:
bucket = self._get_bucket()
metadata = self._run_sync(bucket.head(full_path)).to_py()
metadata = self._run_sync(bucket.head(full_path))

if metadata and hasattr(metadata, "uploaded"):
uploaded = metadata.uploaded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,34 @@ def test_read_returns_none_on_not_found(self):


class TestR2StorageExistsErrors:
def test_exists_returns_true_for_existing_file(self):
storage = make_live_r2_storage(location=unique_name("r2-existing-exists"))
name = "file.txt"
save_bytes(storage, name, b"content")

try:
assert storage.exists(name) is True
finally:
storage.delete(name)

def test_exists_returns_false_on_not_found(self):
storage = make_live_r2_storage(location=unique_name("r2-missing-exists"))

assert storage.exists("nonexistent.txt") is False


class TestR2StorageSizeErrors:
def test_size_returns_existing_file_size(self):
storage = make_live_r2_storage(location=unique_name("r2-existing-size"))
name = "file.txt"
content = b"test content"
save_bytes(storage, name, content)

try:
assert storage.size(name) == len(content)
finally:
storage.delete(name)

def test_size_returns_zero_on_not_found(self):
storage = make_live_r2_storage(location=unique_name("r2-missing-size"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@


class TestDurableObject(DjangoCFDurableObject, DurableObject):
def __init__(self, ctx, env):
super().__init__(ctx, env)

def get_app(self):
return django_wsgi_app()

Expand All @@ -29,6 +32,9 @@ async def drop_orm_table(self):
self.ctx.storage.sql.exec(DROP_DO_TABLE_SQL)

async def test_storage_is_configured(self):
from workers.entrypoints import DurableObjectContext

assert isinstance(self.ctx, DurableObjectContext)
assert get_storage() is not None

async def test_run_query_uses_configured_storage(self):
Expand All @@ -38,6 +44,10 @@ async def test_run_query_uses_configured_storage(self):
sql.exec(f"CREATE TABLE {table} (id INTEGER PRIMARY KEY, value TEXT)")
sql.exec(f"INSERT INTO {table} VALUES (?, ?)", 1, "ok")

rows = sql.exec(f"SELECT id, value FROM {table}").raw().toArray()
assert isinstance(rows, list)
assert rows == [[1, "ok"]]

result = self.database.run_query(
f"SELECT id, value FROM {table} WHERE id = %s", [1]
)
Expand Down
Loading