def test_initialize_room_部屋を初期化する(self, sut, getter, putter): putter({ "room_id": "abcdef", "mem_1000000001": { "nickname": "ななし1", "point": 5 }, "mem_1000000002": { "nickname": "ななし2", "point": 1 }, "mem_1000000003": { "nickname": "ななし3", "point": 3 }, "opened": True, }) room = Room(room_id="abcdef", members=[ Member("1000000001", "ななし1", point=None), Member("1000000002", "ななし2", point=None), Member("1000000003", "ななし3", point=None), ]) now = Arrow(2020, 11, 22) sut.initialize_room(room, now) actual = getter("abcdef") assert actual["opened"] is False assert actual["mem_1000000001"] == {"nickname": "ななし1", "point": None} assert actual["mem_1000000002"] == {"nickname": "ななし2", "point": None} assert actual["mem_1000000003"] == {"nickname": "ななし3", "point": None} assert actual["ttl"] == 1606089600
def test_query_room_dbから取得できる(self, sut, putter): putter({ "room_id": "abcdef", "mem_1000000001": { "nickname": "ななし1", "point": 5 }, "mem_1000000002": { "nickname": "ななし2", "point": 1 }, "mem_1000000003": { "nickname": "ななし3", "point": None }, "opened": False, }) actual = sut.query_room("abcdef") assert actual.room_id == "abcdef" assert actual.opened is False assert len(actual.members) == 3 assert (Member(member_id="1000000001", nickname="ななし1", point=5) in actual.members) assert (Member(member_id="1000000002", nickname="ななし2", point=1) in actual.members) assert (Member(member_id="1000000003", nickname="ななし3", point=None) in actual.members)
def test_act_member_ニックネーム変更(self, sut, getter, putter): putter({ "room_id": "abcdef", "mem_2000000001": { "nickname": "test_name1", "point": None }, "opened": False, }) room = Room(room_id="abcdef") member = Member(member_id="2000000001", nickname="test_name2", point=None) sut.act_member(member, room) actual = getter("abcdef") assert actual == { "room_id": "abcdef", "mem_2000000001": { "nickname": "test_name2", "point": None }, "opened": False, }
def query_room(self, room_id: str) -> Optional[Room]: """ 指定したidの部屋が存在すれば返す :param room_id: :return: 指定したidの部屋が存在すれば返す """ res = self.table.get_item(Key={"room_id": room_id}).get("Item") if not res: return None # 内包表記ver. members = [ Member( member_id=key[4:], nickname=value["nickname"], point=value.get("point"), ) for key, value in res.items() if key.startswith("mem_") ] return Room(room_id=res["room_id"], opened=res["opened"], members=members)
def test_act_member_部屋に参加する(self, sut, getter, putter): putter({ "room_id": "abcdef", "opened": False, }) room = Room(room_id="abcdef") member = Member(member_id="2000000001", nickname="test_name1", point=None) sut.act_member(member, room) actual = getter("abcdef") assert actual["room_id"] == "abcdef" assert actual["mem_2000000001"] == { "nickname": "test_name1", "point": None } assert actual["mem_2000000001"] == { "nickname": "test_name1", "point": None } assert actual["opened"] is False