Skip to content

Commit

Permalink
Move to pyodmongo 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelseeger committed Jun 6, 2024
1 parent 0f5e394 commit 37b8da1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ This is invoked at the very start of an SC2 game (when the in-game clock hits 1
- Summarize past strategies of the opponent
- Ask for follow up questions

You can configure which events AICoach should react to with the `coach_events` option.

### Configure coach events

You can configure which events AICoach should react to with the `coach_events` option.

```yaml
# config.yourname.yml
Expand Down
8 changes: 4 additions & 4 deletions replays/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pydantic_core import ValidationError
from pymongo.collection import Collection
from pyodmongo import DbEngine, DbModel
from pyodmongo.models.responses import SaveResponse
from pyodmongo.models.responses import DbResponse
from pyodmongo.queries import eq, sort
from typing_extensions import override

Expand All @@ -23,17 +23,17 @@ def __init__(self):
self.replays: Collection = self.db._db["replays"]
self.meta: Collection = self.db._db["replays.meta"]

def upsert(self, model: SC2Model) -> SaveResponse:
def upsert(self, model: SC2Model) -> DbResponse:
ModelClass = model.__class__
try:
return self.db.save(model, query=eq(ModelClass.id, model.id))
except ValidationError as e:
# On INSERT, pyodm forces the returned ID into mongo ObjectId and throws since we use a custom ID field
# Return SaveResponse without validation instead
return SaveResponse.model_construct(
return DbResponse.model_construct(
**{
"acknowledged": True,
"upserted_id": model.id,
"upserted_ids": {0: model.id},
"matched_count": 0,
"modified_count": 0,
}
Expand Down
10 changes: 6 additions & 4 deletions tests/integration/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from config import config
from replays import ReplayReader, replaydb
from replays.db import eq
from replays.types import AssistantMessage, Metadata, Replay, Role
Expand Down Expand Up @@ -63,8 +64,8 @@ def test_upsert_existing_replay(replay_file):


def test_upsert_new_replay():
# random 64 character id
new_id = "a" * 64

new_id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

replay = Replay(
id=new_id,
Expand All @@ -76,14 +77,15 @@ def test_upsert_new_replay():

result = replaydb.upsert(replay)
assert result.acknowledged
assert result.upserted_id == new_id
assert any(new_id == v for k, v in result.upserted_ids.items())

del_result = replaydb.db.delete_one(Replay, query=eq(Replay.id, new_id))
del_result = replaydb.db.delete(Replay, query=eq(Replay.id, new_id))

assert del_result.deleted_count == 1
assert del_result.acknowledged


def test_get_most_recent():
replay: Replay = replaydb.get_most_recent()
assert any(config.student.name in player.name for player in replay.players)
assert replay is not None

0 comments on commit 37b8da1

Please sign in to comment.