tests(storages): improve tests

add .cov config report ignores
This commit is contained in:
mpa 2020-08-18 16:10:44 +04:00
parent 071e006021
commit 25ecc6fafc
No known key found for this signature in database
GPG key ID: BCCFBFCCC9B754A8
3 changed files with 19 additions and 1 deletions

View file

@ -0,0 +1,5 @@
[report]
exclude_lines =
pragma: no cover
if TYPE_CHECKING:
raise NotImplementedError

View file

@ -69,7 +69,7 @@ class TestCurrentUserContext:
mocked.assert_awaited()
@pytest.mark.asyncio
@pytest.mark.parametrize("getter_method", ("set_state", "set_data"))
@pytest.mark.parametrize("getter_method", ("get_state", "get_data"))
async def test_getters(self, storage, getter_method):
chat_id, user_id = 1, 2
ctx = CurrentUserContext(storage, chat_id, user_id)
@ -78,6 +78,10 @@ class TestCurrentUserContext:
await getattr(ctx, getter_method)()
mocked.assert_awaited()
assert await getattr(ctx, getter_method)() == await getattr(storage, getter_method)(
key=ctx.key
)
@pytest.mark.asyncio
@pytest.mark.parametrize("reseter_method", ("reset_data", "reset_state", "finish"))
async def test_setters(self, storage, reseter_method):
@ -116,3 +120,7 @@ class TestCurrentUserContext:
new_data = LegitMapping()
assert await ctx.update_data(data=new_data) is None
assert await ctx.get_data() == new_data
await ctx.reset_data()
assert await ctx.update_data(data=None) is None
assert await ctx.get_data() == {}

View file

@ -51,6 +51,11 @@ class TestDictStorage:
assert await storage.reset_data(key=key) is None
assert await storage.get_data(key=key) == {} # reset_data makes data empty dict
new_data = {"abc": "abc"}
assert await storage.update_data(key=key, data=new_data) is None
assert await storage.update_data(key=key, data=None) is None
assert await storage.get_data(key=key) == new_data
@pytest.mark.asyncio
async def test_finish(self):
# finish turns data into initial one