dcor-shared 0.12.0__tar.gz → 0.12.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. dcor_shared-0.12.2/.github/workflows/check.yml +105 -0
  2. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/CHANGELOG +5 -0
  3. {dcor_shared-0.12.0/dcor_shared.egg-info → dcor_shared-0.12.2}/PKG-INFO +7 -14
  4. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/README.rst +4 -12
  5. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared/_version.py +9 -4
  6. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared/ckan.py +4 -0
  7. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared/testing.py +36 -10
  8. {dcor_shared-0.12.0 → dcor_shared-0.12.2/dcor_shared.egg-info}/PKG-INFO +7 -14
  9. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared.egg-info/SOURCES.txt +0 -2
  10. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/tests/test_ckan.py +5 -20
  11. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/tests/test_data.py +9 -60
  12. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/tests/test_s3.py +1 -2
  13. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/tests/test_s3cc.py +5 -11
  14. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/tests/test_testing.py +1 -37
  15. dcor_shared-0.12.0/.github/workflows/check.yml +0 -49
  16. dcor_shared-0.12.0/Vagrantfile +0 -72
  17. dcor_shared-0.12.0/vagrant-run-tests.sh +0 -22
  18. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/.github/workflows/deploy_pypi.yml +0 -0
  19. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/.gitignore +0 -0
  20. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/LICENSE +0 -0
  21. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/MANIFEST.in +0 -0
  22. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared/__init__.py +0 -0
  23. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared/data.py +0 -0
  24. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared/dcinst.py +0 -0
  25. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared/mime.py +0 -0
  26. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared/parse.py +0 -0
  27. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared/paths.py +0 -0
  28. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared/rqjob.py +0 -0
  29. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared/s3.py +0 -0
  30. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared/s3cc.py +0 -0
  31. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared.egg-info/dependency_links.txt +0 -0
  32. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared.egg-info/requires.txt +0 -0
  33. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/dcor_shared.egg-info/top_level.txt +0 -0
  34. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/pyproject.toml +0 -0
  35. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/setup.cfg +0 -0
  36. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/tests/data/calibration_beads_47.rtdc +0 -0
  37. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/tests/requirements.txt +0 -0
  38. {dcor_shared-0.12.0 → dcor_shared-0.12.2}/tests/test_basic.py +0 -0
@@ -0,0 +1,105 @@
1
+ name: Checks
2
+ on: [push, pull_request]
3
+
4
+ jobs:
5
+ test:
6
+ strategy:
7
+ matrix:
8
+ ckan-version: ["2.11"]
9
+ dcor_control: ["develop", "pypi"]
10
+ fail-fast: false
11
+
12
+ name: DCOR-CKAN ${{ matrix.ckan-version }} ${{ matrix.dcor_control }}
13
+ runs-on: ubuntu-latest
14
+ container:
15
+ image: ckan/ckan-dev:${{ matrix.ckan-version }}
16
+ options: --user root --hostname dcor-dev-docker
17
+
18
+ services:
19
+ solr:
20
+ image: ckan/ckan-solr:${{ matrix.ckan-version }}-solr9
21
+ postgres:
22
+ image: ckan/ckan-postgres-dev:${{ matrix.ckan-version }}
23
+ env:
24
+ POSTGRES_USER: postgres
25
+ POSTGRES_PASSWORD: postgres
26
+ POSTGRES_DB: postgres
27
+ options: >-
28
+ --health-cmd "pg_isready"
29
+ --health-interval 10s
30
+ --health-timeout 5s
31
+ --health-retries 10
32
+ redis:
33
+ image: redis:3
34
+ minio:
35
+ image: raghavaalajangi95/dcor-minio:latest
36
+ # Note:
37
+ # The official MinIO setup uses standalone mode, which has limitations:
38
+ # - Certain 'mc admin' commands, such as user and policy management, are not supported.
39
+ # - Using these commands will result in errors like:
40
+ # "This 'admin' API is not supported by server in 'mode-server-fs'"
41
+ # - `minio/minio:edge-cicd` container from MinIO is a good alternative,
42
+ # but it is still not supporting 'mc admin policy' command and the container is not managed properly.
43
+ # References:
44
+ # - https://github.com/minio/minio/discussions/16099
45
+ # - https://github.com/orgs/community/discussions/26688#discussioncomment-4183701
46
+ # - https://stackoverflow.com/questions/64031598/creating-a-minios3-container-inside-a-github-actions-yml-file/64188150#64188150
47
+ env:
48
+ MINIO_ROOT_USER: minioadmin
49
+ MINIO_ROOT_PASSWORD: minioadmin
50
+ MINIO_NEW_USER: dcor
51
+ MINIO_NEW_SECRET_KEY: secretkey12345678
52
+ options: >-
53
+ --health-cmd "curl -f http://localhost:9000/minio/health/ready || exit 1"
54
+ --health-interval 10s
55
+ --health-timeout 5s
56
+ --health-retries 10
57
+ ports:
58
+ - 9000:9000
59
+ - 9001:9001
60
+
61
+ env:
62
+ CKAN_SQLALCHEMY_URL: postgresql://ckan_default:pass@postgres/ckan_test
63
+ CKAN_DATASTORE_WRITE_URL: postgresql://datastore_write:pass@postgres/datastore_test
64
+ CKAN_DATASTORE_READ_URL: postgresql://datastore_read:pass@postgres/datastore_test
65
+ CKAN_SOLR_URL: http://solr:8983/solr/ckan
66
+ CKAN_REDIS_URL: redis://redis:6379/1
67
+
68
+ steps:
69
+ - uses: actions/checkout@v4
70
+ with:
71
+ fetch-depth: 0
72
+
73
+ - name: Install and setup DCOR
74
+ run: |
75
+ pip3 install dcor_control
76
+
77
+ # use test-core.ini as default
78
+ cp /srv/app/src/ckan/test-core.ini /srv/app/ckan.ini
79
+ # initialize CKAN database
80
+ ckan -c /srv/app/ckan.ini db init
81
+ # fix location of allowed datastore commands
82
+ # https://github.com/ckan/ckan/issues/8926
83
+ mkdir -p /srv/app/ckanext/datastore/tests/
84
+ printf 'upper\n"count"\n' > /srv/app/ckanext/datastore/tests/allowed_functions.txt
85
+ # complement configuration
86
+ dcor inspect --assume-yes
87
+
88
+ - name: Install latest DCOR extensions from GitHub
89
+ if: matrix.dcor_control == 'develop'
90
+ run: |
91
+ dcor develop --yes
92
+ dcor inspect --assume-yes
93
+
94
+ - name: Install extension and requirements
95
+ run: |
96
+ pip install -e .
97
+ pip install -r ./tests/requirements.txt
98
+
99
+ - name: Run tests
100
+ run: |
101
+ pytest -v --ckan-ini=/srv/app/ckan.ini \
102
+ --cov=dcor_shared \
103
+ --cov-report=xml \
104
+ --cov-append \
105
+ tests
@@ -1,3 +1,8 @@
1
+ 0.12.2
2
+ - fix: testing did not append S3 resources
3
+ 0.12.1
4
+ - ci: migrate to docker
5
+ - ref: deprecate `get_resource_path`, `make_dataset`, `make_resource`
1
6
  0.12.0
2
7
  - feat: introduce rqjob submodule for managing CKAN background jobs
3
8
  0.11.5
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: dcor_shared
3
- Version: 0.12.0
3
+ Version: 0.12.2
4
4
  Summary: Functionalities shared by the DCOR CKAN extensions
5
5
  Author: Paul Müller
6
6
  Maintainer-email: Paul Müller <dev@craban.de>
@@ -18,6 +18,7 @@ Description-Content-Type: text/x-rst
18
18
  License-File: LICENSE
19
19
  Requires-Dist: boto3
20
20
  Requires-Dist: dclab[s3]>=0.60.9
21
+ Dynamic: license-file
21
22
 
22
23
  dcor_shared
23
24
  ===========
@@ -37,22 +38,14 @@ To install the latest release, simply run:
37
38
 
38
39
  Testing
39
40
  -------
40
- Testing is done via vagrant in a virtualmachine using the
41
- `dcor-test <https://app.vagrantup.com/paulmueller/boxes/dcor-test/>` image.
42
- Make sure that `vagrant` and `virtualbox` are installed and run the
43
- following commands in the root of this repository:
44
-
45
- ::
46
-
47
- # Setup virtual machine using `Vagrantfile`
48
- vagrant up
49
- # Run the tests
50
- vagrant ssh -- sudo bash /testing/vagrant-run-tests.sh
41
+ Testing is implemented via GitHub Actions. You may also set up a local
42
+ docker container with CKAN and MinIO. Take a look at the GitHub Actions
43
+ workflow for more information.
51
44
 
52
45
 
53
46
  .. |PyPI Version| image:: https://img.shields.io/pypi/v/dcor_shared.svg
54
47
  :target: https://pypi.python.org/pypi/dcor_shared
55
48
  .. |Build Status| image:: https://img.shields.io/github/actions/workflow/status/DCOR-dev/dcor_shared/check.yml
56
- :target: https://travis-ci.com/DCOR-dev/dcor_shared
49
+ :target: https://github.com/DCOR-dev/dcor_shared/actions/workflows/check.yml
57
50
  .. |Coverage Status| image:: https://img.shields.io/codecov/c/github/DCOR-dev/dcor_shared
58
51
  :target: https://codecov.io/gh/DCOR-dev/dcor_shared
@@ -16,22 +16,14 @@ To install the latest release, simply run:
16
16
 
17
17
  Testing
18
18
  -------
19
- Testing is done via vagrant in a virtualmachine using the
20
- `dcor-test <https://app.vagrantup.com/paulmueller/boxes/dcor-test/>` image.
21
- Make sure that `vagrant` and `virtualbox` are installed and run the
22
- following commands in the root of this repository:
23
-
24
- ::
25
-
26
- # Setup virtual machine using `Vagrantfile`
27
- vagrant up
28
- # Run the tests
29
- vagrant ssh -- sudo bash /testing/vagrant-run-tests.sh
19
+ Testing is implemented via GitHub Actions. You may also set up a local
20
+ docker container with CKAN and MinIO. Take a look at the GitHub Actions
21
+ workflow for more information.
30
22
 
31
23
 
32
24
  .. |PyPI Version| image:: https://img.shields.io/pypi/v/dcor_shared.svg
33
25
  :target: https://pypi.python.org/pypi/dcor_shared
34
26
  .. |Build Status| image:: https://img.shields.io/github/actions/workflow/status/DCOR-dev/dcor_shared/check.yml
35
- :target: https://travis-ci.com/DCOR-dev/dcor_shared
27
+ :target: https://github.com/DCOR-dev/dcor_shared/actions/workflows/check.yml
36
28
  .. |Coverage Status| image:: https://img.shields.io/codecov/c/github/DCOR-dev/dcor_shared
37
29
  :target: https://codecov.io/gh/DCOR-dev/dcor_shared
@@ -1,8 +1,13 @@
1
- # file generated by setuptools_scm
1
+ # file generated by setuptools-scm
2
2
  # don't change, don't track in version control
3
+
4
+ __all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
5
+
3
6
  TYPE_CHECKING = False
4
7
  if TYPE_CHECKING:
5
- from typing import Tuple, Union
8
+ from typing import Tuple
9
+ from typing import Union
10
+
6
11
  VERSION_TUPLE = Tuple[Union[int, str], ...]
7
12
  else:
8
13
  VERSION_TUPLE = object
@@ -12,5 +17,5 @@ __version__: str
12
17
  __version_tuple__: VERSION_TUPLE
13
18
  version_tuple: VERSION_TUPLE
14
19
 
15
- __version__ = version = '0.12.0'
16
- __version_tuple__ = version_tuple = (0, 12, 0)
20
+ __version__ = version = '0.12.2'
21
+ __version_tuple__ = version_tuple = (0, 12, 2)
@@ -1,5 +1,6 @@
1
1
  import os
2
2
  import pathlib
3
+ import warnings
3
4
 
4
5
  from .parse import get_ini_config_option
5
6
 
@@ -77,6 +78,9 @@ def get_resource_path(resource_id, create_dirs=False):
77
78
 
78
79
  If `create_dirs` is True, create the parent directory tree.
79
80
  """
81
+ warnings.warn("`get_resource_path` should not be used since DCOR moved "
82
+ "to storing data solely on S3",
83
+ DeprecationWarning)
80
84
  rid = resource_id
81
85
  resources_path = get_ckan_storage_path() / "resources"
82
86
  pdir = resources_path / rid[:3] / rid[3:6]
@@ -5,6 +5,7 @@ import numbers
5
5
  import pathlib
6
6
  from typing import Dict, List
7
7
  import uuid
8
+ import warnings
8
9
 
9
10
  import ckan.authz
10
11
  import ckan.tests.factories as factories
@@ -47,6 +48,10 @@ def create_with_upload_no_temp(clean_db, ckan_config, monkeypatch):
47
48
  def make_dataset(create_context=None, owner_org=None, create_with_upload=None,
48
49
  resource_path=None, activate=False, **kwargs):
49
50
  """Create a dataset with a resource for testing"""
51
+ warnings.warn(
52
+ "`make_dataset` is deprecated, use `make_dataset_via_s3` instead",
53
+ DeprecationWarning)
54
+
50
55
  if create_context is None:
51
56
  user = factories.User()
52
57
  create_context = {'ignore_auth': False,
@@ -163,7 +168,6 @@ def make_dataset_via_s3(
163
168
  rid = make_resource_via_s3(resource_path=resource_path,
164
169
  organization_id=owner_org["id"],
165
170
  dataset_id=ds_dict["id"],
166
- create_context=create_context,
167
171
  private=ds_dict.get("private", False)
168
172
  )
169
173
  else:
@@ -188,6 +192,9 @@ def make_dataset_via_s3(
188
192
 
189
193
  def make_resource(resource_path, create_with_upload, create_context,
190
194
  dataset_id):
195
+ warnings.warn(
196
+ "`make_resource` is deprecated, use `make_resource_via_s3` instead",
197
+ DeprecationWarning)
191
198
  content = resource_path.read_bytes()
192
199
  rs = create_with_upload(
193
200
  data=content,
@@ -200,9 +207,25 @@ def make_resource(resource_path, create_with_upload, create_context,
200
207
  return resource
201
208
 
202
209
 
203
- def make_resource_via_s3(resource_path, organization_id, dataset_id,
204
- create_context, private=False):
210
+ def make_resource_via_s3(
211
+ resource_path: pathlib.Path | str,
212
+ organization_id: str,
213
+ dataset_id: str,
214
+ create_context: Dict = None,
215
+ private: bool = False,
216
+ ret_dict: bool = False,
217
+ ):
205
218
  """Upload a resource to S3 and register it with CKAN"""
219
+ if create_context is not None:
220
+ warnings.warn("Create context has no effect for creating resources "
221
+ f"via S3 for testing (got {create_context})",
222
+ DeprecationWarning)
223
+
224
+ user = factories.Sysadmin()
225
+ create_context = {'ignore_auth': False,
226
+ 'user': user['name'],
227
+ 'api_version': 3}
228
+
206
229
  bucket_name = get_ckan_config_option(
207
230
  "dcor_object_store.bucket_name").format(
208
231
  organization_id=organization_id)
@@ -216,15 +239,18 @@ def make_resource_via_s3(resource_path, organization_id, dataset_id,
216
239
 
217
240
  revise_dict = {
218
241
  "match": {"id": dataset_id},
219
- "update": {"resources": [{"id": rid,
220
- "name": resource_path.name,
221
- "s3_available": True,
222
- }
223
- ]
224
- }
242
+ "update__resources__extend": [{
243
+ "id": rid,
244
+ "name": resource_path.name,
245
+ "s3_available": True,
246
+ }]
225
247
  }
226
248
  helpers.call_action("package_revise", create_context, **revise_dict)
227
- return rid
249
+ if ret_dict:
250
+ res_dict = helpers.call_action("resource_show", id=rid)
251
+ return res_dict
252
+ else:
253
+ return rid
228
254
 
229
255
 
230
256
  def synchronous_enqueue_job(job_func, args=None, kwargs=None, title=None,
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: dcor_shared
3
- Version: 0.12.0
3
+ Version: 0.12.2
4
4
  Summary: Functionalities shared by the DCOR CKAN extensions
5
5
  Author: Paul Müller
6
6
  Maintainer-email: Paul Müller <dev@craban.de>
@@ -18,6 +18,7 @@ Description-Content-Type: text/x-rst
18
18
  License-File: LICENSE
19
19
  Requires-Dist: boto3
20
20
  Requires-Dist: dclab[s3]>=0.60.9
21
+ Dynamic: license-file
21
22
 
22
23
  dcor_shared
23
24
  ===========
@@ -37,22 +38,14 @@ To install the latest release, simply run:
37
38
 
38
39
  Testing
39
40
  -------
40
- Testing is done via vagrant in a virtualmachine using the
41
- `dcor-test <https://app.vagrantup.com/paulmueller/boxes/dcor-test/>` image.
42
- Make sure that `vagrant` and `virtualbox` are installed and run the
43
- following commands in the root of this repository:
44
-
45
- ::
46
-
47
- # Setup virtual machine using `Vagrantfile`
48
- vagrant up
49
- # Run the tests
50
- vagrant ssh -- sudo bash /testing/vagrant-run-tests.sh
41
+ Testing is implemented via GitHub Actions. You may also set up a local
42
+ docker container with CKAN and MinIO. Take a look at the GitHub Actions
43
+ workflow for more information.
51
44
 
52
45
 
53
46
  .. |PyPI Version| image:: https://img.shields.io/pypi/v/dcor_shared.svg
54
47
  :target: https://pypi.python.org/pypi/dcor_shared
55
48
  .. |Build Status| image:: https://img.shields.io/github/actions/workflow/status/DCOR-dev/dcor_shared/check.yml
56
- :target: https://travis-ci.com/DCOR-dev/dcor_shared
49
+ :target: https://github.com/DCOR-dev/dcor_shared/actions/workflows/check.yml
57
50
  .. |Coverage Status| image:: https://img.shields.io/codecov/c/github/DCOR-dev/dcor_shared
58
51
  :target: https://codecov.io/gh/DCOR-dev/dcor_shared
@@ -3,9 +3,7 @@ CHANGELOG
3
3
  LICENSE
4
4
  MANIFEST.in
5
5
  README.rst
6
- Vagrantfile
7
6
  pyproject.toml
8
- vagrant-run-tests.sh
9
7
  .github/workflows/check.yml
10
8
  .github/workflows/deploy_pypi.yml
11
9
  dcor_shared/__init__.py
@@ -1,12 +1,10 @@
1
1
  import pathlib
2
2
  from unittest import mock
3
3
 
4
- import ckanext.dcor_schemas.plugin
5
-
6
4
  from dcor_shared import get_resource_dc_config, get_resource_info
7
5
 
8
6
  import pytest
9
- from dcor_shared.testing import make_dataset, synchronous_enqueue_job
7
+ from dcor_shared.testing import make_dataset_via_s3, synchronous_enqueue_job
10
8
 
11
9
  data_path = pathlib.Path(__file__).parent / "data"
12
10
 
@@ -15,15 +13,8 @@ data_path = pathlib.Path(__file__).parent / "data"
15
13
  @pytest.mark.usefixtures('clean_db', 'with_request_context')
16
14
  @mock.patch('ckan.plugins.toolkit.enqueue_job',
17
15
  side_effect=synchronous_enqueue_job)
18
- def test_get_resource_dc_config(enqueue_job_mock, create_with_upload,
19
- monkeypatch):
20
- monkeypatch.setattr(
21
- ckanext.dcor_schemas.plugin,
22
- 'DISABLE_AFTER_DATASET_CREATE_FOR_CONCURRENT_JOB_TESTS',
23
- True)
24
-
25
- _, res_dict = make_dataset(
26
- create_with_upload=create_with_upload,
16
+ def test_get_resource_dc_config(enqueue_job_mock):
17
+ _, res_dict = make_dataset_via_s3(
27
18
  resource_path=data_path / "calibration_beads_47.rtdc",
28
19
  activate=True)
29
20
 
@@ -37,14 +28,8 @@ def test_get_resource_dc_config(enqueue_job_mock, create_with_upload,
37
28
  @pytest.mark.usefixtures('clean_db', 'with_request_context')
38
29
  @mock.patch('ckan.plugins.toolkit.enqueue_job',
39
30
  side_effect=synchronous_enqueue_job)
40
- def test_get_resource_info(enqueue_job_mock, create_with_upload, monkeypatch):
41
- monkeypatch.setattr(
42
- ckanext.dcor_schemas.plugin,
43
- 'DISABLE_AFTER_DATASET_CREATE_FOR_CONCURRENT_JOB_TESTS',
44
- True)
45
-
46
- ds_dict, res_dict = make_dataset(
47
- create_with_upload=create_with_upload,
31
+ def test_get_resource_info(enqueue_job_mock):
32
+ ds_dict, res_dict = make_dataset_via_s3(
48
33
  resource_path=data_path / "calibration_beads_47.rtdc",
49
34
  activate=True)
50
35
 
@@ -5,15 +5,14 @@ from unittest import mock
5
5
  import uuid
6
6
 
7
7
  from ckan import logic
8
- import ckanext.dcor_schemas.plugin
9
8
 
10
9
  from dcor_shared import (
11
- get_dc_instance, get_resource_path, s3, sha256sum, wait_for_resource
10
+ get_dc_instance, s3, sha256sum, wait_for_resource
12
11
  )
13
12
 
14
13
  import pytest
15
14
  import ckan.tests.factories as factories
16
- from dcor_shared.testing import make_dataset, synchronous_enqueue_job
15
+ from dcor_shared.testing import make_dataset_via_s3, synchronous_enqueue_job
17
16
 
18
17
  data_path = pathlib.Path(__file__).parent / "data"
19
18
 
@@ -22,23 +21,14 @@ data_path = pathlib.Path(__file__).parent / "data"
22
21
  @pytest.mark.usefixtures('clean_db', 'with_request_context')
23
22
  @mock.patch('ckan.plugins.toolkit.enqueue_job',
24
23
  side_effect=synchronous_enqueue_job)
25
- def test_get_dc_instance_file(enqueue_job_mock, create_with_upload,
26
- monkeypatch):
27
- monkeypatch.setattr(
28
- ckanext.dcor_schemas.plugin,
29
- 'DISABLE_AFTER_DATASET_CREATE_FOR_CONCURRENT_JOB_TESTS',
30
- True)
31
-
32
- ds_dict, _ = make_dataset(
33
- create_with_upload=create_with_upload,
24
+ def test_get_dc_instance_file(enqueue_job_mock):
25
+ ds_dict, _ = make_dataset_via_s3(
34
26
  resource_path=data_path / "calibration_beads_47.rtdc",
35
27
  activate=True)
36
28
 
37
29
  rid = ds_dict["resources"][0]["id"]
38
- resource_path = pathlib.Path(get_resource_path(rid))
39
- assert resource_path.exists(), "sanity check"
40
30
  with get_dc_instance(rid) as ds:
41
- assert str(ds.path) == str(resource_path)
31
+ assert len(ds)
42
32
 
43
33
 
44
34
  @pytest.mark.ckan_config('ckan.storage_path',
@@ -60,24 +50,13 @@ def test_get_dc_instance_file_fails_without_actual_resource():
60
50
  @pytest.mark.usefixtures('clean_db', 'with_request_context')
61
51
  @mock.patch('ckan.plugins.toolkit.enqueue_job',
62
52
  side_effect=synchronous_enqueue_job)
63
- def test_get_dc_instance_s3(enqueue_job_mock, create_with_upload,
64
- monkeypatch):
65
- monkeypatch.setattr(
66
- ckanext.dcor_schemas.plugin,
67
- 'DISABLE_AFTER_DATASET_CREATE_FOR_CONCURRENT_JOB_TESTS',
68
- True)
69
-
70
- ds_dict, _ = make_dataset(
71
- create_with_upload=create_with_upload,
53
+ def test_get_dc_instance_s3(enqueue_job_mock):
54
+ ds_dict, _ = make_dataset_via_s3(
72
55
  resource_path=data_path / "calibration_beads_47.rtdc",
73
56
  activate=True)
74
57
 
75
58
  res_dict = ds_dict["resources"][0]
76
59
  rid = res_dict["id"]
77
- resource_path = pathlib.Path(get_resource_path(rid))
78
- # remove the file, so DCOR falls back to the S3 resource
79
- resource_path.unlink()
80
- assert not resource_path.exists(), "sanity check"
81
60
  with get_dc_instance(rid) as ds:
82
61
  assert ds.path.startswith("http")
83
62
  assert res_dict["s3_available"]
@@ -85,6 +64,8 @@ def test_get_dc_instance_s3(enqueue_job_mock, create_with_upload,
85
64
 
86
65
 
87
66
  @pytest.mark.ckan_config('ckan.plugins', 'dcor_depot dcor_schemas')
67
+ @pytest.mark.ckan_config('dcor_object_store.bucket_name',
68
+ 'circle-{organization_id}')
88
69
  @pytest.mark.usefixtures('clean_db', 'with_request_context')
89
70
  @mock.patch('ckan.plugins.toolkit.enqueue_job',
90
71
  side_effect=synchronous_enqueue_job)
@@ -125,38 +106,6 @@ def test_wait_for_resource_s3(monkeypatch):
125
106
  wait_for_resource(res_id)
126
107
 
127
108
 
128
- @pytest.mark.ckan_config('ckan.plugins', '') # disable plugins
129
- def test_wait_for_resource_no_s3_url_no_plugins(monkeypatch):
130
- res_id = str(uuid.uuid4())
131
- monkeypatch.setattr(logic, "get_action",
132
- lambda x: lambda context, data_dict: {
133
- "id": res_id})
134
- # Create the actual path
135
- rp = pathlib.Path(get_resource_path(res_id))
136
- rp.parent.mkdir(parents=True, exist_ok=True)
137
- rp.write_bytes(b"This is not a dummy file, but a fake DC file!")
138
- # Should not raise an exception
139
- wait_for_resource(res_id)
140
-
141
-
142
- @pytest.mark.ckan_config('ckan.plugins', 'dcor_depot')
143
- def test_wait_for_resource_no_s3_url_with_dcor_depot_plugin(monkeypatch):
144
- res_id = str(uuid.uuid4())
145
- monkeypatch.setattr(logic, "get_action",
146
- lambda x: lambda context, data_dict: {
147
- "id": res_id})
148
- # Create the actual path
149
- rp = pathlib.Path(get_resource_path(res_id))
150
- rp.parent.mkdir(parents=True, exist_ok=True)
151
- rp.write_bytes(b"This is not a dummy file, but a fake DC file!")
152
- rp2 = rp.with_name("test.rtdc")
153
- rp.rename(rp2)
154
- rp.symlink_to(rp2)
155
-
156
- # Should not raise an exception
157
- wait_for_resource(res_id)
158
-
159
-
160
109
  def test_wait_resource_not_available(monkeypatch):
161
110
  res_id = str(uuid.uuid4())
162
111
  monkeypatch.setattr(logic, "get_action",
@@ -1,14 +1,13 @@
1
1
  import hashlib
2
2
  from unittest import mock
3
3
  import pathlib
4
- import random
5
4
  import uuid
6
5
 
7
6
  import botocore.exceptions
8
7
  import pytest
9
8
  import requests
10
9
 
11
- from dcor_shared import get_ckan_config_option, s3, sha256sum
10
+ from dcor_shared import s3, sha256sum
12
11
  from dcor_shared.testing import upload_presigned_to_s3
13
12
 
14
13
 
@@ -7,10 +7,9 @@ import pytest
7
7
  from ckan import model
8
8
  import ckan.tests.helpers as helpers
9
9
  import ckan.tests.factories as factories
10
- import ckanext.dcor_schemas.plugin
11
10
 
12
11
  from dcor_shared.testing import (
13
- make_dataset, synchronous_enqueue_job, upload_presigned_to_s3
12
+ make_dataset_via_s3, synchronous_enqueue_job, upload_presigned_to_s3
14
13
  )
15
14
  from dcor_shared import s3, s3cc, sha256sum
16
15
 
@@ -140,6 +139,8 @@ def test_get_s3_attributes_for_artifact(enqueue_job_mock):
140
139
 
141
140
 
142
141
  @pytest.mark.ckan_config('ckan.plugins', 'dcor_schemas')
142
+ @pytest.mark.ckan_config('dcor_object_store.bucket_name',
143
+ 'circle-{organization_id}')
143
144
  @pytest.mark.usefixtures('clean_db', 'with_request_context')
144
145
  @mock.patch('ckan.plugins.toolkit.enqueue_job',
145
146
  side_effect=synchronous_enqueue_job)
@@ -170,20 +171,13 @@ def test_get_s3_handle(enqueue_job_mock):
170
171
  @pytest.mark.usefixtures('clean_db', 'with_request_context')
171
172
  @mock.patch('ckan.plugins.toolkit.enqueue_job',
172
173
  side_effect=synchronous_enqueue_job)
173
- def test_get_s3_dc_handle_basin_based(enqueue_job_mock, create_with_upload,
174
- monkeypatch, tmp_path):
175
- monkeypatch.setattr(
176
- ckanext.dcor_schemas.plugin,
177
- 'DISABLE_AFTER_DATASET_CREATE_FOR_CONCURRENT_JOB_TESTS',
178
- True)
179
-
174
+ def test_get_s3_dc_handle_basin_based(enqueue_job_mock, tmp_path):
180
175
  resource_path = tmp_path / "data.rtdc"
181
176
  shutil.copy2(data_path / "calibration_beads_47.rtdc", resource_path)
182
177
  with h5py.File(resource_path, "a") as h5:
183
178
  del h5["events/volume"]
184
179
 
185
- _, res_dict = make_dataset(
186
- create_with_upload=create_with_upload,
180
+ _, res_dict = make_dataset_via_s3(
187
181
  resource_path=resource_path,
188
182
  activate=True)
189
183
  rid = res_dict["id"]
@@ -4,48 +4,12 @@ import pytest
4
4
  import ckan.tests.factories as factories
5
5
  import requests
6
6
 
7
- from dcor_shared.testing import make_dataset, make_dataset_via_s3
7
+ from dcor_shared.testing import make_dataset_via_s3
8
8
  from dcor_shared import s3cc, sha256sum
9
9
 
10
10
  data_path = pathlib.Path(__file__).parent / "data"
11
11
 
12
12
 
13
- @pytest.mark.ckan_config('ckan.plugins', 'dcor_schemas')
14
- @pytest.mark.usefixtures('clean_db', 'with_request_context')
15
- def test_make_dataset():
16
- user = factories.User()
17
- owner_org = factories.Organization(users=[{
18
- 'name': user['id'],
19
- 'capacity': 'admin'
20
- }])
21
- # Note: `call_action` bypasses authorization!
22
- create_context = {'ignore_auth': False,
23
- 'user': user['name'], 'api_version': 3}
24
- ds_dict = make_dataset(create_context, owner_org,
25
- activate=False)
26
- assert ds_dict["state"] == "draft"
27
-
28
-
29
- @pytest.mark.ckan_config('ckan.plugins', 'dcor_schemas')
30
- @pytest.mark.usefixtures('clean_db', 'with_request_context')
31
- def test_make_dataset_no_user_specified():
32
- ds_dict = make_dataset(activate=False)
33
- assert ds_dict["state"] == "draft"
34
-
35
-
36
- @pytest.mark.ckan_config('ckan.plugins', 'dcor_schemas')
37
- @pytest.mark.usefixtures('clean_db', 'with_request_context')
38
- def test_make_dataset_with_resource(create_with_upload):
39
- # upload a *valid* [sic] .rtdc File (this is the control)
40
- ds_dict, res_dict = make_dataset(
41
- create_with_upload=create_with_upload,
42
- resource_path=data_path / "calibration_beads_47.rtdc",
43
- activate=True)
44
- assert len(ds_dict["resources"]) == 1
45
- assert "id" in res_dict
46
- assert res_dict["package_id"] == ds_dict["id"]
47
-
48
-
49
13
  @pytest.mark.ckan_config('ckan.plugins', 'dcor_schemas')
50
14
  @pytest.mark.usefixtures('clean_db', 'with_request_context')
51
15
  def test_make_dataset_via_s3():
@@ -1,49 +0,0 @@
1
- name: Checks
2
-
3
- on:
4
- push:
5
- pull_request:
6
-
7
- # only allow one job to run
8
- concurrency: general_workflow
9
-
10
- jobs:
11
- checks:
12
- runs-on: macos-12
13
- steps:
14
- - uses: actions/checkout@main
15
- - name: Set up Python 3.8
16
- uses: actions/setup-python@main
17
- with:
18
- python-version: "3.8"
19
- - name: Install flake8 dependencies
20
- run: |
21
- # prerequisites
22
- python -m pip install --upgrade pip wheel
23
- python -m pip install flake8
24
- - name: Lint with flake8
25
- run: |
26
- flake8 --exclude _version.py .
27
- - name: Cache vagrant images
28
- uses: actions/cache@v3
29
- env:
30
- cache-name: vagrant-image
31
- with:
32
- path: ~/.vagrant.d
33
- key: macos-build-${{ env.cache-name }}-${{ hashFiles('Vagrantfile') }}
34
- restore-keys: |
35
- macos-build-${{ env.cache-name }}-
36
- - name: save environment variables for codecov in VM
37
- run: |
38
- env | grep GITHUB > environment.txt
39
- cat environment.txt
40
- - name: Get the latest box and remove old boxes from the GH Actions cache
41
- run: |
42
- vagrant box update
43
- vagrant box prune
44
- - name: Setup vagrant VM
45
- run: |
46
- vagrant up
47
- - name: Run tests in vagrant VM
48
- run: |
49
- vagrant ssh -- sudo bash /testing/vagrant-run-tests.sh
@@ -1,72 +0,0 @@
1
- # -*- mode: ruby -*-
2
- # vi: set ft=ruby :
3
-
4
- # All Vagrant configuration is done below. The "2" in Vagrant.configure
5
- # configures the configuration version (we support older styles for
6
- # backwards compatibility). Please don't change it unless you know what
7
- # you're doing.
8
- Vagrant.configure("2") do |config|
9
- # The most common configuration options are documented and commented below.
10
- # For a complete reference, please see the online documentation at
11
- # https://docs.vagrantup.com.
12
-
13
- # Every Vagrant development environment requires a box. You can search for
14
- # boxes at https://vagrantcloud.com/search.
15
- config.vm.box = "paulmueller/dcor-test"
16
-
17
- # Disable automatic box update checking. If you disable this, then
18
- # boxes will only be checked for updates when the user runs
19
- # `vagrant box outdated`. This is not recommended.
20
- # config.vm.box_check_update = false
21
-
22
- # Create a forwarded port mapping which allows access to a specific port
23
- # within the machine from a port on the host machine. In the example below,
24
- # accessing "localhost:8080" will access port 80 on the guest machine.
25
- # NOTE: This will enable public access to the opened port
26
- # config.vm.network "forwarded_port", guest: 80, host: 8080
27
-
28
- # Create a forwarded port mapping which allows access to a specific port
29
- # within the machine from a port on the host machine and only allow access
30
- # via 127.0.0.1 to disable public access
31
- # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
32
-
33
- # Create a private network, which allows host-only access to the machine
34
- # using a specific IP.
35
- # config.vm.network "private_network", ip: "192.168.33.10"
36
-
37
- # Create a public network, which generally matched to bridged network.
38
- # Bridged networks make the machine appear as another physical device on
39
- # your network.
40
- # config.vm.network "public_network"
41
-
42
- # Share an additional folder to the guest VM. The first argument is
43
- # the path on the host to the actual folder. The second argument is
44
- # the path on the guest to mount the folder. And the optional third
45
- # argument is a set of non-required options.
46
- # config.vm.synced_folder "../data", "/vagrant_data"
47
- # config.vm.synced_folder ".", "/vagrant", disabled: true
48
- config.vm.synced_folder ".", "/testing", type: "rsync",
49
- rsync__args: ["-vzra", "--delete"],
50
- rsync__exclude: ["*.pyc", "__pycache__"],
51
- owner: "www-data"
52
- # Provider-specific configuration so you can fine-tune various
53
- # backing providers for Vagrant. These expose provider-specific options.
54
- # Reduce requirements so everythin runs on GitHub Actions
55
- config.vm.provider "virtualbox" do |v|
56
- v.memory = 2048
57
- v.cpus = 1
58
- end
59
-
60
-
61
- # Enable provisioning with a shell script. Additional provisioners such as
62
- # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
63
- # documentation for more information about their specific syntax and use.
64
- # config.vm.provision "shell", inline: <<-SHELL
65
- # apt-get update
66
- # apt-get install -y apache2
67
- # SHELL
68
-
69
- # Prevent reinstallation of guest additinos on every vagrant up
70
- # (Uncomment the next line in your CI tests)
71
- # config.vbguest.auto_update = false
72
- end
@@ -1,22 +0,0 @@
1
- set -e
2
- set -x
3
- # Set CKAN_INI to testing
4
- export CKAN_INI=/etc/ckan/default/ckan.ini
5
- # Go to the directory of this script
6
- cd "$(dirname "${BASH_SOURCE[0]}")"
7
- # Source the CKAN environment
8
- source /usr/lib/ckan/default/bin/activate
9
- # Update pip
10
- pip install --upgrade pip wheel
11
- # Update all DCOR extensions
12
- dcor update --yes
13
- # Install the current package in editable mode for testing
14
- pip install -e .
15
- pip install -r tests/requirements.txt
16
- # run tests with coverage
17
- coverage run --source=dcor_shared -m pytest -p no:warnings tests
18
- # Get GitHub environment variables so codecov detects GH Actions (allow command to fail)
19
- export $(grep -v '^#' environment.txt | xargs) || exit 0
20
- curl -Os https://uploader.codecov.io/latest/linux/codecov
21
- chmod +x codecov
22
- ./codecov
File without changes
File without changes
File without changes
File without changes