fakecspace 0.1.0__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.
- fakecspace-0.1.0/LICENSE +22 -0
- fakecspace-0.1.0/PKG-INFO +137 -0
- fakecspace-0.1.0/README.md +105 -0
- fakecspace-0.1.0/pyproject.toml +77 -0
- fakecspace-0.1.0/setup.cfg +4 -0
- fakecspace-0.1.0/src/fakecspace/__init__.py +5 -0
- fakecspace-0.1.0/src/fakecspace/accounts.py +73 -0
- fakecspace-0.1.0/src/fakecspace/app.py +598 -0
- fakecspace-0.1.0/src/fakecspace/bands.py +100 -0
- fakecspace-0.1.0/src/fakecspace/context.py +31 -0
- fakecspace-0.1.0/src/fakecspace/hooks.py +303 -0
- fakecspace-0.1.0/src/fakecspace/samples.py +41 -0
- fakecspace-0.1.0/src/fakecspace/seeds.py +63 -0
- fakecspace-0.1.0/src/fakecspace/store.py +233 -0
- fakecspace-0.1.0/src/fakecspace/vocab.py +94 -0
- fakecspace-0.1.0/src/fakecspace.egg-info/PKG-INFO +137 -0
- fakecspace-0.1.0/src/fakecspace.egg-info/SOURCES.txt +23 -0
- fakecspace-0.1.0/src/fakecspace.egg-info/dependency_links.txt +1 -0
- fakecspace-0.1.0/src/fakecspace.egg-info/requires.txt +18 -0
- fakecspace-0.1.0/src/fakecspace.egg-info/top_level.txt +1 -0
- fakecspace-0.1.0/tests/test_accounts.py +95 -0
- fakecspace-0.1.0/tests/test_bmu_flow.py +125 -0
- fakecspace-0.1.0/tests/test_failures.py +132 -0
- fakecspace-0.1.0/tests/test_museums.py +70 -0
- fakecspace-0.1.0/tests/test_serena_hooks.py +103 -0
fakecspace-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright ©2026. The Regents of the University of California (Regents). All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and distribute this software and its documentation
|
|
4
|
+
for educational, research, and not-for-profit purposes, without fee and without a
|
|
5
|
+
signed licensing agreement, is hereby granted, provided that the above copyright
|
|
6
|
+
notice, this paragraph and the following two paragraphs appear in all copies,
|
|
7
|
+
modifications, and distributions.
|
|
8
|
+
|
|
9
|
+
Contact The Office of Technology Licensing, UC Berkeley, 2150 Shattuck Avenue,
|
|
10
|
+
Suite 510, Berkeley, CA 94720-1620, (510) 643-7201, otl@berkeley.edu,
|
|
11
|
+
http://ipira.berkeley.edu/industry-info for commercial licensing opportunities.
|
|
12
|
+
|
|
13
|
+
IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
|
14
|
+
INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF
|
|
15
|
+
THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED
|
|
16
|
+
OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
17
|
+
|
|
18
|
+
REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
|
20
|
+
SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED
|
|
21
|
+
"AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
|
22
|
+
ENHANCEMENTS, OR MODIFICATIONS.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fakecspace
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A small simulated CollectionSpace services API, for developing and testing UC Berkeley's CollectionSpace apps. Not CollectionSpace; never use it with real data.
|
|
5
|
+
Author: UC Berkeley Research, Teaching, and Learning
|
|
6
|
+
License-Expression: LicenseRef-UC-Regents
|
|
7
|
+
Project-URL: Source, https://github.com/ets-berkeley-edu/cspace-fakecspace
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Framework :: FastAPI
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: Testing :: Mocking
|
|
13
|
+
Requires-Python: >=3.11
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: fastapi>=0.120
|
|
17
|
+
Requires-Dist: python-multipart>=0.0.20
|
|
18
|
+
Requires-Dist: defusedxml>=0.7
|
|
19
|
+
Provides-Extra: server
|
|
20
|
+
Requires-Dist: uvicorn[standard]>=0.30; extra == "server"
|
|
21
|
+
Provides-Extra: bands
|
|
22
|
+
Requires-Dist: pyvips[binary]>=3.0; extra == "bands"
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: uvicorn[standard]>=0.30; extra == "dev"
|
|
25
|
+
Requires-Dist: pyvips[binary]>=3.0; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
27
|
+
Requires-Dist: httpx>=0.27; extra == "dev"
|
|
28
|
+
Requires-Dist: ruff>=0.14; extra == "dev"
|
|
29
|
+
Requires-Dist: mypy>=1.11; extra == "dev"
|
|
30
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# fakecspace
|
|
34
|
+
|
|
35
|
+
A small simulated [CollectionSpace](https://collectionspace.org/) services API, for developing and testing UC
|
|
36
|
+
Berkeley's CollectionSpace apps: the Bulk Media Uploader
|
|
37
|
+
([cspace-bulk-media-uploader](https://github.com/ets-berkeley-edu/cspace-bulk-media-uploader)) and Serena, the media
|
|
38
|
+
server ([cspace-media-server](https://github.com/ets-berkeley-edu/cspace-media-server)). Both apps use this one copy
|
|
39
|
+
of the simulator.
|
|
40
|
+
|
|
41
|
+
> **It is not CollectionSpace, and it must never hold real data.** Its accounts are synthetic and each password is
|
|
42
|
+
> the user name (published here, in `src/fakecspace/accounts.py`). Its records are in memory and gone when it stops.
|
|
43
|
+
> Behaviour against the real server must be confirmed on a CollectionSpace test tenant. Each app's deployment keeps
|
|
44
|
+
> its own switch, so the simulator is never deployed with production.
|
|
45
|
+
|
|
46
|
+
## What it simulates
|
|
47
|
+
|
|
48
|
+
- **One CollectionSpace per museum** (bampfa, botgarden, cinefiles, pahma, ucjeps), each with its own records. The
|
|
49
|
+
museum comes from the host name a request uses (`pahma.fakecspace`) or a path prefix (`/pahma/cspace-services/...`);
|
|
50
|
+
PAHMA when neither names one. Tenant IDs are synthetic (PAHMA is 14).
|
|
51
|
+
- **Accounts**: `accounts/0/accountperms` and `accounts/0/accountroles`, with the BMU's users (`admin`, `limited`,
|
|
52
|
+
`intern`, `newstaff`, `reader`, `bmureader`) and Serena's (`serena`, `pahma-admin`, `viewer`; `admin` is a Serena
|
|
53
|
+
admin of every museum).
|
|
54
|
+
- **Records**: Media (GET, POST, search by `identificationNumber`, `title` or `blobCsid`), files attached with
|
|
55
|
+
`PUT media/<csid>/blob`, Objects, Relations, groups, Person and Organization terms, the languages vocabulary, and
|
|
56
|
+
the date parser.
|
|
57
|
+
- **Files**: `media/<csid>/blob/content`, `media/<csid>/blob/derivatives/<name>/content`, `blobs/<csid>` and
|
|
58
|
+
`blobs/<csid>/derivatives/<name>/content`. A file uploaded the BMU's way is served as the original and as every
|
|
59
|
+
derivative (Thumbnail, Small, Medium, FullHD, OriginalJpeg). A file over 5 MB isn't kept: the record then has no
|
|
60
|
+
file.
|
|
61
|
+
- **Development hooks** under `/_fake` (`src/fakecspace/hooks.py` lists them): reset, sample sets, records with
|
|
62
|
+
sample files, soft delete, replace, an outage, failures on demand, slowness, and terms changed meanwhile.
|
|
63
|
+
|
|
64
|
+
The simulator starts empty. A client asks for the samples it needs after each reset:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
curl -X POST http://localhost:8180/_fake/reset
|
|
68
|
+
curl -X POST http://localhost:8180/_fake/seed -H 'Content-Type: application/json' -d '{"set": "bmu"}'
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Failures on demand
|
|
72
|
+
|
|
73
|
+
`POST /_fake/fail` takes one JSON shape for both apps:
|
|
74
|
+
|
|
75
|
+
| Field | Meaning |
|
|
76
|
+
| --- | --- |
|
|
77
|
+
| `step` | One step of the BMU's work: `media`, `upload`, `objectSearch`, `objectCreate`, `relation`, `mediaSearch`, `group`, `termRead`. Without a step, the rule applies to every request whose path contains `path`. |
|
|
78
|
+
| `path` | Part of a request's path, e.g. `/blob/content`. |
|
|
79
|
+
| `match` | With a step: part of a name the step carries (identification number, file name, object number, group title, term). |
|
|
80
|
+
| `status` | The HTTP status answered (default 500). |
|
|
81
|
+
| `effect` | `none` or `many`, for `objectSearch` and `mediaSearch`: what the search finds, instead of a status. |
|
|
82
|
+
| `times` | How many requests fail (default 1; 0 until `DELETE /_fake/fail`). |
|
|
83
|
+
| `agent` | Only requests whose User-Agent starts with this, e.g. `bmu-worker` for the BMU's job runs. |
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
curl -X POST http://localhost:8180/_fake/fail -H 'Content-Type: application/json' \
|
|
87
|
+
-d '{"path": "/blob/content", "status": 503, "times": 2}'
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Using it from an app
|
|
91
|
+
|
|
92
|
+
Pin a version from PyPI, with its hash, in the app's development requirements (`pip install fakecspace` for a quick
|
|
93
|
+
try). The extras: `server` (uvicorn, to run it) and `bands` (pyvips, for records with a size band).
|
|
94
|
+
|
|
95
|
+
In tests, call it in-process, with no server:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from fastapi.testclient import TestClient
|
|
99
|
+
from fakecspace.app import app, stores
|
|
100
|
+
|
|
101
|
+
stores.reset() # every museum's store empty
|
|
102
|
+
client = TestClient(app, base_url="http://pahma.fakecspace")
|
|
103
|
+
stores["pahma"].add("m-1") # a Media record with sample files
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`fakecspace.app.store` is PAHMA's store. A Media record (`store.media[csid]`) can be read by attribute
|
|
107
|
+
(`media.blob`) or by CollectionSpace's field name (`media["blobCsid"]`).
|
|
108
|
+
|
|
109
|
+
To run it: `uvicorn fakecspace.app:app --port 8180`, or
|
|
110
|
+
`docker build -t fakecspace . && docker run --rm -p 8180:8180 fakecspace`.
|
|
111
|
+
|
|
112
|
+
## Development
|
|
113
|
+
|
|
114
|
+
Python 3.11 (`.python-version`).
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
python3.11 -m venv .venv && . .venv/bin/activate
|
|
118
|
+
pip install --require-hashes -r requirements-dev.txt
|
|
119
|
+
pip install --no-deps --no-build-isolation -e .
|
|
120
|
+
pytest -q && ruff check . && mypy
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Dependencies are listed in `pyproject.toml` and pinned with hashes in `requirements.txt` (the server, what the
|
|
124
|
+
Dockerfile installs), `requirements-dev.txt` and `requirements-tools.txt`, all made by `./pin-requirements.sh`.
|
|
125
|
+
Never edit those files by hand. `CLAUDE.md` has the rules for changes.
|
|
126
|
+
|
|
127
|
+
## Releasing
|
|
128
|
+
|
|
129
|
+
1. In a pull request, set the new version in `src/fakecspace/__init__.py` and add it to `CHANGELOG.md`.
|
|
130
|
+
2. Optional dry run: Actions › **Publish** › **Run workflow** on the branch publishes it to TestPyPI.
|
|
131
|
+
3. After the merge, tag the merge commit `vX.Y.Z` and push the tag. The **Publish** workflow builds it and, once a
|
|
132
|
+
reviewer approves the `pypi` environment, publishes it to PyPI through trusted publishing (no stored token).
|
|
133
|
+
4. Dependabot then proposes the new version in each app.
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
Copyright The Regents of the University of California: educational, research and not-for-profit use. See `LICENSE`.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# fakecspace
|
|
2
|
+
|
|
3
|
+
A small simulated [CollectionSpace](https://collectionspace.org/) services API, for developing and testing UC
|
|
4
|
+
Berkeley's CollectionSpace apps: the Bulk Media Uploader
|
|
5
|
+
([cspace-bulk-media-uploader](https://github.com/ets-berkeley-edu/cspace-bulk-media-uploader)) and Serena, the media
|
|
6
|
+
server ([cspace-media-server](https://github.com/ets-berkeley-edu/cspace-media-server)). Both apps use this one copy
|
|
7
|
+
of the simulator.
|
|
8
|
+
|
|
9
|
+
> **It is not CollectionSpace, and it must never hold real data.** Its accounts are synthetic and each password is
|
|
10
|
+
> the user name (published here, in `src/fakecspace/accounts.py`). Its records are in memory and gone when it stops.
|
|
11
|
+
> Behaviour against the real server must be confirmed on a CollectionSpace test tenant. Each app's deployment keeps
|
|
12
|
+
> its own switch, so the simulator is never deployed with production.
|
|
13
|
+
|
|
14
|
+
## What it simulates
|
|
15
|
+
|
|
16
|
+
- **One CollectionSpace per museum** (bampfa, botgarden, cinefiles, pahma, ucjeps), each with its own records. The
|
|
17
|
+
museum comes from the host name a request uses (`pahma.fakecspace`) or a path prefix (`/pahma/cspace-services/...`);
|
|
18
|
+
PAHMA when neither names one. Tenant IDs are synthetic (PAHMA is 14).
|
|
19
|
+
- **Accounts**: `accounts/0/accountperms` and `accounts/0/accountroles`, with the BMU's users (`admin`, `limited`,
|
|
20
|
+
`intern`, `newstaff`, `reader`, `bmureader`) and Serena's (`serena`, `pahma-admin`, `viewer`; `admin` is a Serena
|
|
21
|
+
admin of every museum).
|
|
22
|
+
- **Records**: Media (GET, POST, search by `identificationNumber`, `title` or `blobCsid`), files attached with
|
|
23
|
+
`PUT media/<csid>/blob`, Objects, Relations, groups, Person and Organization terms, the languages vocabulary, and
|
|
24
|
+
the date parser.
|
|
25
|
+
- **Files**: `media/<csid>/blob/content`, `media/<csid>/blob/derivatives/<name>/content`, `blobs/<csid>` and
|
|
26
|
+
`blobs/<csid>/derivatives/<name>/content`. A file uploaded the BMU's way is served as the original and as every
|
|
27
|
+
derivative (Thumbnail, Small, Medium, FullHD, OriginalJpeg). A file over 5 MB isn't kept: the record then has no
|
|
28
|
+
file.
|
|
29
|
+
- **Development hooks** under `/_fake` (`src/fakecspace/hooks.py` lists them): reset, sample sets, records with
|
|
30
|
+
sample files, soft delete, replace, an outage, failures on demand, slowness, and terms changed meanwhile.
|
|
31
|
+
|
|
32
|
+
The simulator starts empty. A client asks for the samples it needs after each reset:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
curl -X POST http://localhost:8180/_fake/reset
|
|
36
|
+
curl -X POST http://localhost:8180/_fake/seed -H 'Content-Type: application/json' -d '{"set": "bmu"}'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Failures on demand
|
|
40
|
+
|
|
41
|
+
`POST /_fake/fail` takes one JSON shape for both apps:
|
|
42
|
+
|
|
43
|
+
| Field | Meaning |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `step` | One step of the BMU's work: `media`, `upload`, `objectSearch`, `objectCreate`, `relation`, `mediaSearch`, `group`, `termRead`. Without a step, the rule applies to every request whose path contains `path`. |
|
|
46
|
+
| `path` | Part of a request's path, e.g. `/blob/content`. |
|
|
47
|
+
| `match` | With a step: part of a name the step carries (identification number, file name, object number, group title, term). |
|
|
48
|
+
| `status` | The HTTP status answered (default 500). |
|
|
49
|
+
| `effect` | `none` or `many`, for `objectSearch` and `mediaSearch`: what the search finds, instead of a status. |
|
|
50
|
+
| `times` | How many requests fail (default 1; 0 until `DELETE /_fake/fail`). |
|
|
51
|
+
| `agent` | Only requests whose User-Agent starts with this, e.g. `bmu-worker` for the BMU's job runs. |
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
curl -X POST http://localhost:8180/_fake/fail -H 'Content-Type: application/json' \
|
|
55
|
+
-d '{"path": "/blob/content", "status": 503, "times": 2}'
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Using it from an app
|
|
59
|
+
|
|
60
|
+
Pin a version from PyPI, with its hash, in the app's development requirements (`pip install fakecspace` for a quick
|
|
61
|
+
try). The extras: `server` (uvicorn, to run it) and `bands` (pyvips, for records with a size band).
|
|
62
|
+
|
|
63
|
+
In tests, call it in-process, with no server:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from fastapi.testclient import TestClient
|
|
67
|
+
from fakecspace.app import app, stores
|
|
68
|
+
|
|
69
|
+
stores.reset() # every museum's store empty
|
|
70
|
+
client = TestClient(app, base_url="http://pahma.fakecspace")
|
|
71
|
+
stores["pahma"].add("m-1") # a Media record with sample files
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`fakecspace.app.store` is PAHMA's store. A Media record (`store.media[csid]`) can be read by attribute
|
|
75
|
+
(`media.blob`) or by CollectionSpace's field name (`media["blobCsid"]`).
|
|
76
|
+
|
|
77
|
+
To run it: `uvicorn fakecspace.app:app --port 8180`, or
|
|
78
|
+
`docker build -t fakecspace . && docker run --rm -p 8180:8180 fakecspace`.
|
|
79
|
+
|
|
80
|
+
## Development
|
|
81
|
+
|
|
82
|
+
Python 3.11 (`.python-version`).
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
python3.11 -m venv .venv && . .venv/bin/activate
|
|
86
|
+
pip install --require-hashes -r requirements-dev.txt
|
|
87
|
+
pip install --no-deps --no-build-isolation -e .
|
|
88
|
+
pytest -q && ruff check . && mypy
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Dependencies are listed in `pyproject.toml` and pinned with hashes in `requirements.txt` (the server, what the
|
|
92
|
+
Dockerfile installs), `requirements-dev.txt` and `requirements-tools.txt`, all made by `./pin-requirements.sh`.
|
|
93
|
+
Never edit those files by hand. `CLAUDE.md` has the rules for changes.
|
|
94
|
+
|
|
95
|
+
## Releasing
|
|
96
|
+
|
|
97
|
+
1. In a pull request, set the new version in `src/fakecspace/__init__.py` and add it to `CHANGELOG.md`.
|
|
98
|
+
2. Optional dry run: Actions › **Publish** › **Run workflow** on the branch publishes it to TestPyPI.
|
|
99
|
+
3. After the merge, tag the merge commit `vX.Y.Z` and push the tag. The **Publish** workflow builds it and, once a
|
|
100
|
+
reviewer approves the `pypi` environment, publishes it to PyPI through trusted publishing (no stored token).
|
|
101
|
+
4. Dependabot then proposes the new version in each app.
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
Copyright The Regents of the University of California: educational, research and not-for-profit use. See `LICENSE`.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=80"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fakecspace"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "A small simulated CollectionSpace services API, for developing and testing UC Berkeley's CollectionSpace apps. Not CollectionSpace; never use it with real data."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "LicenseRef-UC-Regents" # educational, research and not-for-profit use; see LICENSE
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.11"
|
|
13
|
+
authors = [{ name = "UC Berkeley Research, Teaching, and Learning" }]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Framework :: FastAPI",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Topic :: Software Development :: Testing :: Mocking",
|
|
20
|
+
]
|
|
21
|
+
# What the code needs, with minimum versions. Installs use the hash-pinned requirements files instead
|
|
22
|
+
# (pin-requirements.sh).
|
|
23
|
+
dependencies = [
|
|
24
|
+
"fastapi>=0.120",
|
|
25
|
+
"python-multipart>=0.0.20",
|
|
26
|
+
"defusedxml>=0.7",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
# To run it as a server: uvicorn fakecspace.app:app --port 8180
|
|
31
|
+
server = ["uvicorn[standard]>=0.30"]
|
|
32
|
+
# Records with a size band (POST /_fake/media {"band": ...}) get JPEGs made with libvips.
|
|
33
|
+
bands = ["pyvips[binary]>=3.0"]
|
|
34
|
+
dev = [
|
|
35
|
+
"uvicorn[standard]>=0.30",
|
|
36
|
+
"pyvips[binary]>=3.0",
|
|
37
|
+
"pytest>=8",
|
|
38
|
+
"httpx>=0.27",
|
|
39
|
+
"ruff>=0.14",
|
|
40
|
+
"mypy>=1.11",
|
|
41
|
+
"build>=1.2",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Source = "https://github.com/ets-berkeley-edu/cspace-fakecspace"
|
|
46
|
+
|
|
47
|
+
[tool.setuptools.dynamic]
|
|
48
|
+
version = { attr = "fakecspace.__version__" }
|
|
49
|
+
|
|
50
|
+
[tool.setuptools.packages.find]
|
|
51
|
+
where = ["src"]
|
|
52
|
+
|
|
53
|
+
[tool.pytest.ini_options]
|
|
54
|
+
testpaths = ["tests"]
|
|
55
|
+
|
|
56
|
+
[tool.ruff]
|
|
57
|
+
line-length = 120
|
|
58
|
+
target-version = "py311"
|
|
59
|
+
|
|
60
|
+
[tool.ruff.lint]
|
|
61
|
+
select = ["E", "F", "W", "I", "B", "UP", "S"]
|
|
62
|
+
ignore = ["S101"] # assert in tests
|
|
63
|
+
|
|
64
|
+
[tool.ruff.lint.per-file-ignores]
|
|
65
|
+
"tests/*" = ["S105", "S106"] # the simulator's synthetic passwords
|
|
66
|
+
|
|
67
|
+
[tool.mypy]
|
|
68
|
+
python_version = "3.11"
|
|
69
|
+
files = ["src", "tests"]
|
|
70
|
+
strict = false
|
|
71
|
+
disallow_untyped_defs = true
|
|
72
|
+
warn_unused_ignores = true
|
|
73
|
+
ignore_missing_imports = true
|
|
74
|
+
|
|
75
|
+
[[tool.mypy.overrides]]
|
|
76
|
+
module = "tests.*"
|
|
77
|
+
disallow_untyped_defs = false
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""The simulator's accounts, their permissions and their roles. All synthetic: each password is its user name, which
|
|
2
|
+
is fine only because the simulator never holds real data.
|
|
3
|
+
|
|
4
|
+
The BMU's users (staff and interns, design doc "Roles") and Serena's (its read-only service account, and admins
|
|
5
|
+
for the admin app) are merged; `admin` is in both and has both apps' roles (F0b).
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from .store import TENANT_IDS, Store
|
|
10
|
+
|
|
11
|
+
# user -> password
|
|
12
|
+
USERS = {
|
|
13
|
+
"admin": "admin", # BMU staff with every permission; a Serena admin of every museum
|
|
14
|
+
"limited": "limited", # BMU staff who can't create Objects or groups
|
|
15
|
+
"reader": "reader", # can read everything but has neither BMU role, so the BMU refuses the sign-in
|
|
16
|
+
"intern": "intern", # a BMU intern: the BMU_Intern role and no permissions at all
|
|
17
|
+
"newstaff": "newstaff", # has the BMU_Staff role but can only read, so the BMU refuses the sign-in
|
|
18
|
+
"bmureader": "bmureader", # the BMU's own read-only account (BMU_Reader role); not a person
|
|
19
|
+
"serena": "serena", # Serena's read-only service account
|
|
20
|
+
"pahma-admin": "pahma-admin", # a Serena admin of PAHMA only
|
|
21
|
+
"viewer": "viewer", # can sign in to Serena's admin app but is no museum's admin
|
|
22
|
+
}
|
|
23
|
+
# Serena's admin app accounts, and the museums each is an admin of (the role Serena_Admin in that museum's tenant).
|
|
24
|
+
ADMINS = {user: USERS[user] for user in ("admin", "pahma-admin", "viewer")}
|
|
25
|
+
ADMIN_MUSEUMS: dict[str, set[str]] = {"admin": set(TENANT_IDS), "pahma-admin": {"pahma"}, "viewer": set()}
|
|
26
|
+
|
|
27
|
+
RESOURCES = ("media", "relations", "collectionobjects", "groups", "personauthorities", "orgauthorities",
|
|
28
|
+
"vocabularies", "structureddates")
|
|
29
|
+
_ACTIONS = {"admin": "CRUDL", "limited": "CRUDL", "reader": "RL", "intern": "", "newstaff": "RL",
|
|
30
|
+
"bmureader": "RL", "serena": "RL", "pahma-admin": "RL", "viewer": "RL"}
|
|
31
|
+
|
|
32
|
+
# Role names without the ROLE_<tenant id>_ prefix.
|
|
33
|
+
_ROLES = {
|
|
34
|
+
"admin": ["TENANT_ADMINISTRATOR", "TENANT_READER", "BMU_STAFF"],
|
|
35
|
+
"limited": ["TENANT_READER", "BMU_STAFF"],
|
|
36
|
+
"reader": ["TENANT_READER"],
|
|
37
|
+
"intern": ["BMU_INTERN"],
|
|
38
|
+
"newstaff": ["TENANT_READER", "BMU_STAFF"],
|
|
39
|
+
"bmureader": ["BMU_READER"],
|
|
40
|
+
"serena": ["TENANT_READER"],
|
|
41
|
+
"pahma-admin": ["TENANT_READER"],
|
|
42
|
+
"viewer": ["TENANT_READER"],
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# What each person is for, shown by the BMU's Demo tools ("Sign in as"); not the service accounts.
|
|
46
|
+
USER_NOTES = {
|
|
47
|
+
"admin": "Staff with every permission",
|
|
48
|
+
"limited": "Staff who can't create Objects or groups",
|
|
49
|
+
"intern": "Intern: no CollectionSpace permissions",
|
|
50
|
+
"newstaff": "Staff role without the permissions: sign-in refused",
|
|
51
|
+
"reader": "Neither BMU role: sign-in refused",
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def perms_for(store: Store, user: str) -> dict[str, str]:
|
|
56
|
+
"""The user's actions on each resource, as accountperms answers (C, R, U, D, L)."""
|
|
57
|
+
perms = {resource: _ACTIONS[user] for resource in RESOURCES}
|
|
58
|
+
if user == "limited":
|
|
59
|
+
perms["collectionobjects"] = "RL"
|
|
60
|
+
perms["groups"] = "RL"
|
|
61
|
+
perms.update(store.perm_overrides.get(user, {}))
|
|
62
|
+
return perms
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def roles_for(store: Store, user: str) -> list[str]:
|
|
66
|
+
"""The user's role names in the store's museum's tenant, e.g. ROLE_14_BMU_STAFF."""
|
|
67
|
+
if user in store.role_overrides:
|
|
68
|
+
return list(store.role_overrides[user])
|
|
69
|
+
tenant = TENANT_IDS[store.museum]
|
|
70
|
+
names = list(_ROLES[user])
|
|
71
|
+
if store.museum in ADMIN_MUSEUMS.get(user, set()):
|
|
72
|
+
names.append("SERENA_ADMIN")
|
|
73
|
+
return [f"ROLE_{tenant}_{name}" for name in names]
|