forked from dandi/dandi-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
79 lines (63 loc) · 2.34 KB
/
Copy pathconftest.py
File metadata and controls
79 lines (63 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from __future__ import annotations
from dandischema.conf import get_instance_config
import dandischema.digests.dandietag
import pytest
from pytest_factoryboy import register
from rest_framework.test import APIClient
import dandiapi.api.models
from dandiapi.api.tests.factories import (
AssetBlobFactory,
DandisetFactory,
DraftAssetFactory,
DraftVersionFactory,
EmbargoedAssetBlobFactory,
EmbargoedUploadFactory,
PublishedAssetFactory,
PublishedVersionFactory,
SocialAccountFactory,
UploadFactory,
UserFactory,
)
from dandiapi.zarr.tests.factories import (
EmbargoedZarrArchiveFactory,
ZarrArchiveFactory,
ZarrFileFactory,
)
register(PublishedAssetFactory, _name='published_asset')
register(DraftAssetFactory, _name='draft_asset')
register(AssetBlobFactory)
register(EmbargoedAssetBlobFactory, _name='embargoed_asset_blob')
register(DandisetFactory)
register(EmbargoedUploadFactory)
register(PublishedVersionFactory, _name='published_version')
register(DraftVersionFactory, _name='draft_version')
# registering DraftVersionFactory after PublishedVersionFactory means
# the fixture `version` will always be a draft
register(UserFactory)
register(SocialAccountFactory)
register(UploadFactory)
# zarr app
register(ZarrArchiveFactory)
register(EmbargoedZarrArchiveFactory, _name='embargoed_zarr_archive')
register(ZarrFileFactory, name='zarr_file')
@pytest.fixture(autouse=True)
def _mock_etag_regex(mocker):
"""Expect uploads in every test to set an MD5-style ETag, not a multi-part upload ETag."""
md5_pattern = r'^[a-f0-9]{32}$'
mocker.patch.object(dandiapi.api.models.Upload, 'ETAG_REGEX', md5_pattern)
mocker.patch.object(dandiapi.api.models.AssetBlob, 'ETAG_REGEX', md5_pattern)
mocker.patch.object(dandischema.digests.dandietag.DandiETag, 'REGEX', md5_pattern)
@pytest.fixture(params=[DraftAssetFactory, PublishedAssetFactory], ids=['draft', 'published'])
def asset_factory(request):
return request.param
@pytest.fixture
def asset(asset_factory):
return asset_factory()
@pytest.fixture(params=[DraftVersionFactory, PublishedVersionFactory], ids=['draft', 'published'])
def version(request):
return request.param()
@pytest.fixture
def api_client() -> APIClient:
return APIClient()
def get_first_allowed_license() -> str:
return sorted(x.value for x in get_instance_config().licenses)[0]