mirror of https://gitlab.com/litecord/litecord.git
tests: add test for guild pruning
This commit is contained in:
parent
cf63a58a63
commit
6608db7bf1
|
|
@ -17,9 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import secrets
|
import secrets
|
||||||
|
import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from litecord.common.guilds import add_member
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_guild_create(test_cli_user):
|
async def test_guild_create(test_cli_user):
|
||||||
|
|
@ -102,3 +105,48 @@ async def test_guild_nickname(test_cli_user):
|
||||||
|
|
||||||
assert fetched_guild["id"] == str(guild.id)
|
assert fetched_guild["id"] == str(guild.id)
|
||||||
assert fetched_guild["members"][0]["nick"] == NEW_NICKNAME
|
assert fetched_guild["members"][0]["nick"] == NEW_NICKNAME
|
||||||
|
|
||||||
|
|
||||||
|
async def test_prune_guild(test_cli_user):
|
||||||
|
guild = await test_cli_user.create_guild()
|
||||||
|
user = await test_cli_user.create_user()
|
||||||
|
async with test_cli_user.app.app_context():
|
||||||
|
await add_member(guild.id, user.id)
|
||||||
|
|
||||||
|
# assert setup went well
|
||||||
|
added_member_guild = await guild.refetch()
|
||||||
|
assert added_member_guild.member_count == 2
|
||||||
|
|
||||||
|
resp = await test_cli_user.get(
|
||||||
|
f"/api/v6/guilds/{guild.id}/prune", query_string={"days": 7}
|
||||||
|
)
|
||||||
|
assert resp.status_code == 200
|
||||||
|
rjson = await resp.json
|
||||||
|
assert rjson["pruned"] == 0
|
||||||
|
|
||||||
|
# set joined_at to the beginning of the universe
|
||||||
|
await test_cli_user.app.db.execute(
|
||||||
|
"UPDATE users SET last_session = $1 WHERE id = $2",
|
||||||
|
datetime.datetime(year=2010, month=1, day=1),
|
||||||
|
user.id,
|
||||||
|
)
|
||||||
|
|
||||||
|
# execute compute prune, must return 1
|
||||||
|
resp = await test_cli_user.get(
|
||||||
|
f"/api/v6/guilds/{guild.id}/prune", query_string={"days": 7}
|
||||||
|
)
|
||||||
|
assert resp.status_code == 200
|
||||||
|
rjson = await resp.json
|
||||||
|
assert rjson["pruned"] == 1
|
||||||
|
|
||||||
|
# execute prune, member count should go to 1
|
||||||
|
resp = await test_cli_user.post(
|
||||||
|
f"/api/v6/guilds/{guild.id}/prune",
|
||||||
|
query_string={"days": 7},
|
||||||
|
)
|
||||||
|
assert resp.status_code == 200
|
||||||
|
rjson = await resp.json
|
||||||
|
assert rjson["pruned"] == 1
|
||||||
|
|
||||||
|
pruned_member_guild = await guild.refetch()
|
||||||
|
assert pruned_member_guild.member_count == 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue