Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
21
Issues
21
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SRCT
go
Commits
0cdcb7db
Verified
Commit
0cdcb7db
authored
Jan 13, 2018
by
David Haynes
🙆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix formatting & comments in go/management
parent
b67358dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
22 deletions
+13
-22
go/go/management/commands/expirelinks.py
go/go/management/commands/expirelinks.py
+8
-12
go/go/management/commands/test_expirelinks.py
go/go/management/commands/test_expirelinks.py
+5
-10
No files found.
go/go/management/commands/expirelinks.py
View file @
0cdcb7db
"""
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/go/management/commands/test_expirelinks.py
View file @
0cdcb7db
"""
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 utili
s
ed in
Set up any variables such as dummy objects that will be utili
z
ed 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
)
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