Skip to content

Commit

Permalink
fix: ruff fix
Browse files Browse the repository at this point in the history
  • Loading branch information
khalsz committed Feb 18, 2025
1 parent ec761d7 commit dbecc0d
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 172 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ jobs:
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: set realm directory permission
run: sudo chown -R 1000:1000 dev/docker/realm

- name: Fix realm_config directory permission
run: sudo chown -R 1000:1000 dev/docker/realm_config

- name: Build and run containers
run: |
Expand All @@ -43,11 +44,6 @@ jobs:
pip install --upgrade pip
pip install uv
uv sync
- name: check running containers
run: docker ps -a

- name: test keycloak connection
run: curl -v http://localhost:8080
- name: Run tests
run: |
uv run pytest -rs
Expand Down
3 changes: 1 addition & 2 deletions dev/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ services:
ports:
- "8080:8080"
volumes:
- ./realm:/opt/keycloak/data
- ./realm_config:/opt/keycloak/data
command: start-dev
healthcheck:
test: ["CMD-SHELL", "exec 3<>/dev/tcp/keycloak/8080 && echo -e 'GET /health/ready HTTP/1.1\\r\\nHost: keycloak\\r\\nConnection: close\\r\\n\\r\\n' >&3 && cat <&3 | grep -q '200 OK'"]
Expand All @@ -107,4 +107,3 @@ volumes:
certs:
vhost:
html:
keycloak-config:
6 changes: 0 additions & 6 deletions dev/docker/realm/h2/keycloakdb.lock.db

This file was deleted.

Binary file removed dev/docker/realm/h2/keycloakdb.mv.db
Binary file not shown.
108 changes: 0 additions & 108 deletions dev/docker/realm/h2/keycloakdb.trace.db

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions src/api/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ def create_cpf_summary(self, data_path: Path):
df["context"] = [Json(base_context)] * len(df)
df = df.drop_duplicates(subset=["name"])
df["name"] = df["name"].apply(
lambda x: models.ShotModel.__fields__.get("cpf_" + x.lower()).alias
if models.ShotModel.__fields__.get("cpf_" + x.lower())
else x
)
lambda x: models.ShotModel.__fields__.get("cpf_" + x.lower()).alias
if models.ShotModel.__fields__.get("cpf_" + x.lower())
else x
)
df.to_sql("cpf_summary", self.uri, if_exists="append")

def create_scenarios(self, data_path: Path):
Expand All @@ -147,7 +147,7 @@ def create_scenarios(self, data_path: Path):
data = pd.DataFrame(dict(id=ids, name=scenarios)).set_index("id")
data = data.dropna()
data["context"] = [Json(base_context)] * len(data)

data.to_sql("scenarios", self.uri, if_exists="append")

def create_shots(self, data_path: Path):
Expand Down
5 changes: 3 additions & 2 deletions tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

import pytest
from fastapi.testclient import TestClient
from requests.auth import HTTPBasicAuth
from sqlalchemy.orm import sessionmaker
from sqlalchemy_utils.functions import (
drop_database,
)
from sqlmodel import Session, create_engine
from strawberry.extensions import SchemaExtension
from requests.auth import HTTPBasicAuth

from src.api.create import DBCreationClient
from src.api.database import get_db
from src.api.main import app, graphql_app
from src.api.environment import TEST_PASSWORD, TEST_USERNAME
from src.api.main import app, graphql_app

# Set up the database URL
host = os.environ.get("DATABASE_HOST", "localhost")
Expand All @@ -40,6 +40,7 @@ def test_db(data_path):

drop_database(SQLALCHEMY_DATABASE_TEST_URL)


@pytest.fixture()
def test_auth():
return HTTPBasicAuth(username=TEST_USERNAME, password=TEST_PASSWORD)
Expand Down
92 changes: 50 additions & 42 deletions tests/api/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,26 @@ def test_exception_handler(client, override_get_db):
def test_post_shots(client, test_auth):
endpoint = "http://localhost:8081/json/shots"

payload = [{
"shot_id": 90121,
"uuid": "883382e6-df26-55f2-af85-ad7bdec24835",
"url": "s3://mast/level1/shots/30122.zarr",
"timestamp": "2013-09-09T14:24:00",
"preshot_description": "extend CHFS to 500 ms - increase zref to +0.75 - ramp current from set value of 0.5 at 220ms to a set value of 0.75 at 310ms",
"postshot_description": "1 breakdown on SS at 100 ms - good deep H-mode - disrupts during the current ramp - but still in H-mode",
"campaign": "M9",
"reference_shot": 29495,
"scenario": 3,
"heating": "2 Beams,SS Beam,SW Beam",
"pellets": "false",
"rmp_coil": "false",
"current_range": "700 kA",
"divertor_config": "Conventional",
"plasma_shape": "Connected Double Null",
"facility": "MAST"
}]
payload = [
{
"shot_id": 90121,
"uuid": "883382e6-df26-55f2-af85-ad7bdec24835",
"url": "s3://mast/level1/shots/30122.zarr",
"timestamp": "2013-09-09T14:24:00",
"preshot_description": "extend CHFS to 500 ms - increase zref to +0.75 - ramp current from set value of 0.5 at 220ms to a set value of 0.75 at 310ms",
"postshot_description": "1 breakdown on SS at 100 ms - good deep H-mode - disrupts during the current ramp - but still in H-mode",
"campaign": "M9",
"reference_shot": 29495,
"scenario": 3,
"heating": "2 Beams,SS Beam,SW Beam",
"pellets": "false",
"rmp_coil": "false",
"current_range": "700 kA",
"divertor_config": "Conventional",
"plasma_shape": "Connected Double Null",
"facility": "MAST",
}
]

response = client.post(
endpoint,
Expand All @@ -193,19 +195,20 @@ def test_post_signals(client, test_auth):
endpoint = "/json/signals"

payload = [
{"uuid": "005fe9da-964a-5563-af2c-dffe3d99ed89",
"shot_id": 90121,
"name": "alp/inner_lo_powpeakval",
"version": 0,
"rank": 1,
"url": "s3://mast/level1/shots/30398.zarr/alp/inner_lo_powpeakval",
"source": "alp",
"quality": "Not Checked",
"shape": [288],
"description": "",
"signal_type": "Analysed",
"dimensions": ["time"]
}
{
"uuid": "005fe9da-964a-5563-af2c-dffe3d99ed89",
"shot_id": 90121,
"name": "alp/inner_lo_powpeakval",
"version": 0,
"rank": 1,
"url": "s3://mast/level1/shots/30398.zarr/alp/inner_lo_powpeakval",
"source": "alp",
"quality": "Not Checked",
"shape": [288],
"description": "",
"signal_type": "Analysed",
"dimensions": ["time"],
}
]

response = client.post(
Expand All @@ -219,12 +222,16 @@ def test_post_signals(client, test_auth):
def test_post_sources(client, test_auth):
endpoint = "/json/sources"

payload = [{"uuid": "a2ecc848-21bf-5137-bd8c-bfcf06020cc9",
"shot_id": 90121,
"name": "abm",
"url": "s3://mast/level1/shots/30119.zarr/abm",
"description": "multi-chord bolometers",
"quality": "Not Checked"}]
payload = [
{
"uuid": "a2ecc848-21bf-5137-bd8c-bfcf06020cc9",
"shot_id": 90121,
"name": "abm",
"url": "s3://mast/level1/shots/30119.zarr/abm",
"description": "multi-chord bolometers",
"quality": "Not Checked",
}
]

response = client.post(
endpoint,
Expand All @@ -251,11 +258,12 @@ def test_post_cpf_summary(client, test_auth):
endpoint = "/json/cpf_summary"

payload = [
{"index": 300,
"name": "dwmhd_ipmax",
"description": "Rate of Change of Total Stored Energy at time of Peak Plasma Current"
}
]
{
"index": 300,
"name": "dwmhd_ipmax",
"description": "Rate of Change of Total Stored Energy at time of Peak Plasma Current",
}
]

response = client.post(
endpoint,
Expand Down

0 comments on commit dbecc0d

Please sign in to comment.