Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/CDA-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI

on:
push:
branches: [ main, githubAction-testing ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
integration-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: set up backend
run: docker compose up --build -d

- name: Set Up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

# Unlike the code-check workflow, this job requires the dev dependencies to be
# installed to make sure we have the necessary, tools, stub files, etc.
- name: Install Poetry
uses: abatilo/actions-poetry@v4

- name: Add Poetry to PATH (for act)
if: env.ACT
run: echo "/root/.local/bin" >> $GITHUB_PATH

- name: Cache Virtual Environment
uses: actions/cache@v4
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}

- name: Install Dependencies
run: poetry install

# Run pytest and generate coverage report data.
- name: Run Tests
run: poetry run pytest tests/cda/ --doctest-modules --cov --cov-report=xml:out/coverage.xml

# Run mypy with strict mode enabled. Only the main source code is type checked (test
# and example code is excluded).
- name: Check Types
run: poetry run mypy --strict cwms/

- name: Generate Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: out/coverage.xml
format: markdown
output: both
badge: true

- name: Generate Job Summary
uses: x-color/github-actions-job-summary@v0.1.1
with:
file: ./code-coverage-results.md
vars: |-
empty: empty
2 changes: 1 addition & 1 deletion .github/workflows/pypi-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
# The tests should have already been run in the testing workflow, but we run them
# again here to make sure that we do not deploy a broken distribution.
- name: Run Tests
run: poetry run pytest tests/
run: poetry run pytest tests/mock/

# Once the tests have passsed we can build the distribution and store it, so it can
# be accessed in the jobs below.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
# The tests should have already been run in the testing workflow, but we run them
# again here to make sure that we do not deploy a broken distribution.
- name: Run Tests
run: poetry run pytest tests/
run: poetry run pytest tests/mock/

# Once the tests have passsed we can build the distribution and store it, so it can
# be accessed in the jobs below.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

# Run pytest and generate coverage report data.
- name: Run Tests
run: poetry run pytest tests/ --doctest-modules --cov --cov-report=xml:out/coverage.xml
run: poetry run pytest tests/mock/ --doctest-modules --cov --cov-report=xml:out/coverage.xml

# Run mypy with strict mode enabled. Only the main source code is type checked (test
# and example code is excluded).
Expand Down
45 changes: 45 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,51 @@ Run poetry against a single file with:
poetry run pytest tests/turbines/turbines_test.py
```

### Local CDA Testing and Development

To test and develop with a local CDA instance, follow these steps:

1. **Install Docker**
Download and install Docker from the [official website](https://www.docker.com/get-started/).

2. **Start and Verify CDA Services**
From the project root, run:
```sh
docker compose up -d
```
This will start the required services: Oracle database instance, CWMS API, Keycloak Auth, and Traefik proxy.
Additionally, there is a one-time service that runs and then shuts down; this service connects to the database instance to set initial conditions and users.
If you want to update the initial data in the database, you can do so by editing the `compose_files/sql/users.sql` file.

Ensure all these services are running by checking their status:
```sh
docker compose ps
```
All containers should have a `State` of `Up` before proceeding.

#### Service Ports and Access

By default, the local CDA instance will be accessible at [http://localhost:8082](http://localhost:8082), and the Oracle database will be available on port `1526`. When developing or running tests, ensure your application or test configuration points to these ports.

> **Note:** If you are running other instances of CDA or Oracle on your machine, they may use different ports. Always verify which ports are in use and update your configuration files accordingly to avoid conflicts.

3. **Run Tests Against CDA**
Once the services are running, execute the tests:
```sh
poetry run pytest tests/
```
This will run all tests, including those that require a CDA connection.

#### Running CDA Tests Against Other Instances

Developers can also run the tests in the `tests/cda/` package against other CDA instances by providing the `--api_key` and `--api_root` command line arguments. For example:

```sh
poetry run pytest tests/cda/ --api_root=http://localhost:8082/cwms-data/
```

> **Warning:** The tests in the `tests/cda/` package are destructive and may cause irreversible deletion of data from the targeted CDA instance. Use caution and avoid running these tests against production or important environments.

### Code Style

In order for a pull request to be accepted, python code must be formatted using [black][black] and [isort][isort]. YAML files should also be formatted using either Prettier or the provided pre-commit hook. Developer are encouraged to integrate these tools into their workflow. Pre-commit hooks can be installed to automatically validate any code changes, and reformat if necessary.
Expand Down
Loading