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

Fix formatting & comments in go/management

parent b67358dc
"""
go/commands/expirelinks.py
"""
Remove expired links from the database.
"""
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
......@@ -16,20 +17,15 @@ from go.models import URL
class Command(BaseCommand):
"""
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'
def handle(self, *args, **options):
"""
The handle function handles the main component of the django-admin
command.
Handle the main component of the django-admin command. Loop
through a list of all URL objects that have expired (expires field is
less than or equal [lte] to today's date)
"""
# Loop through a list of all URL objects that have expired
# (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()
for expired_url in URL.objects.filter(expires__lte=timezone.now()):
expired_url.delete()
"""
go/commands/test_expirelinks.py
"""
Test that the function to expire Go links actually works.
"""
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
......@@ -19,16 +20,11 @@ from django.utils import timezone
from go.models import URL, RegisteredUser
class ExpireLinksTest(TestCase):
"""
Test cases for the functions in expirelinks
"""
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
"""
# Setup a blank URL object with an owner
User.objects.create(username='dhaynes', password='password')
get_user = User.objects.get(username='dhaynes')
......@@ -52,9 +48,8 @@ class ExpireLinksTest(TestCase):
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')
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