Skip to content
Open
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
4 changes: 3 additions & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ jobs:

- name: Run S3 tracking server tests
run: |
python -m pytest tests/tracking/test_bip0042_s3_buffering.py -v
python -m pytest \
tests/tracking/test_bip0042_s3_buffering.py \
tests/tracking/test_s3_initialize_db.py -v

test-bedrock:
runs-on: ubuntu-latest
Expand Down
7 changes: 2 additions & 5 deletions burr/tracking/server/s3/initialize_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@
# specific language governing permissions and limitations
# under the License.

import os
from pathlib import Path

from tortoise import Tortoise, run_async

from burr.tracking.server.s3 import settings

DB_PATH = Path("~/.burr_server/db.sqlite3").expanduser()


async def connect():
if not os.path.exists(DB_PATH):
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
db_path = Path(settings.DB_PATH).expanduser()
db_path.parent.mkdir(parents=True, exist_ok=True)
await Tortoise.init(
config=settings.TORTOISE_ORM,
)
Expand Down
38 changes: 38 additions & 0 deletions tests/tracking/test_s3_initialize_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import asyncio
from unittest.mock import AsyncMock

import pytest

pytest.importorskip("tortoise")
from burr.tracking.server.s3 import initialize_db, settings


def test_connect_uses_configured_database_path(tmp_path, monkeypatch):
db_path = tmp_path / "nested" / "custom.sqlite3"
tortoise_config = {"connections": {"default": f"sqlite:///{db_path}"}, "apps": {}}
tortoise_init = AsyncMock()
monkeypatch.setattr(settings, "DB_PATH", str(db_path))
monkeypatch.setattr(settings, "TORTOISE_ORM", tortoise_config)
monkeypatch.setattr(initialize_db.Tortoise, "init", tortoise_init)

asyncio.run(initialize_db.connect())

assert db_path.parent.is_dir()
tortoise_init.assert_awaited_once_with(config=tortoise_config)
Loading