[Config] Asynchronous getters (#907)

* Make config get async

* Asyncify alias

* Asyncify bank

* Asyncify cog manager

* IT BOOTS

* Asyncify core commands

* Asyncify repo manager

* Asyncify downloader

* Asyncify economy

* Asyncify alias TESTS

* Asyncify economy TESTS

* Asyncify downloader TESTS

* Asyncify config TESTS

* A bank thing

* Asyncify Bank cog

* Warning message in docs

* Update docs with await syntax

* Update docs with await syntax
This commit is contained in:
Will
2017-08-11 21:43:21 -04:00
committed by GitHub
parent cf8e11238c
commit de912a3cfb
18 changed files with 371 additions and 296 deletions

View File

@@ -16,12 +16,14 @@ def test_is_valid_alias_name(alias):
assert alias.is_valid_alias_name("not valid name") is False
def test_empty_guild_aliases(alias, empty_guild):
assert list(alias.unloaded_aliases(empty_guild)) == []
@pytest.mark.asyncio
async def test_empty_guild_aliases(alias, empty_guild):
assert list(await alias.unloaded_aliases(empty_guild)) == []
def test_empty_global_aliases(alias):
assert list(alias.unloaded_global_aliases()) == []
@pytest.mark.asyncio
async def test_empty_global_aliases(alias):
assert list(await alias.unloaded_global_aliases()) == []
async def create_test_guild_alias(alias, ctx):
@@ -36,7 +38,7 @@ async def create_test_global_alias(alias, ctx):
async def test_add_guild_alias(alias, ctx):
await create_test_guild_alias(alias, ctx)
is_alias, alias_obj = alias.is_alias(ctx.guild, "test")
is_alias, alias_obj = await alias.is_alias(ctx.guild, "test")
assert is_alias is True
assert alias_obj.global_ is False
@@ -44,19 +46,19 @@ async def test_add_guild_alias(alias, ctx):
@pytest.mark.asyncio
async def test_delete_guild_alias(alias, ctx):
await create_test_guild_alias(alias, ctx)
is_alias, _ = alias.is_alias(ctx.guild, "test")
is_alias, _ = await alias.is_alias(ctx.guild, "test")
assert is_alias is True
await alias.delete_alias(ctx, "test")
is_alias, _ = alias.is_alias(ctx.guild, "test")
is_alias, _ = await alias.is_alias(ctx.guild, "test")
assert is_alias is False
@pytest.mark.asyncio
async def test_add_global_alias(alias, ctx):
await create_test_global_alias(alias, ctx)
is_alias, alias_obj = alias.is_alias(ctx.guild, "test")
is_alias, alias_obj = await alias.is_alias(ctx.guild, "test")
assert is_alias is True
assert alias_obj.global_ is True
@@ -65,7 +67,7 @@ async def test_add_global_alias(alias, ctx):
@pytest.mark.asyncio
async def test_delete_global_alias(alias, ctx):
await create_test_global_alias(alias, ctx)
is_alias, alias_obj = alias.is_alias(ctx.guild, "test")
is_alias, alias_obj = await alias.is_alias(ctx.guild, "test")
assert is_alias is True
assert alias_obj.global_ is True

View File

@@ -11,13 +11,14 @@ def bank(config):
return bank
def test_bank_register(bank, ctx):
default_bal = bank.get_default_balance(ctx.guild)
assert default_bal == bank.get_account(ctx.author).balance
@pytest.mark.asyncio
async def test_bank_register(bank, ctx):
default_bal = await bank.get_default_balance(ctx.guild)
assert default_bal == (await bank.get_account(ctx.author)).balance
async def has_account(member, bank):
balance = bank.get_balance(member)
balance = await bank.get_balance(member)
if balance == 0:
balance = 1
await bank.set_balance(member, balance)
@@ -27,11 +28,11 @@ async def has_account(member, bank):
async def test_bank_transfer(bank, member_factory):
mbr1 = member_factory.get()
mbr2 = member_factory.get()
bal1 = bank.get_account(mbr1).balance
bal2 = bank.get_account(mbr2).balance
bal1 = (await bank.get_account(mbr1)).balance
bal2 = (await bank.get_account(mbr2)).balance
await bank.transfer_credits(mbr1, mbr2, 50)
newbal1 = bank.get_account(mbr1).balance
newbal2 = bank.get_account(mbr2).balance
newbal1 = (await bank.get_account(mbr1)).balance
newbal2 = (await bank.get_account(mbr2)).balance
assert bal1 - 50 == newbal1
assert bal2 + 50 == newbal2
@@ -40,16 +41,16 @@ async def test_bank_transfer(bank, member_factory):
async def test_bank_set(bank, member_factory):
mbr = member_factory.get()
await bank.set_balance(mbr, 250)
acc = bank.get_account(mbr)
acc = await bank.get_account(mbr)
assert acc.balance == 250
@pytest.mark.asyncio
async def test_bank_can_spend(bank, member_factory):
mbr = member_factory.get()
canspend = bank.can_spend(mbr, 50)
assert canspend == (50 < bank.get_default_balance(mbr.guild))
canspend = await bank.can_spend(mbr, 50)
assert canspend == (50 < await bank.get_default_balance(mbr.guild))
await bank.set_balance(mbr, 200)
acc = bank.get_account(mbr)
canspendnow = bank.can_spend(mbr, 100)
acc = await bank.get_account(mbr)
canspendnow = await bank.can_spend(mbr, 100)
assert canspendnow