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 William Coughlin
GraceDB Server
Commits
ac36ea55
Commit
ac36ea55
authored
6 years ago
by
Tanner Prestegard
Committed by
GraceDB
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests for alerts
parent
cb51596d
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/alerts/tests/test_views.py
+66
-0
66 additions, 0 deletions
gracedb/alerts/tests/test_views.py
with
66 additions
and
0 deletions
gracedb/alerts/tests/test_views.py
0 → 100644
+
66
−
0
View file @
ac36ea55
import
mock
from
django.conf
import
settings
from
django.contrib.auth.models
import
Group
as
AuthGroup
from
django.urls
import
reverse
from
core.tests.utils
import
GraceDbTestBase
from
alerts.models
import
Contact
,
Notification
class
TestUpdateContactView
(
GraceDbTestBase
):
@classmethod
def
setUpTestData
(
cls
):
super
(
TestUpdateContactView
,
cls
).
setUpTestData
()
# Create email and phone contacts
cls
.
email_contact
=
Contact
.
objects
.
create
(
user
=
cls
.
internal_user
,
description
=
'
test email
'
,
email
=
'
test@test.com
'
)
cls
.
phone_contact
=
Contact
.
objects
.
create
(
user
=
cls
.
internal_user
,
description
=
'
test phone
'
,
phone
=
'
12345678901
'
,
phone_method
=
Contact
.
CONTACT_PHONE_BOTH
)
def
test_edit_email
(
self
):
"""
Users should not be able to update contact email
"""
# (because it sidesteps the verification process)
data
=
{
'
key_field
'
:
'
email
'
,
'
description
'
:
'
new description
'
,
'
email
'
:
'
new@new.com
'
,
}
original_email
=
self
.
email_contact
.
email
url
=
reverse
(
'
alerts:edit-contact
'
,
args
=
[
self
.
email_contact
.
pk
])
response
=
self
.
request_as_user
(
url
,
"
POST
"
,
self
.
internal_user
,
data
=
data
)
# Refresh from database
self
.
email_contact
.
refresh_from_db
()
# Check values - description should be updated, but email should not be
self
.
assertEqual
(
self
.
email_contact
.
description
,
data
[
'
description
'
])
self
.
assertNotEqual
(
self
.
email_contact
.
email
,
data
[
'
email
'
])
self
.
assertEqual
(
self
.
email_contact
.
email
,
original_email
)
def
test_edit_phone
(
self
):
"""
Users should not be able to update contact phone
"""
# (because it sidesteps the verification process)
data
=
{
'
key_field
'
:
'
phone
'
,
'
description
'
:
'
new description
'
,
'
phone
'
:
'
23456789012
'
,
}
original_phone
=
self
.
phone_contact
.
phone
url
=
reverse
(
'
alerts:edit-contact
'
,
args
=
[
self
.
phone_contact
.
pk
])
response
=
self
.
request_as_user
(
url
,
"
POST
"
,
self
.
internal_user
,
data
=
data
)
# Refresh from database
self
.
phone_contact
.
refresh_from_db
()
# Check values - description should be updated, but phone should not be
self
.
assertEqual
(
self
.
phone_contact
.
description
,
data
[
'
description
'
])
self
.
assertNotEqual
(
self
.
phone_contact
.
phone
,
data
[
'
phone
'
])
self
.
assertEqual
(
self
.
phone_contact
.
phone
,
original_phone
)
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