Skip to content

Commit 52dee3c

Browse files
committed
basic upload_project_dataset unit tests
1 parent ac47101 commit 52dee3c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

test/mocking.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,12 @@ function _restcall_mocked(method, url, headers, payload; query)
417417
end
418418
payload = JSON.parse(something(payload, "{}"))
419419
if isempty(payload) || !haskey(payload, "action")
420-
if "$(MOCK_USERNAME)/$(dataset)" in existing_datasets
420+
is_existing_dataset = if is_user
421+
"$(MOCK_USERNAME)/$(dataset)" in existing_datasets
422+
else
423+
UUIDs.UUID(dataset) in uuidhash.(existing_datasets)
424+
end
425+
if is_existing_dataset
421426
Dict{String, Any}(
422427
"location" => Dict{String, Any}(
423428
"bucket" => "",
@@ -440,7 +445,6 @@ function _restcall_mocked(method, url, headers, payload; query)
440445
end
441446
else
442447
@assert payload["action"] == "close"
443-
dataset = payload["name"]
444448
Dict{String, Any}(
445449
"size_bytes" => 8124,
446450
"dataset_id" => "c1488c3f-0910-4f73-9c40-14f3c7a8696b",

test/projects.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,27 @@ end
166166
end
167167
end
168168

169+
@testset "JuliaHub.upload_project_dataset()" begin
170+
Mocking.apply(mocking_patch) do
171+
@test JuliaHub.upload_project_dataset("example-dataset", @__FILE__) isa JuliaHub.Dataset
172+
@test JuliaHub.upload_project_dataset(("anotheruser", "publicdataset"), @__FILE__) isa
173+
JuliaHub.Dataset
174+
@test_throws JuliaHub.InvalidRequestError JuliaHub.upload_project_dataset(
175+
("non-existent-user", "example-dataset"), @__FILE__
176+
) isa JuliaHub.Dataset
177+
@test_throws JuliaHub.InvalidRequestError JuliaHub.upload_project_dataset(
178+
"no-such-dataset", @__FILE__
179+
)
180+
dataset_noproject = JuliaHub.dataset("example-dataset")
181+
@test dataset_noproject.project === nothing
182+
dataset = JuliaHub.upload_project_dataset(dataset_noproject, @__FILE__)
183+
@test dataset isa JuliaHub.Dataset
184+
@test dataset.project isa JuliaHub.DatasetProjectLink
185+
@test dataset.project.uuid === project_auth_2.project_id
186+
@test dataset.project.is_writable === false
187+
@test JuliaHub.upload_project_dataset(dataset_noproject, @__FILE__) isa JuliaHub.Dataset
188+
end
189+
end
190+
169191
# We'll restore the default (non-project) global auth
170192
JuliaHub.__AUTH__[] = DEFAULT_GLOBAL_MOCK_AUTH

0 commit comments

Comments
 (0)