Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
go
Commits
0cdcb7db
Verified
Commit
0cdcb7db
authored
Jan 13, 2018
by
David Haynes
🙆
Browse files
Fix formatting & comments in go/management
parent
b67358dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
go/go/management/commands/expirelinks.py
View file @
0cdcb7db
"""
"""
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/go/management/commands/test_expirelinks.py
View file @
0cdcb7db
"""
"""
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 utili
s
ed in
Set up any variables such as dummy objects that will be utili
z
ed 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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment