async def test_guilds_select(self): guilds = GuildsService() assert not await guilds.select(404) GuildFactory.create(xid=404) assert await guilds.select(404)
async def test_guilds_should_show_points(self): guild1 = GuildFactory.create() guild2 = GuildFactory.create(show_points=True) guilds = GuildsService() await guilds.select(guild1.xid) assert not await guilds.should_show_points() await guilds.select(guild2.xid) assert await guilds.should_show_points()
async def test_guilds_voiced(self): guilds = GuildsService() assert await guilds.voiced() == [] guild1 = GuildFactory.create(voice_create=True) GuildFactory.create() guild3 = GuildFactory.create(voice_create=True) assert set(await guilds.voiced()) == {guild1.xid, guild3.xid}
async def test_guilds_to_dict(self): guild = GuildFactory.create(xid=101) guilds = GuildsService() await guilds.select(101) service_dict = await guilds.to_dict() assert guild.to_dict() == service_dict
def test_meeting_create_serializer_validate_guild(): user = UserFactory() guild = GuildFactory() guild.members.add(user) serializer = MeetingCreateSerializer(context={"request": Mock(user=user)}) result = serializer.validate_guild(guild) assert result == guild
def test_meeting_create_serializer_validate_guild_error(): guild = GuildFactory() serializer = MeetingCreateSerializer( context={"request": Mock(user=UserFactory())}) with pytest.raises(ValidationError) as exc_info: serializer.validate_guild(guild) assert (str(exc_info.value.detail[0]) == "You cannot add a meeting to a guild you don't belong!")
async def test_guilds_set_motd(self): guilds = GuildsService() assert not await guilds.select(101) guild = GuildFactory.create() guilds = GuildsService() await guilds.select(guild.xid) message_of_the_day = "message of the day" await guilds.set_motd(message_of_the_day) DatabaseSession.expire_all() guild = DatabaseSession.query(Guild).get(guild.xid) assert guild and guild.motd == message_of_the_day
async def test_fetch(self): guild1 = GuildFactory.create() guild2 = GuildFactory.create() user1 = UserFactory.create(xid=101) user2 = UserFactory.create(xid=102) user3 = UserFactory.create(xid=103) watch1 = WatchFactory.create(guild_xid=guild1.xid, user_xid=user1.xid) watch2 = WatchFactory.create(guild_xid=guild1.xid, user_xid=user2.xid) WatchFactory.create(guild_xid=guild2.xid, user_xid=user3.xid) DatabaseSession.expire_all() watches = WatchesService() assert await watches.fetch(guild1.xid) == [ { "guild_xid": guild1.xid, "note": watch1.note, "user_xid": user1.xid, }, { "guild_xid": guild1.xid, "note": watch2.note, "user_xid": user2.xid, }, ]
async def test_guilds_toggle_voice_create(self): guilds = GuildsService() assert not await guilds.select(101) guild = GuildFactory.create(xid=101) guilds = GuildsService() await guilds.select(101) await guilds.toggle_voice_create() DatabaseSession.expire_all() guild = DatabaseSession.query(Guild).get(101) assert guild and guild.voice_create await guilds.select(101) await guilds.toggle_voice_create() DatabaseSession.expire_all() guild = DatabaseSession.query(Guild).get(101) assert guild and not guild.voice_create
async def test_guilds_toggle_show_points(self): guilds = GuildsService() assert not await guilds.select(101) guild = GuildFactory.create(xid=101, name="guild-name") guilds = GuildsService() await guilds.select(101) await guilds.toggle_show_points() DatabaseSession.expire_all() guild = DatabaseSession.query(Guild).get(101) assert guild and guild.show_points await guilds.select(101) await guilds.toggle_show_points() DatabaseSession.expire_all() guild = DatabaseSession.query(Guild).get(101) assert guild and not guild.show_points
async def test_guilds_current_name(self): guild = GuildFactory.create(xid=101) guilds = GuildsService() await guilds.select(101) assert await guilds.current_name() == guild.name
def step_impl(context, belong): context.guild = GuildFactory() if belong == "do": context.guild.members.add(context.user)