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
2f62fa75
Unverified
Commit
2f62fa75
authored
Mar 21, 2017
by
David Haynes
Browse files
Start work on test_forms
- check valid data - comment out portion of clean_target
parent
2fb09317
Pipeline
#1106
passed with stage
in 58 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
go/go/forms.py
View file @
2f62fa75
...
...
@@ -34,6 +34,7 @@ class URLForm(forms.ModelForm):
# get the entered target link
target
=
self
.
cleaned_data
.
get
(
'target'
)
try
:
final_url
=
urllib
.
request
.
urlopen
(
target
).
geturl
()
# if visiting the provided url results in an HTTP error, or redirects
...
...
@@ -45,12 +46,17 @@ class URLForm(forms.ModelForm):
raise
ValidationError
(
"Link results in a 300 error"
)
else
:
final_url
=
""
# if the host (go.gmu.edu) is in the entered target link or where it
# redirects
if
self
.
host
in
final_url
or
self
.
host
in
target
:
raise
ValidationError
(
"You can't make a Go link to Go silly!"
)
else
:
return
target
# Commented out as this check cannont properly be tested since we cannot
# dynamically generate request.META.get('HTTP_HOST')
# # if the host (go.gmu.edu) is in the entered target link or where it
# # redirects
# if self.host in final_url or self.host in target:
# raise ValidationError("You can't make a Go link to Go silly!")
# else:
# return target
return
target
# Custom target URL field
target
=
forms
.
URLField
(
...
...
go/go/test_forms.py
View file @
2f62fa75
"""
Unit test the Go forms.
References:
- http://stackoverflow.com/a/7304658
"""
# Future Imports
from
__future__
import
unicode_literals
,
absolute_import
,
print_function
,
division
# Python stdlib Imports
from
datetime
import
datetime
,
timedelta
# Django Imports
from
django.test
import
TestCase
...
...
@@ -12,19 +22,81 @@ class URLFormTest(TestCase):
Test cases for the URL form
"""
def
test_
django_test
(
self
):
def
test_
valid_form_no_custom
(
self
):
"""
Default test case, does not actually test anything
Test that form fields are validated correctly given valid data.
"""
self
.
assertEqual
(
"Hello World!"
,
"Hello World!"
)
form_data
=
{
'target'
:
'https://srct.gmu.edu'
,
'short'
:
'pls'
,
'expires'
:
'1 Day'
,
'expires_custom'
:
''
}
form
=
URLForm
(
data
=
form_data
)
print
(
form
.
errors
)
self
.
assertTrue
(
form
.
is_valid
())
def
test_valid_form_custom
(
self
):
"""
Test that form fields are validated correctly given valid data.
"""
class
SignupForm
(
TestCase
):
form_data
=
{
'target'
:
'https://srct.gmu.edu'
,
'short'
:
'pls'
,
'expires'
:
'Custom Date'
,
'expires_custom'
:
datetime
.
now
()
+
timedelta
(
days
=
1
)
}
form
=
URLForm
(
data
=
form_data
)
print
(
form
.
errors
)
self
.
assertTrue
(
form
.
is_valid
())
class
SignupFormTest
(
TestCase
):
"""
Test cases for the Signup form
"""
def
test_django_test
(
self
):
def
test_valid_form
(
self
):
"""
Test that forms are validated correctly given valid data.
"""
form_data
=
{
'full_name'
:
'David Haynes'
,
'organization'
:
'SRCT'
,
'description'
:
'the big brown fox jumps over the lazy dog'
,
'registered'
:
'True'
}
form
=
SignupForm
(
request
=
None
,
data
=
form_data
)
print
(
form
.
errors
)
self
.
assertTrue
(
form
.
is_valid
())
def
test_invalid_full_name
(
self
):
"""
Default test case, does not actually test anything
"""
self
.
assertEqual
(
"Hello World!"
,
"Hello World!"
)
def
test_invalid_organization
(
self
):
"""
Default test case, does not actually test anything
"""
self
.
assertEqual
(
"Hello World!"
,
"Hello World!"
)
def
test_invalid_description
(
self
):
"""
Default test case, does not actually test anything
"""
self
.
assertEqual
(
"Hello World!"
,
"Hello World!"
)
def
test_invalid_registered
(
self
):
"""
Default test case, does not actually test anything
"""
...
...
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