Add test for db get old squeaks to delete (#1641)

* Add test for get squeaks to delete db method

* Improve test for get squeaks to delete db method

* Add test for get squeaks to delete with liked squeaks and authored squeak
This commit is contained in:
Jonathan Zernik 2021-10-18 20:32:56 -07:00 committed by GitHub
parent 3ffa122f4f
commit 26eae15509
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,8 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import time
import mock
import pytest
from sqlalchemy import create_engine
@ -129,6 +131,15 @@ def followed_squeak_hashes(
yield inserted_squeak_hashes
@pytest.fixture
def authored_squeak_hashes(
squeak_db,
inserted_squeak_hashes,
inserted_signing_profile,
):
yield inserted_squeak_hashes
@pytest.fixture
def unfollowed_squeak_hashes(
squeak_db,
@ -655,3 +666,90 @@ def test_number_of_squeaks_with_address_in_block_range(
)
assert num_squeaks == max_block - min_block + 1
def test_get_old_squeaks_to_delete(
squeak_db,
followed_squeak_hashes,
):
current_time_ms = int(time.time() * 1000)
time_elapsed_s = 56789
fake_current_time_ms = current_time_ms + 1000 * time_elapsed_s
# TODO: set up test so it returns positive number of squeaks to delete.
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
interval_s = time_elapsed_s - 10
hashes_to_delete = squeak_db.get_old_squeaks_to_delete(
interval_s=interval_s,
)
assert len(hashes_to_delete) == 100
def test_get_old_squeaks_to_delete_none(
squeak_db,
followed_squeak_hashes,
):
current_time_ms = int(time.time() * 1000)
time_elapsed_s = 56789
fake_current_time_ms = current_time_ms + 1000 * time_elapsed_s
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
interval_s = time_elapsed_s + 10
hashes_to_delete = squeak_db.get_old_squeaks_to_delete(
interval_s=interval_s,
)
assert len(hashes_to_delete) == 0
def test_get_old_squeaks_to_delete_none_signing_profile(
squeak_db,
authored_squeak_hashes,
):
"""
`get_old_squeaks_to_delete` Method should return 0 results because
all squeaks are authored by the signing profile.
"""
current_time_ms = int(time.time() * 1000)
time_elapsed_s = 56789
fake_current_time_ms = current_time_ms + 1000 * time_elapsed_s
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
interval_s = time_elapsed_s - 10
hashes_to_delete = squeak_db.get_old_squeaks_to_delete(
interval_s=interval_s,
)
assert len(hashes_to_delete) == 0
def test_get_old_squeaks_to_delete_none_liked(
squeak_db,
liked_squeak_hashes,
):
"""
`get_old_squeaks_to_delete` Method should return 0 results because
all squeaks are liked.
"""
current_time_ms = int(time.time() * 1000)
time_elapsed_s = 56789
fake_current_time_ms = current_time_ms + 1000 * time_elapsed_s
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
interval_s = time_elapsed_s - 10
hashes_to_delete = squeak_db.get_old_squeaks_to_delete(
interval_s=interval_s,
)
assert len(hashes_to_delete) == 0