Skip to content

Commit

Permalink
test that unexpired pastes shouldn't & won't be deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
shtlrs committed Mar 23, 2024
1 parent 3a4955f commit ff23046
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions test/integration/test_reaping_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tempfile
import toml
from unittest.mock import patch, MagicMock
from sqlalchemy import create_engine
from sqlalchemy import create_engine, insert


import pytest
Expand Down Expand Up @@ -59,16 +59,24 @@ async def test_pastes_reaped_on_startup(
engine = manager.DatabaseManager.get_engine()
utils.create_tables(engine)

slugs = [utility.slug_create() for _ in range(2)]

slugs = [utility.slug_create() for _ in range(8)]
persistent_paste_slug = utility.slug_create()
pastes = []
for text in slugs:
paste = models.Paste(text, expiry=1)
file = models.File(paste.slug, text, lexer="text")
paste.files.append(file)
pastes.append(paste)

persistent_paste_text = "I will survive!"
persistent_paste = models.Paste(persistent_paste_slug, expiry=30)
file = models.File(persistent_paste.slug, persistent_paste_text, lexer="text")
persistent_paste.files.append(file)
pastes.append(persistent_paste)

with manager.DatabaseManager.get_session() as session:
session.add(paste)
session.commit()
with manager.DatabaseManager.get_session() as session:
session.add_all(pastes)
session.commit()

# This does two things.
# 1. Most importantly, yields control back to this control from tornado's started loop in the http command.
Expand All @@ -86,3 +94,12 @@ async def test_pastes_reaped_on_startup(
.first()
)
assert paste is None

paste = (
session.query(models.Paste)
.filter(models.Paste.slug == persistent_paste_slug)
.first()
)
assert paste is not None
assert persistent_paste_text == paste.files[0].raw

0 comments on commit ff23046

Please sign in to comment.