test_expirelinks.py 1.66 KB
Newer Older
David Haynes's avatar
David Haynes committed
1 2 3
"""
go/commands/test_expirelinks.py

4 5
Test that the function to expire Go links actually works.
"""
6 7 8
# Python stdlib Imports
from datetime import timedelta

9
# Django Imports
10 11
from django.contrib.auth.models import User
from django.core.management import call_command
David Haynes's avatar
David Haynes committed
12 13
from django.test import TestCase
from django.utils import timezone
14 15

# App Imports
David Haynes's avatar
David Haynes committed
16
from go_back.models import URL, RegisteredUser
17

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
# class ExpireLinksTest(TestCase):
#     def setUp(self):
#         """
#         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')
#         get_registered_user = RegisteredUser.objects.get(user=get_user)
#         URL.objects.create(owner=get_registered_user, short='test')
#         URL.objects.create(owner=get_registered_user, short='test-2')

#         # Get some dates
#         yesterday = timezone.now() - timedelta(days=1)
#         tomorrow = timezone.now() + timedelta(days=1)

#         # Get the URL to apply it to
#         current_url = URL.objects.get(short='test')
#         second_url = URL.objects.get(short='test-2')

#         # Apply the dates
#         current_url.expires = yesterday
#         second_url.expires = tomorrow
#         current_url.save()
#         second_url.save()

#     def test_expirelinks(self):
#         """
#         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) TODO