Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Feb 29, 2024
1 parent 939cbf1 commit 1ed5a55
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
3 changes: 2 additions & 1 deletion dandi/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ class SampleDandisetFactory:
local_dandi_api: DandiAPI
tmp_path_factory: pytest.TempPathFactory

def mkdandiset(self, name: str) -> SampleDandiset:
def mkdandiset(self, name: str, embargo: bool = False) -> SampleDandiset:
d = self.local_dandi_api.client.create_dandiset(
name,
# Minimal metadata needed to create a publishable Dandiset:
Expand All @@ -539,6 +539,7 @@ def mkdandiset(self, name: str) -> SampleDandiset:
}
],
},
embargo=embargo,
)
dspath = self.tmp_path_factory.mktemp("dandiset")
(dspath / dandiset_metadata_file).write_text(f"identifier: '{d.identifier}'\n")
Expand Down
44 changes: 42 additions & 2 deletions dandi/tests/test_dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import requests
import responses

from .fixtures import DandiAPI, SampleDandiset
from .fixtures import DandiAPI, SampleDandiset, SampleDandisetFactory
from .skip import mark
from .. import dandiapi
from ..consts import (
Expand Down Expand Up @@ -329,7 +329,47 @@ def test_check_schema_version_mismatch() -> None:

def test_get_dandisets(text_dandiset: SampleDandiset) -> None:
dandisets = list(text_dandiset.client.get_dandisets())
assert sum(1 for d in dandisets if d.identifier == text_dandiset.dandiset_id) == 1
assert text_dandiset.dandiset_id in [d.identifier for d in dandisets]

Check warning on line 332 in dandi/tests/test_dandiapi.py

View check run for this annotation

Codecov / codecov/patch

dandi/tests/test_dandiapi.py#L332

Added line #L332 was not covered by tests


def test_get_embargoed_dandisets(
sample_dandiset_factory: SampleDandisetFactory,
) -> None:
ds = sample_dandiset_factory.mkdandiset("Embargoed Dandiset", embargo=True)
dandisets = list(ds.client.get_dandisets(embargoed=True))
assert ds.dandiset_id in [d.identifier for d in dandisets]
dandisets = list(ds.client.get_dandisets(embargoed=False))
assert ds.dandiset_id not in [d.identifier for d in dandisets]
dandisets = list(ds.client.get_dandisets(embargoed=None))
assert ds.dandiset_id not in [d.identifier for d in dandisets]

Check warning on line 344 in dandi/tests/test_dandiapi.py

View check run for this annotation

Codecov / codecov/patch

dandi/tests/test_dandiapi.py#L338-L344

Added lines #L338 - L344 were not covered by tests


def test_get_draft_dandisets(new_dandiset: SampleDandiset) -> None:
dandisets = list(new_dandiset.client.get_dandisets(draft=True))
assert new_dandiset.dandiset_id in [d.identifier for d in dandisets]
dandisets = list(new_dandiset.client.get_dandisets(draft=False))
assert new_dandiset.dandiset_id not in [d.identifier for d in dandisets]
dandisets = list(new_dandiset.client.get_dandisets(draft=None))
assert new_dandiset.dandiset_id in [d.identifier for d in dandisets]

Check warning on line 353 in dandi/tests/test_dandiapi.py

View check run for this annotation

Codecov / codecov/patch

dandi/tests/test_dandiapi.py#L348-L353

Added lines #L348 - L353 were not covered by tests


def test_get_empty_dandisets(new_dandiset: SampleDandiset) -> None:
dandisets = list(new_dandiset.client.get_dandisets(empty=True))
assert new_dandiset.dandiset_id in [d.identifier for d in dandisets]
dandisets = list(new_dandiset.client.get_dandisets(empty=False))
assert new_dandiset.dandiset_id not in [d.identifier for d in dandisets]
dandisets = list(new_dandiset.client.get_dandisets(empty=None))
assert new_dandiset.dandiset_id in [d.identifier for d in dandisets]

Check warning on line 362 in dandi/tests/test_dandiapi.py

View check run for this annotation

Codecov / codecov/patch

dandi/tests/test_dandiapi.py#L357-L362

Added lines #L357 - L362 were not covered by tests


def test_search_get_dandisets(
sample_dandiset_factory: SampleDandisetFactory,
) -> None:
ds = sample_dandiset_factory.mkdandiset("Unicorn Dandiset")
dandisets = list(ds.client.get_dandisets(search="Unicorn"))
assert ds.dandiset_id in [d.identifier for d in dandisets]
dandisets = list(ds.client.get_dandisets(search="Dragon"))
assert ds.dandiset_id not in [d.identifier for d in dandisets]

Check warning on line 372 in dandi/tests/test_dandiapi.py

View check run for this annotation

Codecov / codecov/patch

dandi/tests/test_dandiapi.py#L368-L372

Added lines #L368 - L372 were not covered by tests


def test_get_dandiset_lazy(
Expand Down

0 comments on commit 1ed5a55

Please sign in to comment.