From 70fbb9e7db6a966823c17d8729b050ea00e5e83f Mon Sep 17 00:00:00 2001 From: Jonathan Zernik Date: Tue, 19 Oct 2021 01:34:50 -0700 Subject: [PATCH] Add test for get profiles db method (#1646) * Add test for get profiles db method * Add test for get contact profiles db method --- tests/db/test_squeak_db.py | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/db/test_squeak_db.py b/tests/db/test_squeak_db.py index e7365ada..b57bf034 100644 --- a/tests/db/test_squeak_db.py +++ b/tests/db/test_squeak_db.py @@ -27,7 +27,10 @@ from sqlalchemy import create_engine from squeaknode.db.squeak_db import SqueakDb from tests.utils import gen_address +from tests.utils import gen_contact_profile from tests.utils import gen_random_hash +from tests.utils import gen_signing_key +from tests.utils import gen_signing_profile from tests.utils import gen_squeak_with_block_header @@ -180,6 +183,30 @@ def inserted_peer_id(squeak_db, peer): yield squeak_db.insert_peer(peer) +@pytest.fixture +def inserted_contact_profile_ids(squeak_db): + ret = [] + for i in range(100): + profile_name = "contact_profile_{}".format(i) + address = str(gen_address()) + profile = gen_contact_profile(profile_name, address) + profile_id = squeak_db.insert_profile(profile) + ret.append(profile_id) + yield ret + + +@pytest.fixture +def inserted_signing_profile_ids(squeak_db): + ret = [] + for i in range(100): + profile_name = "signing_profile_{}".format(i) + signing_key = str(gen_signing_key()) + profile = gen_signing_profile(profile_name, signing_key) + profile_id = squeak_db.insert_profile(profile) + ret.append(profile_id) + yield ret + + def test_init_with_retries(squeak_db): with mock.patch.object(squeak_db, 'init', autospec=True) as mock_init, \ mock.patch('squeaknode.db.squeak_db.time.sleep', autospec=True) as mock_sleep: @@ -753,3 +780,50 @@ def test_get_old_squeaks_to_delete_none_liked( ) assert len(hashes_to_delete) == 0 + + +def test_get_profiles( + squeak_db, + inserted_contact_profile_ids, + inserted_signing_profile_ids, +): + profiles = squeak_db.get_profiles() + + assert len(profiles) == len(inserted_contact_profile_ids) + \ + len(inserted_signing_profile_ids) + + +def test_get_signing_profiles( + squeak_db, + inserted_signing_profile_ids, +): + profiles = squeak_db.get_signing_profiles() + + assert len(profiles) == len(inserted_signing_profile_ids) + + +def test_get_signing_profiles_none( + squeak_db, + inserted_contact_profile_ids, +): + profiles = squeak_db.get_signing_profiles() + + assert len(profiles) == 0 + + +def test_get_contact_profiles( + squeak_db, + inserted_contact_profile_ids, +): + profiles = squeak_db.get_contact_profiles() + + assert len(profiles) == len(inserted_contact_profile_ids) + + +def test_get_contact_profiles_none( + squeak_db, + inserted_signing_profile_ids, +): + profiles = squeak_db.get_contact_profiles() + + assert len(profiles) == 0