# ows-product-digital

## Getting Started

### Set up environment

To connect to the db, copy the DB credentials into a file named .env

```bash
$ cp .env.shadow .env
```

### Installation

The installation is very straightforward, but make sure you are using the closest version
from whats specified at the `.python-version` file.

#### MacOS

The most reliable method to avoid issues with MacOS built-in python3 version
is to use `pyenv` (https://github.com/pyenv/pyenv), installed via `brew` (https://formulae.brew.sh/formula/pyenv).

Once you have pyenv installed, you just need to
`pyenv install 3.x.y` and then `pyenv global 3.x.y` before start working in the repo.
Once you are in the (env), make sure these two commands output the same expected version

```
python --version
env/bin/python --version
```

If they do, you are ready to go!

<br/>

#### Windows

Just ask for a remote VM that has it installed for you.

```bash
make pip_dev
```

````

### Running

When all dependencies have been installed, you can run the flask application
on your local instance by running:

```bash
(env) $ python dev.py
````

You can optionally set a PORT environment variable to run on a port other than
5000:

```bash
(env) $ PORT=5001 python dev.py
```

By using the development server, you will have access to specific features that
are not necessarily available in production, such as the exception tracer.


### Docker

#### Unit tests and linting

Run unit tests and linting inside Docker (mirrors CI):

```bash
make docker_unit_lint
```

To clean up the container afterwards:

```bash
make down_unit_lint
```

#### Integration tests

Run integration tests against QA in Docker. 
Make sure you first run `awsume prod`


```bash
make docker_test_integration
```

To clean up:

```bash
make down_test_integration
```

#### Dev server

Spin up the Flask dev server in Docker:

```bash
make up_dev
```

Tear it down:

```bash
make down_dev
```

### Testing

To run the tests, all you have to do is to run:

```bash
(env) $ py.test tests/ --cov product_digital --cov-report term-missing
(env) $ ruff check product_digital/ tests/
```

### Updating

To install new dependencies.

```bash
make pip_dev
```

### Connection with other services

If you need to develop a feature that requires another service to be hit using this one as a intermediary proxy (ex: `ows-track/validate`)

You would need to define a "service map" in your `.env` file that will override the default qa-host for that service to point at your custom running instance at host:port (usually localhost:xxxx)

OWSREQUEST_SERVICE_MAP={
"ows-track": "localhost:5501"
}
