Skip to content

Commit 1d2ad61

Browse files
committed
Update environment configuration and improve admin user handling in routes
1 parent e0d6a39 commit 1d2ad61

File tree

4 files changed

+17
-25
lines changed

4 files changed

+17
-25
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
PYTHONPATH=/server
2+
BASE_URL=http://localhost:8000
23

34
# SQLite Database Configuration
45
SQLITE_PATH=/app/data/pynewsdb.db

app/routers/admin/routes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717

1818
async def create_admin(session: AsyncSession):
19-
ADMIN_USER = os.getenv("ADMIN_USER")
20-
ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD")
21-
ADMIN_EMAIL = os.getenv("ADMIN_EMAIL")
19+
ADMIN_USER = os.getenv("ADMIN_USER", "")
20+
ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "")
21+
ADMIN_EMAIL = os.getenv("ADMIN_EMAIL", "")
2222
password = ADMIN_PASSWORD
2323
hashed_password = auth.hash_password(password)
2424
community = DBCommunity(
2525
username=ADMIN_USER,
2626
email=ADMIN_EMAIL,
27-
password=hashed_password,
27+
password=str(hashed_password),
2828
role="admin",
2929
)
3030
await create_community(session=session, community=community)

docker-compose.yaml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3.8"
2-
31
services:
42
pynews-api:
53
build:
@@ -42,22 +40,14 @@ services:
4240
"
4341
restart: "no"
4442

45-
volumes:
46-
sqlite_data:
47-
driver: local
48-
driver_opts:
49-
type: none
50-
o: bind
51-
device: ./data
52-
5343
scanapi-tests:
5444
build:
5545
context: .
5646
dockerfile: Dockerfile
5747
target: scanapi-test
5848
container_name: scanapi-tests
5949
env_file:
60-
- .env.test
50+
- .env
6151
environment:
6252
- BASE_URL=http://pynews-server:8000
6353
volumes:
@@ -79,6 +69,12 @@ volumes:
7969

8070
volumes:
8171
report-data:
72+
sqlite_data:
73+
driver: local
74+
driver_opts:
75+
type: none
76+
o: bind
77+
device: ./data
8278

8379
networks:
8480
default:

scanapi/scanapi.yaml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,26 @@ endpoints:
22
- name: py_news_server
33
path: ${BASE_URL}/api
44
vars:
5-
community_username: ${USERNAME_TEST}
6-
community_password: ${PASSWORD_TEST}
5+
admin_user: ${ADMIN_USER}
6+
admin_password: ${ADMIN_PASSWORD}
77
requests:
88
- name: healthcheck
99
path: healthcheck
1010
tests:
1111
- !include tests/status_code_is_200.yaml
1212
- !include tests/healthcheck/body_status_healthy.yaml
13-
- name: create_community
14-
path: authentication/create_community
15-
method: POST
16-
body:
17-
name: "Test Community"
1813
- name: login_for_access_token
1914
path: authentication/token
2015
method: POST
2116
headers:
2217
Content-Type: application/x-www-form-urlencoded
2318
body:
24-
username: ${community_username}
25-
password: ${community_password}
19+
username: ${admin_user}
20+
password: ${admin_password}
2621
tests:
2722
- !include tests/status_code_is_200.yaml
2823
vars:
29-
access_token: ${{ response.json()["access_token"] }}
24+
access_token: ${{ response.json()["access_token"] if response.status_code == 200 else "" }}
3025
endpoints:
3126
- !include libraries_authenticated.yaml
3227
- !include libraries_unauthenticated.yaml

0 commit comments

Comments
 (0)