## Summary Closes #5. - Composer can **Send now** without a schedule time (Schedule and Save draft still available) - Account names wrap and show the platform id so a bad OAuth label is still readable - Social accounts page can rename the display name; re-auth keeps a custom name instead of overwriting it with a placeholder - Worker polls `dispatch_due` every 15s so scheduled campaigns and social posts fire without a manual command; local `docker compose up` now starts the worker ## Test plan - [ ] Open Social → Compose: confirm **Send now**, **Schedule**, and **Save draft** buttons (no combined Save / publish) - [ ] Send now with a connected account and caption → post queues immediately, no datetime required - [ ] Schedule with a datetime → post is scheduled; Schedule with a blank time → validation error - [ ] Composer account list shows full name plus external id, wrapping if the name is long - [ ] Social accounts → rename a messy label → new name shows in composer without reconnecting - [ ] Re-authorize an account that was renamed → custom name is kept - [ ] Rebuild and start compose (`docker compose up --build`) so the **worker** service is running - [ ] Schedule a social post ~2 minutes ahead → after due time, worker logs `Enqueued N due item(s).` and the post leaves Scheduled (published or failed) - [ ] `docker compose logs -f worker` shows `Polling due scheduled work every 15s.` Reviewed-on: #6
78 lines
2.7 KiB
Python
78 lines
2.7 KiB
Python
from datetime import timedelta
|
|
from io import StringIO
|
|
from unittest.mock import patch
|
|
|
|
from django.core.management import call_command
|
|
from django.test import Client, TestCase, override_settings
|
|
from django.urls import reverse
|
|
from django.utils import timezone
|
|
|
|
from social.models import SocialPost
|
|
|
|
|
|
class HealthzTests(TestCase):
|
|
def test_healthz_ok(self):
|
|
response = Client().get("/healthz/")
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.json()["status"], "ok")
|
|
|
|
|
|
class UnderConstructionTests(TestCase):
|
|
@override_settings(SITE_UNDER_CONSTRUCTION=True)
|
|
def test_home_redirects_when_gated(self):
|
|
response = Client().get("/")
|
|
self.assertEqual(response.status_code, 302)
|
|
self.assertIn("/under-construction", response["Location"])
|
|
|
|
@override_settings(SITE_UNDER_CONSTRUCTION=False)
|
|
def test_home_ok_when_open(self):
|
|
response = Client().get("/")
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
class PublicSmokeTests(TestCase):
|
|
def test_about_and_contact_get(self):
|
|
client = Client()
|
|
self.assertEqual(client.get(reverse("public:about")).status_code, 200)
|
|
self.assertEqual(client.get(reverse("public:contact")).status_code, 200)
|
|
|
|
|
|
class DispatchDueTests(TestCase):
|
|
def test_enqueues_past_scheduled_social_post(self):
|
|
post = SocialPost.objects.create(
|
|
body="Open house",
|
|
status=SocialPost.Status.SCHEDULED,
|
|
scheduled_for=timezone.now() - timedelta(minutes=5),
|
|
)
|
|
mock_task = patch(
|
|
"core.management.commands.dispatch_due.publish_social_post"
|
|
).start()
|
|
self.addCleanup(patch.stopall)
|
|
out = StringIO()
|
|
call_command("dispatch_due", stdout=out)
|
|
post.refresh_from_db()
|
|
self.assertEqual(post.status, SocialPost.Status.QUEUED)
|
|
mock_task.enqueue.assert_called_once_with(post_id=str(post.pk))
|
|
self.assertIn("Enqueued 1 due item(s).", out.getvalue())
|
|
|
|
def test_skips_future_scheduled_social_post(self):
|
|
post = SocialPost.objects.create(
|
|
body="Later",
|
|
status=SocialPost.Status.SCHEDULED,
|
|
scheduled_for=timezone.now() + timedelta(hours=1),
|
|
)
|
|
mock_task = patch(
|
|
"core.management.commands.dispatch_due.publish_social_post"
|
|
).start()
|
|
self.addCleanup(patch.stopall)
|
|
call_command("dispatch_due", stdout=StringIO())
|
|
post.refresh_from_db()
|
|
self.assertEqual(post.status, SocialPost.Status.SCHEDULED)
|
|
mock_task.enqueue.assert_not_called()
|
|
|
|
def test_quiet_when_nothing_due(self):
|
|
out = StringIO()
|
|
call_command("dispatch_due", stdout=out)
|
|
self.assertEqual(out.getvalue(), "")
|
|
|