Skip to content

Commit 852067b

Browse files
authored
Merge pull request #39 from mbengit/master
Fix ariel delete/cancel issues
2 parents 1680072 + 774aec5 commit 852067b

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

qpylib/ariel.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,21 @@ def delete(self, search_id, api_version='latest'):
112112
''' Deletes a previous Ariel search.
113113
search_id: Ariel search ID
114114
api_version: QRadar API version to use, defaults to latest.
115-
Returns a tuple containing search status and search ID.
115+
Returns search status.
116116
Raises ArielError if the search could not be deleted.
117117
'''
118118
response = qpylib.REST('DELETE', ArielSearch.SEARCH_ENDPOINT.format(search_id),
119119
headers=self._build_headers(api_version))
120-
if response.status_code != 200:
120+
if response.status_code != 202:
121121
raise ArielError('Ariel search {0} could not be deleted: HTTP {1} was returned'
122122
.format(search_id, response.status_code))
123-
response_json = response.json()
124-
return (response_json['status'], response_json['search_id'])
123+
return response.json()['status']
125124

126125
def cancel(self, search_id, api_version='latest'):
127126
''' Cancels an ongoing Ariel search.
128127
search_id: Ariel search ID.
129128
api_version: QRadar API version to use, defaults to latest.
130-
Returns a tuple containing search status and search ID.
129+
Returns search status.
131130
Raises ArielError if the search could not be cancelled.
132131
'''
133132
response = qpylib.REST('POST', ArielSearch.SEARCH_ENDPOINT.format(search_id),
@@ -136,8 +135,7 @@ def cancel(self, search_id, api_version='latest'):
136135
if response.status_code != 200:
137136
raise ArielError('Ariel search {0} could not be cancelled: HTTP {1} was returned'
138137
.format(search_id, response.status_code))
139-
response_json = response.json()
140-
return (response_json['status'], response_json['search_id'])
138+
return response.json()['status']
141139

142140
@staticmethod
143141
def _build_headers(api_version):

test/test_ariel.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,34 +158,26 @@ def test_results_range_start_and_end():
158158

159159
@responses.activate
160160
def test_search_delete_failure():
161-
responses.add('DELETE', DELETE_SEARCH, status=404,
162-
json={})
163-
with pytest.raises(ArielError, match='Ariel search {0} could not be deleted'
161+
responses.add('DELETE', DELETE_SEARCH, status=500)
162+
with pytest.raises(ArielError,
163+
match='Ariel search {0} could not be deleted: HTTP 500 was returned'
164164
.format(SEARCH_ID)):
165165
ArielSearch().delete(SEARCH_ID)
166166

167167
@responses.activate
168168
def test_search_delete_success():
169-
responses.add('DELETE', DELETE_SEARCH, status=200,
170-
json={'status': 'COMPLETED', 'search_id': SEARCH_ID})
171-
status, search_id = ArielSearch().delete(SEARCH_ID)
172-
173-
assert status == 'COMPLETED'
174-
assert search_id == SEARCH_ID
169+
responses.add('DELETE', DELETE_SEARCH, status=202, json={'status': 'COMPLETED'})
170+
assert ArielSearch().delete(SEARCH_ID) == 'COMPLETED'
175171

176172
@responses.activate
177173
def test_search_cancel_failure():
178-
responses.add('POST', CANCEL_SEARCH, status=404,
179-
json={})
180-
with pytest.raises(ArielError, match='Ariel search {0} could not be cancelled'
174+
responses.add('POST', CANCEL_SEARCH, status=500)
175+
with pytest.raises(ArielError,
176+
match='Ariel search {0} could not be cancelled: HTTP 500 was returned'
181177
.format(SEARCH_ID)):
182178
ArielSearch().cancel(SEARCH_ID)
183179

184180
@responses.activate
185181
def test_search_cancel_success():
186-
responses.add('POST', CANCEL_SEARCH, status=200,
187-
json={'status': 'COMPLETED', 'search_id': SEARCH_ID})
188-
status, search_id = ArielSearch().cancel(SEARCH_ID)
189-
190-
assert status == 'COMPLETED'
191-
assert search_id == SEARCH_ID
182+
responses.add('POST', CANCEL_SEARCH, status=200, json={'status': 'COMPLETED'})
183+
assert ArielSearch().cancel(SEARCH_ID) == 'COMPLETED'

0 commit comments

Comments
 (0)