Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
Flask_User_Reg
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mitchell Moore
Flask_User_Reg
Commits
039d02d2
Commit
039d02d2
authored
5 years ago
by
Mitchell Moore
Browse files
Options
Downloads
Patches
Plain Diff
Added testing script to utilize 'testing' config.
parent
01bb4296
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!15
Added testing script to utilize 'testing' config.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests.py
+101
-0
101 additions, 0 deletions
tests.py
with
101 additions
and
0 deletions
tests.py
0 → 100644
+
101
−
0
View file @
039d02d2
# tests.py
import
unittest
import
flask
from
flask
import
abort
,
url_for
,
g
from
flask_testing
import
TestCase
from
app
import
create_app
class
TestBase
(
TestCase
):
def
create_app
(
self
):
app
=
create_app
(
'
testing
'
)
return
app
def
setUp
(
self
):
"""
Will be called before every test
"""
app
=
create_app
(
'
testing
'
)
return
app
def
tearDown
(
self
):
"""
Will be called after every test
"""
class
TestModels
(
TestBase
):
# TODO: make tests
pass
class
TestViews
(
TestBase
):
# TODO: make tests
def
test_index_view
(
self
):
"""
Test that homepage is accessible.
"""
response
=
self
.
client
.
get
(
url_for
(
'
index
'
))
self
.
assertEqual
(
response
.
status_code
,
200
)
# with self.app.test_client() as c:
# rv = c.get('/')
# assert flask.session['REMOTE_USER'] == 'bobby'
def
test_page_resources
(
self
):
"""
Test that all resources load are found.
"""
with
self
.
app
.
test_request_context
(
'
/?redir=test
'
):
assert
flask
.
request
.
path
==
'
/
'
c
=
flask
.
app
.
request
.
args
[
'
redir
'
]
assert
c
==
'
test
'
# def test_logout_view(self):
# """
# Test that logout link is inaccessible without login
# and redirects to login page then to logout
# """
# target_url = url_for('auth.logout')
# redirect_url = url_for('auth.login', next=target_url)
# response = self.client.get(target_url)
# self.assertEqual(response.status_code, 302)
# self.assertRedirects(response, redirect_url)\
class
TestErrorPages
(
TestBase
):
def
test_403_forbidden
(
self
):
# create route to abort the request with the 403 Error
@self.app.route
(
'
/403
'
)
def
forbidden_error
():
abort
(
403
)
response
=
self
.
client
.
get
(
'
/403
'
)
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertTrue
(
"
403 Error
"
in
response
.
data
)
def
test_404_not_found
(
self
):
response
=
self
.
client
.
get
(
'
/nothinghere
'
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertTrue
(
"
404 Error
"
in
response
.
data
)
def
test_500_internal_server_error
(
self
):
# create route to abort the request with the 500 Error
@self.app.route
(
'
/500
'
)
def
internal_server_error
():
abort
(
500
)
response
=
self
.
client
.
get
(
'
/500
'
)
self
.
assertEqual
(
response
.
status_code
,
500
)
self
.
assertTrue
(
"
500 Error
"
in
response
.
data
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment