Skip to content

Restructure files #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 22, 2024
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 .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
}
},
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pip install -r requirements-dev.txt && pip install -e src",
"postCreateCommand": "pip install -r requirements-dev.txt && pip install -e src/backend",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
6 changes: 3 additions & 3 deletions .github/workflows/app-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ jobs:
python -m pip install -r requirements-dev.txt
- name: Install app as editable app
run: |
python -m pip install -e src
python -m pip install -e src/backend
- name: Setup local database with seed data
run: |
cp .env.sample .env
python ./src/fastapi_app/setup_postgres_database.py
python ./src/fastapi_app/setup_postgres_seeddata.py
python ./src/backend/fastapi_app/setup_postgres_database.py
python ./src/backend/fastapi_app/setup_postgres_seeddata.py
- name: Setup node
uses: actions/setup-node@v4
with:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ Since the local app uses OpenAI models, you should first deploy it for the optim
1. Run these commands to install the web app as a local package (named `fastapi_app`), set up the local database, and seed it with test data:

```bash
python3 -m pip install -e src
python ./src/fastapi_app/setup_postgres_database.py
python ./src/fastapi_app/setup_postgres_seeddata.py
python3 -m pip install -e src/backend
python ./src/backend/fastapi_app/setup_postgres_database.py
python ./src/backend/fastapi_app/setup_postgres_seeddata.py
```

2. Build the frontend:
Expand All @@ -139,7 +139,7 @@ Since the local app uses OpenAI models, you should first deploy it for the optim
cd src/frontend
npm install
npm run build
cd ../..
cd ../../
```

There must be an initial build of static assets before running the backend, since the backend serves static files from the `src/static` directory.
Expand Down
2 changes: 1 addition & 1 deletion azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
template: [email protected]
services:
web:
project: ./src
project: ./src/backend
language: py
module: web
host: containerapp
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-r src/requirements.txt
-r src/backend/requirements.txt
ruff
pre-commit
pip-tools
Expand Down
2 changes: 1 addition & 1 deletion scripts/load_python_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ echo 'Creating Python virtual environment in .venv...'
python3 -m venv .venv

echo 'Installing dependencies from "requirements.txt" into virtual environment (in quiet mode)...'
.venv/bin/python -m pip --quiet --disable-pip-version-check install -e src
.venv/bin/python -m pip --quiet --disable-pip-version-check install -e src/backend
.venv/bin/python -m pip --quiet --disable-pip-version-check install -r requirements-dev.txt
2 changes: 1 addition & 1 deletion scripts/setup_postgres_azurerole.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ if ([string]::IsNullOrEmpty($POSTGRES_HOST) -or [string]::IsNullOrEmpty($POSTGRE
exit 1
}

python ./src/fastapi_app/setup_postgres_azurerole.py --host $POSTGRES_HOST --username $POSTGRES_USERNAME --app-identity-name $APP_IDENTITY_NAME
python ./src/backend/fastapi_app/setup_postgres_azurerole.py --host $POSTGRES_HOST --username $POSTGRES_USERNAME --app-identity-name $APP_IDENTITY_NAME
2 changes: 1 addition & 1 deletion scripts/setup_postgres_azurerole.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ fi

. ./scripts/load_python_env.sh

.venv/bin/python ./src/fastapi_app/setup_postgres_azurerole.py --host $POSTGRES_HOST --username $POSTGRES_USERNAME --app-identity-name $APP_IDENTITY_NAME
.venv/bin/python ./src/backend/fastapi_app/setup_postgres_azurerole.py --host $POSTGRES_HOST --username $POSTGRES_USERNAME --app-identity-name $APP_IDENTITY_NAME
2 changes: 1 addition & 1 deletion scripts/setup_postgres_database.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ if ([string]::IsNullOrEmpty($POSTGRES_HOST) -or [string]::IsNullOrEmpty($POSTGRE
exit 1
}

python ./src/fastapi_app/setup_postgres_database.py --host $POSTGRES_HOST --username $POSTGRES_USERNAME --password $POSTGRES_PASSWORD
python ./backend/src/fastapi_app/setup_postgres_database.py --host $POSTGRES_HOST --username $POSTGRES_USERNAME --password $POSTGRES_PASSWORD
2 changes: 1 addition & 1 deletion scripts/setup_postgres_database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ POSTGRES_DATABASE=$(azd env get-values | grep POSTGRES_DATABASE | sed 's/="/=/'

. ./scripts/load_python_env.sh

.venv/bin/python ./src/fastapi_app/setup_postgres_database.py --host $POSTGRES_HOST --username $POSTGRES_USERNAME --database $POSTGRES_DATABASE
.venv/bin/python ./src/backend/fastapi_app/setup_postgres_database.py --host $POSTGRES_HOST --username $POSTGRES_USERNAME --database $POSTGRES_DATABASE
2 changes: 1 addition & 1 deletion scripts/setup_postgres_seeddata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ if ([string]::IsNullOrEmpty($POSTGRES_HOST) -or [string]::IsNullOrEmpty($POSTGRE
exit 1
}

python ./src/fastapi_app/setup_postgres_seeddata.py --host $POSTGRES_HOST --username $POSTGRES_USERNAME --password $POSTGRES_PASSWORD
python ./src/backend/fastapi_app/setup_postgres_seeddata.py --host $POSTGRES_HOST --username $POSTGRES_USERNAME --password $POSTGRES_PASSWORD
2 changes: 1 addition & 1 deletion scripts/setup_postgres_seeddata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ POSTGRES_DATABASE=$(azd env get-values | grep POSTGRES_DATABASE | sed 's/="/=/'

. ./scripts/load_python_env.sh

.venv/bin/python ./src/fastapi_app/setup_postgres_seeddata.py --host $POSTGRES_HOST --username $POSTGRES_USERNAME --database $POSTGRES_DATABASE
.venv/bin/python ./src/backend/fastapi_app/setup_postgres_seeddata.py --host $POSTGRES_HOST --username $POSTGRES_USERNAME --database $POSTGRES_DATABASE
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
build: {
outDir: "../static",
outDir: "../backend/static",
emptyOutDir: true,
sourcemap: true,
rollupOptions: {
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def create_and_seed_db():
@pytest_asyncio.fixture(scope="session")
async def app(mock_session_env):
"""Create a FastAPI app."""
if not Path("src/static/").exists():
if not Path("src/backend/static/").exists():
pytest.skip("Please generate frontend files first!")
app = create_app(testing=True)
await create_and_seed_db()
Expand Down
30 changes: 21 additions & 9 deletions tests/mocks.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
from collections import namedtuple
from typing import Any

from azure.core.credentials import TokenCredential

MockToken = namedtuple("MockToken", ["token", "expires_on"])
from azure.core.credentials import AccessToken, TokenCredential


class MockAzureCredential(TokenCredential):
def get_token(self, uri):
return MockToken("", 9999999999)
def get_token(
self,
*scopes: str,
claims: str | None = None,
tenant_id: str | None = None,
enable_cae: bool = False,
**kwargs: Any,
) -> AccessToken:
return AccessToken("", 9999999999)


class MockAzureCredentialExpired(TokenCredential):
def __init__(self):
self.access_number = 0

async def get_token(self, uri):
def get_token(
self,
*scopes: str,
claims: str | None = None,
tenant_id: str | None = None,
enable_cae: bool = False,
**kwargs: Any,
) -> AccessToken:
self.access_number += 1
if self.access_number == 1:
return MockToken("", 0)
return AccessToken("", 0)
else:
return MockToken("", 9999999999)
return AccessToken("", 9999999999)
6 changes: 3 additions & 3 deletions tests/test_frontend_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async def test_index(test_client):
"""test the index route"""
response = test_client.get("/")

html_index_file_path = "src/static/index.html"
html_index_file_path = "src/backend/static/index.html"
with open(html_index_file_path, "rb") as f:
html_index_file = f.read()

Expand All @@ -23,7 +23,7 @@ async def test_favicon(test_client):
"""test the favicon route"""
response = test_client.get("/favicon.ico")

favicon_file_path = "src/static/favicon.ico"
favicon_file_path = "src/backend/static/favicon.ico"
with open(favicon_file_path, "rb") as f:
favicon_file = f.read()

Expand All @@ -46,7 +46,7 @@ async def test_assets_non_existent_404(test_client):
@pytest.mark.asyncio
async def test_assets(test_client):
"""test the assets route with an existing file"""
assets_dir_path = "src/static/assets"
assets_dir_path = "src/backend/static/assets"
assets_file_path = os.listdir(assets_dir_path)[0]

with open(os.path.join(assets_dir_path, assets_file_path), "rb") as f:
Expand Down
Loading