mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-19 13:18:26 +02:00
Add test for get profiles db method (#1646)
* Add test for get profiles db method * Add test for get contact profiles db method
This commit is contained in:
parent
4b35021ba0
commit
70fbb9e7db
1 changed files with 74 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue