To speed up the local development workflow for amanuensis, alongside the gen3 stack, follow these steps.
- Build the image using Dockerfile.dev:
docker build -f Dockerfile.dev -t amanuensis:test .
update again with tests 2) In the docker-compose.yml file inside the compose-services repo:
1) Make sure amanuensis-service is using the amanuensis:test image.
2) Under amanuensis-service volumes property, map your local source-code repo to the amanuensis/amanuensis directory. The order is source:target.
```
- /location-of-your-repos/amanuensis/amanuensis:/amanuensis/amanuensis
```
-
Inside compose-services run
docker compose upto start all services of the gen3 stack. -
Open a shell to the amanuensis:test container. Navigate to /amanuensis/amanuensis and run
bash watch-files.sh. This will watch for files changes in this directory and re-run the uwsgi command every time there is a file change, which will ensure that changes are reflected in the container almost immediatelly.
Once you run bash watch-files.sh most of the output will show in that same terminal window. Information about HTTP requests--method, URL, etc.--will continue to show up in the Docker logs.
The Docker.dev file installs inotify-tools to allow the watch-files.sh script to check for file changes. In addtition, it will install vim.
To use bash instead of the default, sh, run exec /bin/bash in the container or if starting from the host terminal run:
docker exec -it amanuensis-service /bin/bash
python -m venv env
source env/bin/activate
poetry install
alembic revision -m "add_save"
-
in the config fill in ARBORIST with 'http://arborist-service'
-
activate the virtual env
-
pytest tests_endpoints/endpoints
-
pytest tests_endpoints/resources
-
mocking:
-
all initiated variables, functions, objects and attributes can be mocked
-
using the patch function from the mock library
patch("path where object is called", return_value="fake return value")
patch("path where object is called", side_effect="A method to replace the orignal")
patch.object("path where object is called", "attribute to change", (either return_value or side_effect)="mocked value")
make sure to use the path where the object is called not definied
example: patch('amanuensis.resources.consortium_data_contributor.get_consortium_list', ["INRG"])
-
-
Fence in tests_endpoints/endpoints.conftest there are two pytest fixtures that simulate calls to fence
when creating a new test pass fence_get_users_mock as a parameter to the test function and then use side_effect=fence_get_users_mock to patch fence_get_users
this will use the fixture fence_users to represent the fence DB
if a test requires adding a user to fence_users mid way through a test pass fence_users as a parameter in the test function and then new users can be appended at any point
-
Arborist
for every request add the header "Authorization": 'bearer {fence_id}'
this will use the fence_get_users_mock to retrieve the fence user with the given fence_id
if check_arborist_auth was a decorator on the requests method it allow the request thorugh if the fence_users role is admin
The test_build_project file tests a group of users making a data request from start to finish here is what is occuring in this test, feel free to add onto this as changes are made in amanuensis
USERS: in FENCE DB: user1 user2 user3 admin
in AMANUENSIS DB:
user2
admin
in NEITHER:
user4
user5
-
user1 creates a filter set
-
sends post req to /filter-sets?explorerId=1 to create a filter set
-
sends get req to /filter-sets?explorerId=1 to get all of their filter sets
-
sends post req to /filter-sets/snapshot to create a snap shot of the filter set they created
- user1 shares the filter set with user2 and user2 has user1 make a change
-
user1 shares the snapshot code with user2
-
user2 sends get req to /filter-sets/snapshot/{snapshot_response.json} to get the filterset from the snapshot
-
user1 sends put req to /filter-sets/{id}?explorerId=1'to make the change to the filter set
-
-
the users are ready to make a data request and contact an admin to do so
-
admin send get req to /admin/filter-sets/user" to retrieve the filter set from user1
-
admin sends a post req to '/admin/projects' to create a project
- user1, admin, user4, and user5 are added as associated users in this request all have metadata access
- data was requested from INRG and INSTRUCT
-
admin sends get req to "/admin/all_associated_user_roles" to retreve all roles
-
admin sends post req to "/admin/associated_user" to add user2 to project with data access
-
admin sends post req to "/admin/associated_user" to add user3 to project with metadata access
-
admin sends requests to readd user1 and user5 and nothing happens as they are already added
-
admin sends put req to "/admin/associated_user_role" to give user1 data access
-
admin sends put req to "/admin/associated_user_role" to get user3 data access
- users decide they want to remove user3 from the project
-
admin sends delete req to "/admin/remove_associated_user_from_project" to remove user3 from project *user3 active set to false and role set to metadata access in ProjectAssociatedUser table
-
admin sends get req to "/admin/states" to get all the possible states
- INRG data request was approved
- admin sends post req to "/admin/projects/state" to change request state for INRG to approved
*INSTRUCT requires revision to filter set
-
admin sends post req to "/admin/projects/state" to change request state for INSTRUCT to revision
-
admin sends a post req to "/admin/filter-sets" to create a new filter set with corrections
-
admin sends post req to "admin/copy-search-to-user" to add user1 to the new filter set
-
admin sends post req to "admin/copy-search-to-project" to add the new filter set to the project
-
admin sends post req to "/admin/projects/state" to change INSTRUCT to approved
-
admin sends put req to "/admin/projects" to add an approved url
-
admin sends post req to "/admin/projects/state" to move all requests to data available
-
user2 sends get req to "/download-urls/{project_id}" to get the data
-
user3 sends get req to "/download-urls/{project_id}" to get the data but a 403 is returned becuase they were removed from the project
-
admin sends get req to "/download-urls/{project_id}" to get the data but a 403 is returned becuase they dont have data access
-
user5 signs up in fence and sends get req to /projects and their userid should be updated in the associated_users table
-
user3 sends get reqeust to /projects and should see nothing becuase they are not an active user of the project
-
user1 sends get req to /projects and should see the the project
-
user1 sends get req to "filter-sets/{id}?explorerId=1" to retrieve the original filter set of the project
-
user1 send delete req to "filter-sets/{id}?explorerId=1" to delete the oringial filter set
-
-
admin creates a project for user4
-
admin sends post req to /admin/projects to create a data request
user4 should not be added to associated_user table again
-