@@ -0,0 +1,2993 @@
+from datetime import timedelta%0Afrom io import StringIO%0Afrom unittest.mock import Mock, patch%0A%0Afrom django.core.management import call_command%0Afrom django.test import TestCase%0A%0Afrom . import factories%0A%0A%0Aclass CheckDomainsCommandTestCase(TestCase):%0A    %22%22%22Management command for running the domain checks.%22%22%22%0A%0A    def call_command(self, **kwargs):%0A        %22%22%22Helper to call the management command and return stdout/stderr.%22%22%22%0A        stdout, stderr = StringIO(), StringIO()%0A        kwargs%5B'stdout'%5D, kwargs%5B'stderr'%5D = stdout, stderr%0A        call_command('checkdomains', **kwargs)%0A        stdout.seek(0)%0A        stderr.seek(0)%0A        return stdout, stderr%0A%0A    def test_no_checks(self):%0A        %22%22%22Call command with no checks configured.%22%22%22%0A        stdout, stderr = self.call_command()%0A        self.assertIn('0 domain statuses updated', stdout.getvalue())%0A%0A    @patch('domainchecks.management.commands.checkdomains.DomainCheck')%0A    def test_check_stale_domains(self, mock_model):%0A        %22%22%22Checks should only be run for active and stale domains.%22%22%22%0A        self.call_command()%0A        cutoff = timedelta(minutes=5)%0A        mock_model.objects.active.assert_called_with()%0A        mock_model.objects.active.return_value.stale.assert_called_with(%0A            cutoff=cutoff)%0A%0A    @patch('domainchecks.management.commands.checkdomains.DomainCheck')%0A    def test_specify_cutoff(self, mock_model):%0A        %22%22%22Minutes option changes the stale cutoff.%22%22%22%0A        self.call_command(minutes=60)%0A        cutoff = timedelta(minutes=60)%0A        mock_model.objects.active.return_value.stale.assert_called_with(%0A            cutoff=cutoff)%0A%0A    @patch('domainchecks.management.commands.checkdomains.DomainCheck')%0A    def test_check_run_check(self, mock_model):%0A        %22%22%22Checks should use the run_check model method.%22%22%22%0A        example = Mock()%0A        mock_model.objects.active.return_value.stale.return_value = %5Bexample, %5D%0A        self.call_command()%0A        example.run_check.assert_called_with(timeout=10)%0A%0A    @patch('domainchecks.management.commands.checkdomains.DomainCheck')%0A    def test_specity_timeout(self, mock_model):%0A        %22%22%22Timeout option changes the timeout for run_check.%22%22%22%0A        example = Mock()%0A        mock_model.objects.active.return_value.stale.return_value = %5Bexample, %5D%0A        self.call_command(timeout=1)%0A        example.run_check.assert_called_with(timeout=1)%0A%0A    def test_functional_defaults(self):%0A        %22%22%22Run command defaults with actual domain record.%22%22%22%0A        stale = factories.create_domain_check()%0A        # Still want to mock the remote call%0A        with patch('domainchecks.models.requests') as mock_requests:%0A            mock_requests.request.return_value = Mock(%0A                status_code=200, text='Ok')%0A            stdout, stderr = self.call_command()%0A            mock_requests.request.assert_called_once_with(%0A                stale.method, stale.url, allow_redirects=False, timeout=10)%0A        self.assertIn('1 domain status updated', stdout.getvalue())%0A

Add tests for the checkdomains command.