Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
G
gracedb-client
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
4
Issues
4
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
3
Merge Requests
3
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lscsoft
gracedb-client
Commits
206d1540
Commit
206d1540
authored
Oct 13, 2020
by
Alexander Pace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exception fixes for ligo-gracedb-2.7.1
parent
b68da6ee
Pipeline
#162389
passed with stages
in 15 minutes and 52 seconds
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
105 additions
and
114 deletions
+105
-114
ligo-gracedb.spec
ligo-gracedb.spec
+2
-2
ligo/gracedb/cli/tests/test_main.py
ligo/gracedb/cli/tests/test_main.py
+7
-1
ligo/gracedb/client.py
ligo/gracedb/client.py
+2
-2
ligo/gracedb/exceptions.py
ligo/gracedb/exceptions.py
+12
-14
ligo/gracedb/legacy_cli.py
ligo/gracedb/legacy_cli.py
+0
-11
ligo/gracedb/rest.py
ligo/gracedb/rest.py
+1
-3
ligo/gracedb/test/integration/test_cli.py
ligo/gracedb/test/integration/test_cli.py
+38
-43
ligo/gracedb/test/integration/test_superevents.py
ligo/gracedb/test/integration/test_superevents.py
+13
-16
ligo/gracedb/test/integration/test_update_grbevent.py
ligo/gracedb/test/integration/test_update_grbevent.py
+18
-21
ligo/gracedb/utils.py
ligo/gracedb/utils.py
+11
-0
ligo/gracedb/version.py
ligo/gracedb/version.py
+1
-1
No files found.
ligo-gracedb.spec
View file @
206d1540
%define name ligo-gracedb
%define version 2.7.
0
%define unmangled_version 2.7.
0
%define version 2.7.
1
%define unmangled_version 2.7.
1
%define release 1
Summary: Gravity Wave Candidate Event Database
...
...
ligo/gracedb/cli/tests/test_main.py
View file @
206d1540
...
...
@@ -90,8 +90,14 @@ def test_main_with_bad_response(main_tester, capsys, response_msg):
code
=
status
,
reason
=
reason
)
# Define an error response object:
err_response
=
Response
()
err_response
.
status_code
=
400
err_response
.
reason
=
'Bad Request'
err_response
.
_content
=
b
'test'
EXCEPTION_DATA
=
[
Exception
(
'test'
),
HTTPError
(
400
,
'Bad Request'
,
'test'
)]
HTTPError
(
response
=
err_response
)]
@
pytest
.
mark
.
parametrize
(
"exc"
,
EXCEPTION_DATA
)
# noqa: E302
def
test_main_with_exception_in_CLI_call
(
main_tester
,
capsys
,
exc
):
...
...
ligo/gracedb/client.py
View file @
206d1540
...
...
@@ -26,7 +26,7 @@ from .extern.safe_netrc import netrc
from
os
import
getuid
from
.version
import
__version__
from
.adapter
import
GraceDbCertAdapter
from
.utils
import
hook_response
from
.utils
import
hook_response
,
raise_status_exception
# To remove later: python2 compatibility fix:
if
sys
.
version_info
[
0
]
>
2
:
...
...
@@ -119,7 +119,7 @@ class GraceDBClient(Session):
self
.
headers
.
update
(
self
.
_update_headers
())
# Adjust the response via a session hook:
self
.
hooks
=
{
'response'
:
hook_response
}
self
.
hooks
=
{
'response'
:
[
hook_response
,
raise_status_exception
]
}
if
reload_certificate
and
self
.
auth_type
==
'x509'
:
self
.
mount
(
'https://'
,
GraceDbCertAdapter
(
...
...
ligo/gracedb/exceptions.py
View file @
206d1540
# Custom exceptions
class
HTTPError
(
Exception
):
def
__init__
(
self
,
status_code
,
reason
,
text
):
self
.
status
=
status_code
self
.
status_code
=
status_code
self
.
reason
=
reason
self
.
message
=
text
self
.
text
=
text
Exception
.
__init__
(
self
,
status_code
,
reason
,
text
)
import
requests.exceptions
class
HTTPError
(
requests
.
exceptions
.
HTTPError
):
def
__init__
(
self
,
response
):
self
.
response
=
response
self
.
status_code
=
response
.
status_code
self
.
status
=
response
.
status_code
self
.
reason
=
response
.
reason
self
.
message
=
response
.
text
self
.
text
=
response
.
text
Exception
.
__init__
(
self
,
response
)
ligo/gracedb/legacy_cli.py
View file @
206d1540
...
...
@@ -281,17 +281,6 @@ Longer strings will be truncated.""" % {
# Compile dict of kwargs for instantiating the client class
client_args
=
{}
# Process proxy args
proxyport
=
None
if
proxy
and
proxy
.
find
(
':'
)
>
0
:
try
:
proxy
,
proxyport
=
proxy
.
split
(
':'
)
proxyport
=
int
(
proxyport
)
except
:
op
.
error
(
"Malformed proxy: '%s'"
%
proxy
)
client_args
[
'proxy_host'
]
=
proxy
client_args
[
'proxy_port'
]
=
proxyport
# Auth args
client_args
[
'force_noauth'
]
=
options
.
force_noauth
client_args
[
'username'
]
=
options
.
username
...
...
ligo/gracedb/rest.py
View file @
206d1540
...
...
@@ -184,9 +184,7 @@ class GraceDb(GraceDBClient):
raise
e
else
:
if
r
.
status_code
!=
200
:
raise
HTTPError
(
r
.
status_code
,
r
.
reason
,
r
.
text
)
raise
HTTPError
(
r
)
self
.
_service_info
=
r
.
json
()
return
self
.
_service_info
...
...
ligo/gracedb/test/integration/test_cli.py
View file @
206d1540
...
...
@@ -4,6 +4,7 @@ import pytest
import
shlex
from
ligo.gracedb.cli.client
import
CommandLineInterface
from
ligo.gracedb.exceptions
import
HTTPError
# Apply module-level marks
pytestmark
=
[
pytest
.
mark
.
cli
,
pytest
.
mark
.
integration
]
...
...
@@ -499,15 +500,16 @@ def test_update_grbevent():
cmd
=
(
'update grbevent {gid} --redshift={rs} --designation="{des}" '
'--ra={ra}'
).
format
(
gid
=
gid
,
rs
=
redshift
,
des
=
designation
,
ra
=
ra
)
response
=
run_CLI_test
(
cmd
)
new_data
=
response
.
json
()
try
:
response
=
run_CLI_test
(
cmd
)
new_data
=
response
.
json
()
# Even though they're test GRB events, unprivileged users
# can't update GRB events. So try to catch a 200 error
# in the case of an admin or grb user, and 403 otherwise.
# This came up with setting up the gitlab integration instance.
# Even though they're test GRB events, unprivileged users
# can't update GRB events. So try to catch a 200 status
# in the case of an admin or grb user, and 403 otherwise.
# This came up with setting up the gitlab integration instance.
if
response
.
status_code
==
200
:
assert
response
.
status_code
==
200
# Compare results
initial_grb_params
=
initial_data
[
'extra_attributes'
][
'GRB'
]
new_grb_params
=
new_data
[
'extra_attributes'
][
'GRB'
]
...
...
@@ -517,12 +519,8 @@ def test_update_grbevent():
assert
new_grb_params
[
'ra'
]
!=
initial_grb_params
[
'ra'
]
assert
new_grb_params
[
'redshift'
]
!=
initial_grb_params
[
'redshift'
]
elif
response
.
status_code
==
403
:
# Make sure the permissions error is returned:
assert
'You do not have permission'
in
new_data
.
get
(
'detail'
)
else
:
assert
response
.
status_code
<=
400
except
HTTPError
as
e
:
assert
e
.
status_code
==
403
def
test_confirm_as_gw
():
...
...
@@ -604,37 +602,35 @@ def test_permissions():
# Expose superevent
cmd
=
'expose {sid}'
.
format
(
sid
=
sid
)
response
=
run_CLI_test
(
cmd
)
out
=
response
.
json
()
try
:
response
=
run_CLI_test
(
cmd
)
out
=
response
.
json
()
# Check response-- this will be 200 for admins and
# em_advocates, or 403 for everyone else, like th
# gitlab runner.
if
response
.
status_code
==
200
:
# Check response-- this will be 200 for admins and
# em_advocates, or 403 for everyone else, like th
# gitlab runner.
assert
response
.
status_code
==
200
assert
isinstance
(
out
,
list
)
assert
len
(
out
)
==
3
elif
response
.
status_code
==
403
:
assert
"You are not allowed"
in
out
.
get
(
'detail'
)
else
:
assert
response
.
status_code
<=
400
except
HTTPError
as
e
:
assert
e
.
status_code
==
403
# Hide superevent
cmd
=
'hide {sid}'
.
format
(
sid
=
sid
)
response
=
run_CLI_test
(
cmd
)
out
=
response
.
json
()
try
:
response
=
run_CLI_test
(
cmd
)
out
=
response
.
json
()
# Check response-- same rules apply for exposing:
# Note that unauthorized users will get the 403 response
# at the permissions check even if the superevent is not
# exposed. So if the previous test 200'ed, then in theory
# this one will too if everything worked.
if
response
.
status_code
==
200
:
# Check response-- same rules apply for exposing:
# Note that unauthorized users will get the 403 response
# at the permissions check even if the superevent is not
# exposed. So if the previous test 200'ed, then in theory
# this one will too if everything worked.
assert
response
.
status_code
==
200
assert
isinstance
(
out
,
list
)
assert
len
(
out
)
==
0
elif
response
.
status_code
==
403
:
assert
"You are not allowed"
in
out
.
get
(
'detail'
)
else
:
assert
response
.
status_code
<=
400
except
HTTPError
as
e
:
assert
e
.
status_code
==
403
def
test_voevents
():
...
...
@@ -787,11 +783,12 @@ def test_signoffs():
# Create signoff ----------------------------------------------------------
cmd
=
'create signoff {sid} ADV OK "looks good"'
.
format
(
sid
=
sid
)
response
=
run_CLI_test
(
cmd
)
out
=
response
.
json
()
try
:
response
=
run_CLI_test
(
cmd
)
out
=
response
.
json
()
# Check response
if
response
.
status_code
==
201
:
# Check response
assert
response
.
status_code
==
201
assert
out
[
'status'
]
==
'OK'
assert
out
[
'comment'
]
==
'looks good'
assert
out
[
'instrument'
]
==
''
...
...
@@ -803,11 +800,9 @@ def test_signoffs():
# clever way of doing it.
authorized_user
=
True
e
lif
response
.
status_code
==
403
:
assert
'You do not have permission'
in
out
.
get
(
'detail'
)
e
xcept
HTTPError
as
e
:
assert
e
.
status_code
==
403
authorized_user
=
False
else
:
assert
response
.
status_code
<=
400
if
authorized_user
:
# Get signoff ------------------------------------------------------
...
...
ligo/gracedb/test/integration/test_superevents.py
View file @
206d1540
import
pytest
from
ligo.gracedb.exceptions
import
HTTPError
# Apply module-level mark
pytestmark
=
pytest
.
mark
.
integration
...
...
@@ -38,9 +39,8 @@ def test_creation_with_already_used_preferred_event(client, create_event):
# Try to create new superevent with an existing
# preferred event:
response
=
client
.
createSuperevent
(
1
,
2
,
3
,
event
,
category
=
'T'
)
assert
response
.
status_code
==
400
assert
response
.
reason
==
'Bad Request'
with
pytest
.
raises
(
HTTPError
):
response
=
client
.
createSuperevent
(
1
,
2
,
3
,
event
,
category
=
'T'
)
def
test_creation_with_events
(
client
,
create_event
):
...
...
@@ -163,18 +163,16 @@ def test_event_addition_and_removal(client, create_event, create_superevent):
assert
new_event
[
'graceid'
]
not
in
data
[
'gw_events'
]
# Try remove event again, should get error
response
=
client
.
removeEventFromSuperevent
(
superevent
[
'superevent_id'
],
new_event
[
'graceid'
]
)
assert
response
.
status_code
==
404
assert
response
.
reason
==
'Not Found'
with
pytest
.
raises
(
HTTPError
):
client
.
removeEventFromSuperevent
(
superevent
[
'superevent_id'
],
new_event
[
'graceid'
]
)
# Try remove preferred event, should get error
response
=
client
.
removeEventFromSuperevent
(
superevent
[
'superevent_id'
],
superevent
[
'preferred_event'
]
)
assert
response
.
status_code
==
400
assert
response
.
reason
==
'Bad Request'
with
pytest
.
raises
(
HTTPError
):
client
.
removeEventFromSuperevent
(
superevent
[
'superevent_id'
],
superevent
[
'preferred_event'
]
)
def
test_confirm_as_gw
(
client
,
create_superevent
):
...
...
@@ -194,9 +192,8 @@ def test_confirm_as_gw(client, create_superevent):
assert
gw_id
.
startswith
(
'TGW'
)
or
'GW'
in
gw_id
[:
3
]
# Try to update again
response
=
client
.
confirm_superevent_as_gw
(
superevent
[
'superevent_id'
])
assert
response
.
status_code
==
400
assert
response
.
reason
==
'Bad Request'
with
pytest
.
raises
(
HTTPError
):
client
.
confirm_superevent_as_gw
(
superevent
[
'superevent_id'
])
# Test getting data using both IDs
response
=
client
.
superevent
(
superevent
[
'superevent_id'
])
...
...
ligo/gracedb/test/integration/test_update_grbevent.py
View file @
206d1540
import
os
import
pytest
from
ligo.gracedb.exceptions
import
HTTPError
# Apply module-level marks
pytestmark
=
pytest
.
mark
.
integration
...
...
@@ -19,20 +19,21 @@ def test_update_grbevent(client, test_data_dir):
redshift
=
3.4
designation
=
'very good'
ra
=
12.34
response
=
client
.
update_grbevent
(
gid
,
redshift
=
redshift
,
designation
=
designation
,
ra
=
ra
)
new_data
=
response
.
json
()
# Even though they're test GRB events, unprivileged users
# can't update GRB events. So try to catch a 200 error
# in the case of an admin or grb user, and 403 otherwise.
# This came up with setting up the gitlab integration instance.
if
response
.
status_code
==
200
:
try
:
response
=
client
.
update_grbevent
(
gid
,
redshift
=
redshift
,
designation
=
designation
,
ra
=
ra
)
new_data
=
response
.
json
()
# Even though they're test GRB events, unprivileged users
# can't update GRB events. So try to catch a 200 error
# in the case of an admin or grb user, and 403 otherwise.
# This came up with setting up the gitlab integration instance.
assert
response
.
status_code
==
200
# Compare results
initial_grb_params
=
initial_data
[
'extra_attributes'
][
'GRB'
]
new_grb_params
=
new_data
[
'extra_attributes'
][
'GRB'
]
...
...
@@ -42,9 +43,5 @@ def test_update_grbevent(client, test_data_dir):
assert
new_grb_params
[
'ra'
]
!=
initial_grb_params
[
'ra'
]
assert
new_grb_params
[
'redshift'
]
!=
initial_grb_params
[
'redshift'
]
elif
response
.
status_code
==
403
:
# Make sure the permissions error is returned:
assert
'You do not have permission'
in
new_data
.
get
(
'detail'
)
else
:
assert
response
.
status_code
<=
400
except
HTTPError
as
e
:
assert
e
.
status_code
==
403
ligo/gracedb/utils.py
View file @
206d1540
import
re
import
six
import
mimetypes
import
requests
from
functools
import
wraps
from
.exceptions
import
HTTPError
EVENT_PREFIXES
=
[
'G'
,
'E'
,
'H'
,
'M'
,
'T'
]
event_prefix_regex
=
re
.
compile
(
r
'^({prefixes})\d+'
.
format
(
...
...
@@ -65,3 +67,12 @@ def get_mimetype(file_to_send):
# https://requests.readthedocs.io/en/master/user/advanced/#event-hooks
def
hook_response
(
r
,
*
args
,
**
kwargs
):
r
.
status
=
r
.
status_code
# Another hook: return the raise_for_status behavior which was previously
# enabled in the adjustResponse function.
def
raise_status_exception
(
r
,
*
args
,
**
kwargs
):
try
:
r
.
raise_for_status
()
except
requests
.
HTTPError
as
e
:
raise
HTTPError
(
response
=
e
.
response
)
ligo/gracedb/version.py
View file @
206d1540
__version__
=
'2.7.
0
'
__version__
=
'2.7.
1
'
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