Skip to content

Commit

Permalink
Add tests for flush command
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Mar 29, 2024
1 parent cf118a2 commit 2915f07
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions tests/test_management_commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import timedelta
from datetime import datetime, timedelta
from io import StringIO

from django.conf import settings
from django.core import mail
Expand All @@ -9,7 +10,7 @@

from timeline_logger.models import TimelineLog

from .factories import ArticleFactory, UserFactory
from .factories import ArticleFactory, TimelineLogFactory, UserFactory


class ReportMailingTestCase(TestCase):
Expand Down Expand Up @@ -152,3 +153,32 @@ def test_timeline_digest_from_email_setting(self):

self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].from_email, settings.TIMELINE_DIGEST_FROM_EMAIL)


class PruneTimelineLogsTestCase(TestCase):
def setUp(self):

self.log_1 = TimelineLogFactory.create(
timestamp=datetime(2024, 3, 1, 12, 0, 0),
)

self.log_2 = TimelineLogFactory.create(timestamp=datetime(2024, 3, 1, 14, 0, 0))

def test_prune_timeline_logs_no_date(self):
call_command(
"prune_timeline_logs", interactive=False, verbosity=0, stdout=StringIO()
)

self.assertEqual(TimelineLog.objects.count(), 0)

def test_prune_timeline_logs_date(self):
call_command(
"prune_timeline_logs",
before=datetime(2024, 3, 1, 13, 0, 0),
interactive=False,
verbosity=0,
stdout=StringIO(),
)

self.assertEqual(TimelineLog.objects.count(), 1)
self.assertEqual(TimelineLog.objects.first().pk, self.log_2.pk)

0 comments on commit 2915f07

Please sign in to comment.