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
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
IGWN Computing and Software
GraceDB
GraceDB Server
Commits
9a5eff34
Commit
9a5eff34
authored
5 years ago
by
Tanner Prestegard
Committed by
GraceDB
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add some unit tests for alert signup views
parent
443ccd73
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gracedb/alerts/tests/test_access.py
+18
-2
18 additions, 2 deletions
gracedb/alerts/tests/test_access.py
gracedb/alerts/tests/test_views.py
+67
-0
67 additions, 0 deletions
gracedb/alerts/tests/test_views.py
with
85 additions
and
2 deletions
gracedb/alerts/tests/test_access.py
+
18
−
2
View file @
9a5eff34
...
...
@@ -142,12 +142,28 @@ class TestContactDeleteView(GraceDbTestBase):
class
TestNotificationCreateView
(
GraceDbTestBase
):
"""
Test user access to notification creation view
"""
def
test_internal_user_get
(
self
):
"""
Internal user can get notification creation view
"""
def
test_internal_user_get_with_verified_contact
(
self
):
"""
Internal user can get notification creation view if they have a
verified contact
"""
url
=
reverse
(
'
alerts:create-notification
'
)
self
.
internal_user
.
contact_set
.
create
(
phone
=
'
12345678901
'
,
phone_method
=
Contact
.
CONTACT_PHONE_TEXT
,
verified
=
True
,
description
=
'
test
'
)
response
=
self
.
request_as_user
(
url
,
"
GET
"
,
self
.
internal_user
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_internal_user_get_with_no_verified_contact
(
self
):
"""
Internal user can
'
t get notification creation view if they don
'
t have
a verified contact
"""
url
=
reverse
(
'
alerts:create-notification
'
)
response
=
self
.
request_as_user
(
url
,
"
GET
"
,
self
.
internal_user
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
response
.
url
,
reverse
(
'
alerts:index
'
))
def
test_lvem_user_get
(
self
):
"""
LV-EM user can
'
t get notification creation view
"""
url
=
reverse
(
'
alerts:create-notification
'
)
...
...
This diff is collapsed.
Click to expand it.
gracedb/alerts/tests/test_views.py
+
67
−
0
View file @
9a5eff34
import
mock
import
pytest
from
django.conf
import
settings
from
django.contrib.auth.models
import
Group
as
AuthGroup
...
...
@@ -77,3 +78,69 @@ class TestUpdateContactView(GraceDbTestBase):
self
.
assertNotEqual
(
self
.
phone_contact
.
phone
,
data
[
'
phone
'
])
self
.
assertEqual
(
self
.
phone_contact
.
phone
,
original_phone
)
self
.
assertEqual
(
self
.
phone_contact
.
phone_method
,
data
[
'
phone_method
'
])
@pytest.mark.parametrize
(
"
notif_exists
"
,
[
True
,
False
])
@pytest.mark.django_db
def
test_delete_contact
(
notif_exists
,
internal_user
,
client
):
client
.
force_login
(
internal_user
)
# Manually create verified contact for user
contact
=
internal_user
.
contact_set
.
create
(
phone
=
'
12345678901
'
,
verified
=
True
,
phone_method
=
Contact
.
CONTACT_PHONE_TEXT
,
description
=
'
test
'
)
# Optionally create a notification
if
notif_exists
:
notif
=
internal_user
.
notification_set
.
create
(
description
=
'
test
'
,
category
=
Notification
.
NOTIFICATION_CATEGORY_SUPEREVENT
)
notif
.
contacts
.
add
(
contact
)
# Try to delete contact
response
=
client
.
get
(
reverse
(
'
alerts:delete-contact
'
,
args
=
[
contact
.
pk
]))
# Assert results
if
notif_exists
:
# Redirect to main alerts page
assert
response
.
status_code
==
302
assert
response
.
url
==
reverse
(
'
alerts:index
'
)
# Message displayed by message framework
assert
"
cannot be deleted
"
in
response
.
cookies
[
'
messages
'
].
value
# Contact still exists
assert
Contact
.
objects
.
filter
(
pk
=
contact
.
pk
).
exists
()
else
:
# Redirect to main alerts page
assert
response
.
status_code
==
302
assert
response
.
url
==
reverse
(
'
alerts:index
'
)
# Contact does not exist
assert
not
Contact
.
objects
.
filter
(
pk
=
contact
.
pk
).
exists
()
@pytest.mark.django_db
def
test_create_notification_no_contact
(
internal_user
,
client
):
client
.
force_login
(
internal_user
)
# Manually create verified contact for user
contact
=
internal_user
.
contact_set
.
create
(
phone
=
'
12345678901
'
,
verified
=
True
,
phone_method
=
Contact
.
CONTACT_PHONE_TEXT
,
description
=
'
test
'
)
# Try to create a notification with no contact
url
=
reverse
(
'
alerts:create-notification
'
)
data
=
{
'
description
'
:
'
test
'
,
'
key_field
'
:
'
superevent
'
,
}
response
=
client
.
post
(
url
,
data
=
data
)
# This should call the forms_invalid() method of the CBV,
# resulting in a TemplateResponse to render the form with
# errors
# Get form
form
=
[
form
for
form
in
response
.
context
[
'
forms
'
]
if
form
.
key
==
'
superevent
'
][
0
]
# Check form status and errors
assert
form
.
is_bound
==
True
assert
form
.
is_valid
()
==
False
assert
'
contacts
'
in
form
.
errors
assert
form
.
errors
.
as_data
()[
'
contacts
'
][
0
].
code
==
'
required
'
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