mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-13 12:33:25 +02:00
Add test for get sent offer by squeak and peer (#1693)
This commit is contained in:
parent
76e1bd29cc
commit
dc6cef8cff
2 changed files with 75 additions and 0 deletions
|
|
@ -1205,6 +1205,8 @@ class SqueakDb:
|
|||
"""
|
||||
Get a sent offer by squeak hash and peer address host. Only
|
||||
return sent offer if it's not expired and not paid.
|
||||
|
||||
TODO: add where clause for peer address network.
|
||||
"""
|
||||
s = (
|
||||
select([self.sent_offers])
|
||||
|
|
|
|||
|
|
@ -1269,3 +1269,76 @@ def test_get_sent_offer_missing(squeak_db, inserted_sent_offer_id):
|
|||
)
|
||||
|
||||
assert retrieved_sent_offer is None
|
||||
|
||||
|
||||
def test_get_sent_offer_by_squeak_and_peer(
|
||||
squeak_db,
|
||||
inserted_sent_offer_id,
|
||||
sent_offer,
|
||||
squeak_hash,
|
||||
peer_address,
|
||||
creation_date,
|
||||
expiry,
|
||||
):
|
||||
expire_time_s = creation_date + expiry
|
||||
current_time_s = expire_time_s - 10
|
||||
fake_current_time_ms = current_time_s * 1000
|
||||
|
||||
with mock.patch.object(SqueakDb, 'timestamp_now_ms', new_callable=mock.PropertyMock) as mock_timestamp_ms:
|
||||
mock_timestamp_ms.return_value = fake_current_time_ms
|
||||
|
||||
retrieved_sent_offer = squeak_db.get_sent_offer_by_squeak_hash_and_peer(
|
||||
squeak_hash,
|
||||
peer_address,
|
||||
)
|
||||
|
||||
assert retrieved_sent_offer._replace(
|
||||
sent_offer_id=None,
|
||||
) == sent_offer
|
||||
|
||||
|
||||
def test_get_sent_offer_by_squeak_and_peer_wrong_squeak_hash(
|
||||
squeak_db,
|
||||
inserted_sent_offer_id,
|
||||
sent_offer,
|
||||
peer_address,
|
||||
creation_date,
|
||||
expiry,
|
||||
):
|
||||
expire_time_s = creation_date + expiry
|
||||
current_time_s = expire_time_s - 10
|
||||
fake_current_time_ms = current_time_s * 1000
|
||||
|
||||
with mock.patch.object(SqueakDb, 'timestamp_now_ms', new_callable=mock.PropertyMock) as mock_timestamp_ms:
|
||||
mock_timestamp_ms.return_value = fake_current_time_ms
|
||||
|
||||
retrieved_sent_offer = squeak_db.get_sent_offer_by_squeak_hash_and_peer(
|
||||
gen_random_hash(),
|
||||
peer_address,
|
||||
)
|
||||
|
||||
assert retrieved_sent_offer is None
|
||||
|
||||
|
||||
def test_get_sent_offer_by_squeak_and_peer_wrong_peer_address(
|
||||
squeak_db,
|
||||
inserted_sent_offer_id,
|
||||
sent_offer,
|
||||
squeak_hash,
|
||||
peer_address,
|
||||
creation_date,
|
||||
expiry,
|
||||
):
|
||||
expire_time_s = creation_date + expiry
|
||||
current_time_s = expire_time_s - 10
|
||||
fake_current_time_ms = current_time_s * 1000
|
||||
|
||||
with mock.patch.object(SqueakDb, 'timestamp_now_ms', new_callable=mock.PropertyMock) as mock_timestamp_ms:
|
||||
mock_timestamp_ms.return_value = fake_current_time_ms
|
||||
|
||||
retrieved_sent_offer = squeak_db.get_sent_offer_by_squeak_hash_and_peer(
|
||||
squeak_hash,
|
||||
peer_address._replace(host="wrong_host"),
|
||||
)
|
||||
|
||||
assert retrieved_sent_offer is None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue