Verified Commit 0cdcb7db authored by David Haynes's avatar David Haynes 🙆

Fix formatting & comments in go/management

parent b67358dc
""" """
go/commands/expirelinks.py go/commands/expirelinks.py
"""
Remove expired links from the database.
"""
# Future Imports # Future Imports
from __future__ import (absolute_import, division, print_function, from __future__ import (absolute_import, division, print_function,
unicode_literals) unicode_literals)
...@@ -16,20 +17,15 @@ from go.models import URL ...@@ -16,20 +17,15 @@ from go.models import URL
class Command(BaseCommand): class Command(BaseCommand):
""" """
Define a new custom django-admin command to remove expired links from the Define a new custom django-admin command to remove expired links from the
database database.
""" """
# Define help text for this command
help = 'Removes expired links from the database' help = 'Removes expired links from the database'
def handle(self, *args, **options): def handle(self, *args, **options):
""" """
The handle function handles the main component of the django-admin Handle the main component of the django-admin command. Loop
command. through a list of all URL objects that have expired (expires field is
less than or equal [lte] to today's date)
""" """
for expired_url in URL.objects.filter(expires__lte=timezone.now()):
# Loop through a list of all URL objects that have expired expired_url.delete()
# (expires field is less than or equal to today's date)
for toexpire in URL.objects.filter(expires__lte=timezone.now()):
# Delete the current URL
toexpire.delete()
""" """
go/commands/test_expirelinks.py go/commands/test_expirelinks.py
"""
Test that the function to expire Go links actually works.
"""
# Future Imports # Future Imports
from __future__ import (absolute_import, division, print_function, from __future__ import (absolute_import, division, print_function,
unicode_literals) unicode_literals)
...@@ -19,16 +20,11 @@ from django.utils import timezone ...@@ -19,16 +20,11 @@ from django.utils import timezone
from go.models import URL, RegisteredUser from go.models import URL, RegisteredUser
class ExpireLinksTest(TestCase): class ExpireLinksTest(TestCase):
"""
Test cases for the functions in expirelinks
"""
def setUp(self): def setUp(self):
""" """
Set up any variables such as dummy objects that will be utilised in Set up any variables such as dummy objects that will be utilized in
testing methods testing methods
""" """
# Setup a blank URL object with an owner # Setup a blank URL object with an owner
User.objects.create(username='dhaynes', password='password') User.objects.create(username='dhaynes', password='password')
get_user = User.objects.get(username='dhaynes') get_user = User.objects.get(username='dhaynes')
...@@ -52,9 +48,8 @@ class ExpireLinksTest(TestCase): ...@@ -52,9 +48,8 @@ class ExpireLinksTest(TestCase):
def test_expirelinks(self): def test_expirelinks(self):
""" """
Test that the expirelinks django admin command functions as intentioned. Make a call to expire Go links and assert that the number of links has
been reduced.
""" """
call_command('expirelinks') call_command('expirelinks')
self.assertTrue(len(URL.objects.all()) == 1) self.assertTrue(len(URL.objects.all()) == 1)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment