Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GraceDB Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Michael Coughlin
GraceDB Server
Commits
6e20bf48
Commit
6e20bf48
authored
6 years ago
by
Tanner Prestegard
Committed by
GraceDB
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests for user info view
parent
c6851936
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gracedb/api/v1/main/tests/test_views.py
+50
-0
50 additions, 0 deletions
gracedb/api/v1/main/tests/test_views.py
with
50 additions
and
0 deletions
gracedb/api/v1/main/tests/test_views.py
0 → 100644
+
50
−
0
View file @
6e20bf48
from
__future__
import
absolute_import
from
django.conf
import
settings
from
django.urls
import
reverse
from
api.tests.utils
import
GraceDbApiTestBase
from
...settings
import
API_VERSION
def
v_reverse
(
viewname
,
*
args
,
**
kwargs
):
"""
Easily customizable versioned API reverse for testing
"""
viewname
=
'
api:{version}:
'
.
format
(
version
=
API_VERSION
)
+
viewname
return
reverse
(
viewname
,
*
args
,
**
kwargs
)
class
TestUserInfoView
(
GraceDbApiTestBase
):
def
test_internal_user
(
self
):
"""
Internal user sees correct information
"""
url
=
v_reverse
(
'
user-info
'
)
response
=
self
.
request_as_user
(
url
,
"
GET
"
,
self
.
internal_user
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# Test information
self
.
assertEqual
(
response
.
data
[
'
is_internal_user
'
],
True
)
for
attr
in
[
'
username
'
,
'
first_name
'
,
'
last_name
'
,
'
email
'
]:
self
.
assertEqual
(
response
.
data
.
get
(
attr
),
getattr
(
self
.
internal_user
,
attr
))
def
test_lvem_user
(
self
):
"""
LV-EM user sees correct information
"""
url
=
v_reverse
(
'
user-info
'
)
response
=
self
.
request_as_user
(
url
,
"
GET
"
,
self
.
lvem_user
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# Test information
self
.
assertEqual
(
response
.
data
[
'
is_internal_user
'
],
False
)
for
attr
in
[
'
username
'
,
'
first_name
'
,
'
last_name
'
,
'
email
'
]:
self
.
assertEqual
(
response
.
data
.
get
(
attr
),
getattr
(
self
.
lvem_user
,
attr
))
def
test_public_user
(
self
):
"""
Public user sees correct information
"""
url
=
v_reverse
(
'
user-info
'
)
response
=
self
.
request_as_user
(
url
,
"
GET
"
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# Test information
self
.
assertEqual
(
response
.
data
.
keys
(),
[
'
username
'
])
self
.
assertEqual
(
response
.
data
[
'
username
'
],
'
AnonymousUser
'
)
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