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
2 changes: 1 addition & 1 deletion .github/workflows/test_backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3


- name: Start test docker services
run: |
make start-test-infra
Expand All @@ -42,7 +43,6 @@ jobs:
until nc -z river-localstack 4566; do sleep 1; done

- name: Run tests
uses: prefix-dev/setup-pixi@v0.8.1
env:
GH_USERNAME: ${{ secrets.GH_USERNAME }}
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
Expand Down
47 changes: 24 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ PYPY_VERSION := 3.11-v7.3.20-linux64
backend/pypy${PYPY_VERSION}/bin/pypy3:
wget https://downloads.python.org/pypy/pypy${PYPY_VERSION}.tar.bz2 -O backend/pypy${PYPY_VERSION}.tar.bz2
tar xf backend/pypy${PYPY_VERSION}.tar.bz2 -C backend

install-backend-deps: backend/pypy${PYPY_VERSION}/bin/pypy3
cd backend && ./pypy${PYPY_VERSION}/bin/pypy3 -mpip install -r requirements.txt
cd backend && ./pypy${PYPY_VERSION}/bin/pypy3 -m ensurepip && ./pypy${PYPY_VERSION}/bin/pypy3 -mpip install -r requirements.txt

dev-frontend: ~/.pixi/bin/pixi
cd frontend && pixi run npm install -f
Expand Down Expand Up @@ -55,9 +53,9 @@ migrate-dev-db: backend/pypy${PYPY_VERSION}/bin/pypy3
start-test-db:
docker compose up test-db -d

migrate-test-db: ~/.pixi/bin/pixi
cd backend && backend/pypy${PYPY_VERSION}/bin/pypy3 -m aerich init-db || echo "DB already existed"
cd backend && backend/pypy${PYPY_VERSION}/bin/pypy3 -m aerich upgrade
migrate-test-db: backend/pypy${PYPY_VERSION}/bin/pypy3
cd backend && ./pypy${PYPY_VERSION}/bin/pypy3 -m aerich init-db || echo "DB already existed"
cd backend && ./pypy${PYPY_VERSION}/bin/pypy3 -m aerich upgrade

format-backend:
black . --line-length 120
Expand Down Expand Up @@ -90,30 +88,33 @@ start-traefik: ~/.pixi/bin/pixi
.PHONY: start-test-infra test-auth test-health test-organization test-all
start-test-infra: start-test-db start-redis start-localstack start-slurm
@echo "Start test infra setup"

test-auth:
cd backend && pixi run pytest --cov=app/service_auth app/service_auth --cov-report=term-missing -vvvvvv

test-health:
cd backend && pixi run pytest --cov=app/service_health app/service_health --cov-report=term-missing -vvvvvv
install-test-deps: backend/pypy${PYPY_VERSION}/bin/pypy3
cd backend && ./pypy${PYPY_VERSION}/bin/pypy3 -mpip install pytest pytest-cov pytest-asyncio

test-auth: install-test-deps
cd backend && ./pypy${PYPY_VERSION}/bin/pypy3 -m pytest --cov=app/service_auth app/service_auth --cov-report=term-missing -vvvvvv

test-health: install-test-deps
cd backend && ./pypy${PYPY_VERSION}/bin/pypy3 -m pytest --cov=app/service_health app/service_health --cov-report=term-missing -vvvvvv

test-organization:
cd backend && pixi run pytest --cov=app/service_organization app/service_organization --cov-report=term-missing -vvvvvv
test-organization: install-test-deps
cd backend && ./pypy${PYPY_VERSION}/bin/pypy3 -m pytest --cov=app/service_organization app/service_organization --cov-report=term-missing -vvvvvv

test-credential:
cd backend && pixi run pytest --cov=app/service_credential app/service_credential --cov-report=term-missing -vvvvvv -k "github"
test-credential: install-test-deps
cd backend && ./pypy${PYPY_VERSION}/bin/pypy3 -m pytest --cov=app/service_credential app/service_credential --cov-report=term-missing -vvvvvv -k "github"

test-analysis:
cd backend && pixi run pytest --cov=app/service_analysis app/service_analysis --cov-report=term-missing -vvvvvv
test-analysis: install-test-deps
cd backend && ./pypy${PYPY_VERSION}/bin/pypy3 -m pytest --cov=app/service_analysis app/service_analysis --cov-report=term-missing -vvvvvv

test-project:
cd backend && pixi run pytest --cov=app/service_project app/service_project --cov-report=term-missing -vvvvvv
test-project: install-test-deps
cd backend && ./pypy${PYPY_VERSION}/bin/pypy3 -m pytest --cov=app/service_project app/service_project --cov-report=term-missing -vvvvvv

test-storage:
cd backend && pixi run pytest --cov=app/service_storage app/service_storage --cov-report=term-missing -vvvvvv
test-storage: install-test-deps
cd backend && ./pypy${PYPY_VERSION}/bin/pypy3 -m pytest --cov=app/service_storage app/service_storage --cov-report=term-missing -vvvvvv

test-job:
cd backend && pixi run pytest --cov=app/service_job app/service_job --cov-report=term-missing -vvvvvv
test-job: install-test-deps
cd backend && ./pypy${PYPY_VERSION}/bin/pypy3 -m pytest --cov=app/service_job app/service_job --cov-report=term-missing -vvvvvv

test-all: test-health test-auth test-organization test-credential test-analysis test-project
echo "Running all tests..."
Expand Down
4 changes: 2 additions & 2 deletions backend/app/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ async def user_aws(test_client, cookies_admin, user_aws_arn):
}
aws = await create_instance(
test_client,
f"/api/users/creds/{cred["id"]}/",
f"/api/users/creds/{cred['id']}/",
aws_data,
cookies_admin,
201,
Expand Down Expand Up @@ -311,7 +311,7 @@ async def org_aws(test_client, organization, cookies_org_manager):
}
aws = await create_instance(
test_client,
f"/api/orgs/{organization}/creds/{cred["id"]}/",
f"/api/orgs/{organization}/creds/{cred['id']}/",
aws_data,
cookies_org_manager,
201,
Expand Down
2 changes: 1 addition & 1 deletion backend/app/service_analysis/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async def get_analysis(

return ok(
{
"items": result,
"item": result,
"page": page,
"page_size": page_size,
"total": total_count,
Expand Down
20 changes: 10 additions & 10 deletions backend/app/service_analysis/tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ async def test_basic_analysis(

# list instance as admin
res_admin = await list_instance(test_client, f"{BASE_URL}/", cookies_admin, 200)
assert len(res_admin["items"]) == 1
assert_instance_fields(res_admin["items"][0], EXPECTED_FIELDS)
assert len(res_admin["item"]) == 1
assert_instance_fields(res_admin["item"][0], EXPECTED_FIELDS)

# list instance as contributor
res_contrib = await list_instance(test_client, f"{BASE_URL}/", cookies_contributor, 200)
assert len(res_contrib["items"]) == 1
assert_instance_fields(res_contrib["items"][0], EXPECTED_FIELDS)
assert len(res_contrib["item"]) == 1
assert_instance_fields(res_contrib["item"][0], EXPECTED_FIELDS)

# delete as admin (should fail)
delete_url = f'{BASE_URL}/{res_admin["items"][0]["id"]}/'
delete_url = f"{BASE_URL}/{res_admin['item'][0]['id']}/"
await delete_instance(test_client, delete_url, cookies_admin, 204)

# delete as superuser (should pass)
Expand Down Expand Up @@ -93,23 +93,23 @@ async def get_page(page, page_size):
# page 1
data = await get_page(1, 10)
assert data["page"] == 1
assert len(data["items"]) == 10
assert len(data["item"]) == 10

# page 2
data = await get_page(2, 10)
assert data["page"] == 2
assert len(data["items"]) == 10
assert len(data["item"]) == 10

# last page
data = await get_page(4, 10)
assert data["page"] == 4
assert len(data["items"]) == 0
assert len(data["item"]) == 0
# too large page
data = await get_page(99, 10)
assert data["items"] == []
assert data["item"] == []

# search by url
res = await test_client.get(f"{BASE_URL}/", query={"search": "repo-1"}, cookies=cookies_admin)
data = await res.json()
assert res.status == 200
assert any("repo-1" in item["url"] for item in data["items"])
assert any("repo-1" in item["url"] for item in data["item"])
16 changes: 8 additions & 8 deletions backend/app/service_credential/tests/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def test_credential_aws(
# success
aws_instance = await create_instance(
test_client,
f"{BASE_URL}/users/creds/{cred_instance_user_aws["id"]}/",
f"{BASE_URL}/users/creds/{cred_instance_user_aws['id']}/",
aws_data,
cookies=cookies_admin,
)
Expand All @@ -117,7 +117,7 @@ async def test_credential_aws(
bad_data["aws"]["endpoint_url"] = "http://localhost:8081"
instance = await create_instance(
test_client,
f"{BASE_URL}/users/creds/{cred_instance_user_aws["id"]}/",
f"{BASE_URL}/users/creds/{cred_instance_user_aws['id']}/",
bad_data,
cookies_admin,
400,
Expand Down Expand Up @@ -149,7 +149,7 @@ async def test_credential_aws(
# success
aws_instance = await create_instance(
test_client,
f"{BASE_URL}/orgs/{organization}/creds/{cred_instance_org_aws["id"]}/",
f"{BASE_URL}/orgs/{organization}/creds/{cred_instance_org_aws['id']}/",
aws_data,
cookies=cookies_org_manager,
)
Expand All @@ -168,7 +168,7 @@ async def test_credential_aws(
bad_data["aws"]["endpoint_url"] = "http://localhost:8081"
instance = await create_instance(
test_client,
f"{BASE_URL}/orgs/{organization}/creds/{cred_instance_org_aws["id"]}/",
f"{BASE_URL}/orgs/{organization}/creds/{cred_instance_org_aws['id']}/",
bad_data,
cookies_org_manager,
400,
Expand Down Expand Up @@ -254,7 +254,7 @@ async def test_credential_aws(
aws_data["aws"]["endpoint_url"] = os.environ["ENDPOINT_URL"]
aws_instance = await update_instance(
test_client,
f"{BASE_URL}/users/creds/{cred_instance_user_aws["id"]}/",
f"{BASE_URL}/users/creds/{cred_instance_user_aws['id']}/",
aws_data,
cookies=cookies_admin,
expected_status=201,
Expand Down Expand Up @@ -286,7 +286,7 @@ async def test_credential_aws(
aws_data["aws"]["endpoint_url"] = os.environ["ENDPOINT_URL"]
aws_instance = await update_instance(
test_client,
f"{BASE_URL}/orgs/{organization}/creds/{cred_instance_org_aws["id"]}/",
f"{BASE_URL}/orgs/{organization}/creds/{cred_instance_org_aws['id']}/",
aws_data,
cookies=cookies_org_manager,
expected_status=201,
Expand All @@ -303,11 +303,11 @@ async def test_credential_aws(
# Delete
await delete_instance(
test_client,
f"{BASE_URL}/users/creds/{cred_instance_user_aws["id"]}/",
f"{BASE_URL}/users/creds/{cred_instance_user_aws['id']}/",
cookies_admin,
)
await delete_instance(
test_client,
f"{BASE_URL}/orgs/{organization}/creds/{cred_instance_org_aws["id"]}/",
f"{BASE_URL}/orgs/{organization}/creds/{cred_instance_org_aws['id']}/",
cookies_org_manager,
)
4 changes: 2 additions & 2 deletions backend/app/service_credential/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def test_credential_base(

error = await update_instance(
test_client,
f"{BASE_URL}/users/creds/{cred_instance_user_aws["id"]}/",
f"{BASE_URL}/users/creds/{cred_instance_user_aws['id']}/",
bad_data,
cookies_admin,
400,
Expand All @@ -65,7 +65,7 @@ async def test_credential_base(
}
error = await update_instance(
test_client,
f"{BASE_URL}/users/creds/{cred_instance_user_aws["id"]}/",
f"{BASE_URL}/users/creds/{cred_instance_user_aws['id']}/",
bad_data,
cookies_admin,
400,
Expand Down
2 changes: 1 addition & 1 deletion backend/app/service_job/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async def list_web_job(

return ok(
{
"items": result,
"item": result,
"page": page,
"page_size": page_size,
"total": total_count,
Expand Down
10 changes: 5 additions & 5 deletions backend/app/service_job/tests/test_api_web_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ async def test_create_list_job(
)
assert res.status == 200
result = await res.json()
assert "items" in result
assert len(result["items"]) == 5
assert "item" in result
assert len(result["item"]) == 5
assert result["total"] >= 15

# List jobs with pagination (page=3, page_size=5)
Expand All @@ -92,8 +92,8 @@ async def test_create_list_job(
)
assert res.status == 200
result = await res.json()
assert "items" in result
assert len(result["items"]) == 5
assert "item" in result
assert len(result["item"]) == 5

# Search for a specific job by name
search_name = "customer-03"
Expand All @@ -104,7 +104,7 @@ async def test_create_list_job(
)
assert res.status == 200
result = await res.json()
assert any(job["name"] == search_name for job in result["items"])
assert any(job["name"] == search_name for job in result["item"])

# get log of current running job
# TODO: test job log
Expand Down
2 changes: 1 addition & 1 deletion backend/app/service_organization/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def list_organization(

return ok(
{
"items": result,
"item": result,
"page": page,
"page_size": page_size,
"total": total_count,
Expand Down
18 changes: 9 additions & 9 deletions backend/app/service_organization/tests/test_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ async def check_page(page, expected_count):
res_data = await res.json()
assert res.status == 200
assert res_data["page"] == page
assert len(res_data["items"]) == expected_count
for item in res_data["items"]:
assert len(res_data["item"]) == expected_count
for item in res_data["item"]:
assert_instance_fields(item, expected_fields)

await check_page(1, 10)
Expand All @@ -58,22 +58,22 @@ async def check_page(page, expected_count):
res_data = await res.json()
assert res.status == 200
assert res_data["total"] == 1
assert "29" in res_data["items"][0]["name"]
assert "29" in res_data["item"][0]["name"]

# search by description
res = await test_client.get(f"{BASE_URL}", query={"search": "Description-1"}, cookies=cookies_org_manager)
res_data = await res.json()
assert res.status == 200
assert res_data["total"] == 11
assert len(res_data["items"]) == 11
for item in res_data["items"]:
assert len(res_data["item"]) == 11
for item in res_data["item"]:
assert_instance_fields(item, expected_fields)

# Update
update_org = res_data["items"][0]
update_org = res_data["item"][0]
updated_org = await update_instance(
test_client,
f"{BASE_URL}/{update_org["id"]}/",
f"{BASE_URL}/{update_org['id']}/",
data={
"name": "New name",
"description": "New description",
Expand All @@ -90,7 +90,7 @@ async def check_page(page, expected_count):
# delete 1 remains 29
await delete_instance(
test_client,
f"{BASE_URL}/{update_org["id"]}/",
f"{BASE_URL}/{update_org['id']}/",
cookies=cookies_org_manager,
)
res = await test_client.get(
Expand All @@ -99,4 +99,4 @@ async def check_page(page, expected_count):
cookies=cookies_org_manager,
)
res_data = await res.json()
assert len(res_data["items"]) == 29
assert len(res_data["item"]) == 29
2 changes: 1 addition & 1 deletion backend/app/service_project/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async def list_projects(

return ok(
{
"items": result,
"item": result,
"page": page,
"page_size": page_size,
"total": total_count,
Expand Down
Loading