tmv-api 0.1.0
Total Member View, Application Programming Interface [TMV-API]
License: MIT
Requires Python: >=3.11.0,<3.12.0
Keywords: tmv,api

# Total Member View(TMV) - Application Programming Interface(API)

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

## Contents

- [Links](#links)
- [Installation](#installation)
- [Development](#development)
- [Troubleshooting](#troubleshooting)

## Links

- [Project confluence](https://confluence.elevancehealth.com/display/CCHub/Total+Member+Views)
- [Project jira](https://jira.elevancehealth.com/projects/TOTALV/summary)
- [Front-end repo](https://bitbucket.elevancehealth.com/projects/HOS/repos/hos-design-system/browse/apps/tmv-app)
- [Infra + CI/CD repo](https://bitbucket.elevancehealth.com/projects/HOS/repos/hos-gitops/browse/infrastructure/np-01/hos-dev/modules/tmv)
- [Dev deployment API URL](https://tmv-api-hos-dev.nginx.slvr-corp-sharedservedaiaas.awsdns.internal.das/api/)
- [Dev deployment](https://dev.tmv.healthos.carelon.com/)
- [SIT deployment](https://sit.tmv.healthos.carelon.com/)
- [UAT deployment](https://uat.tmv.healthos.carelon.com/)
- [Figma design 1](https://www.figma.com/proto/tgJSPlCjTIcat8T9kMbbp8/Health-OS-Platform?page-id=0%3A1&type=design&node-id=2-35598&viewport=3334%2C-)
- [Figma design 2](27%2C0.22&t=Py2JCjkbmABI123m-1&scaling=min-zoom&starting-point-node-id=2%3A47217)

## Installation

- The development environment can be installed with the `project-dev-setup.sh` script.
- Please download the `project-dev-setup.sh` script from this repo and run it from your shell: `source project-dev-setup.sh`.
- `bash` and `zsh` are supported.
- `macOS` and `debian linux` are supported.

The script:

- detects the OS.
- installs baseline OS specific prerequisites (brew for MacOS) if necessary.
- installs git.
- installs pyenv.
- installs pyenv-virtualenv.
- installs pre-commit.
- adds some necessary lines to the shell profile.
- reloads the shell profile.
- clones this repo into a local directory.
- installs the project version of python via pyenv.
- creates the project virtual-env using the project version of python via pyenv.
- installs project dependencies and installs the project in pip's editable mode.

## Development

### Enter virtualenv

```bash
pyenv activate tmv-api
```

### (Re)install dependencies in development mode (needed when deps change)

```bash
pip install --use-pep517 --editable .[dev]
```

### Run dev server

```bash
python manage.py runserver
```

### Testing

Run the following command to execute all tests:

```bash
python manage.py test
```

to test with breakpoints enabled use:

```bash
python manage.py test -- -s
```

If `whitenoise` throws errors regarding `favicon.ico`, run the following

```bash
python manage.py collectstatic
```

#### VCR tests

If no path is specified for a VCR test, the VCR cassette file will be stored under the same directory as the test file, in a file with the same name as the test itself.

A path can also be specified to store cassette files, for example:

```python
@vcr.use_cassette('fixtures/vcr_cassettes/test_abc.yaml')
```

Please refer to [VCR documentation](https://vcrpy.readthedocs.io/en/latest/usage.html) for more information.

##### Removing JWT tokens from VCR files

VCR Recordings can contain JWT tokens from the interactions with backend servers. This can cause BitBucket warnings. Such JWT tokens can/should be removed from the recordings to avoid any code scan issues. It is advised that tests be rerun to make sure that changes in the fixtures did not cause any test failures.

Also take a look at the custom `vcr_test` in `tmv_api.project.pytest_settings` which strips out sensative data from the cassettes.

### Uninstall package in development mode

```bash
pip uninstall --yes tmv-api
```

### Cleanup python compile artifacts

```bash
pyclean . --debris all
```

### Exit virtualenv

```bash
deactivate
```

## Development - local docker image debugging

### Build

```bash
docker build . --tag "tmv-api"
```

### Run

```bash
docker run --interactive --tty --publish="8000:8000" tmv-api
```

### Use

Navigate to http://localhost:8000/admin

### Full-Clean

**Note**: This will take down all images and containers on your local system.

```bash
docker system prune --all --force
```

## Troubleshooting

### If you are running in Windows:

- to run the dev server from windows do not use the command `python manage.py runserver`; instead, use the command `waitress-serve --listen=127.0.0.1:8000 tmv_api.project.wsgi.development:application`.

### If you get an SSL error while running pip install

try to run this

```bash
python -m pip config --no-input --user set "global.trusted-host" "pypi.python.org pypi.org files.pythonhosted.org"
```

and then retry the `pip install` command you tried.

### ...