MCPcopy Create free account
hub / github.com/CiscoPSIRT/openVulnQuery / QueryClientTest

Class QueryClientTest

tests/test_query_client.py:199–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197
198
199class QueryClientTest(unittest.TestCase):
200 def test_query_client_unchanged_adv_tokens(self):
201 self.assertEquals(query_client.ADV_TOKENS,
202 constants.ADVISORY_FORMAT_TOKENS)
203
204 def test_query_client_unchanged_temporal_filter_keys(self):
205 self.assertTrue(len(query_client.TEMPORAL_FILTER_KEYS) == 2)
206
207 def test_query_client_ensure_adv_format_token_succeeds(self):
208 self.assertTrue(query_client.ensure_adv_format_token(''))
209
210 def test_query_client_filter_succeeds(self):
211 self.assertTrue(query_client.Filter())
212
213 def test_query_client_temporal_filter_succeeds(self):
214 self.assertTrue(query_client.TemporalFilter('', *('',) * 2))
215
216 def test_query_client_first_published_succeeds(self):
217 self.assertTrue(query_client.FirstPublished(*('',) * 2))
218
219 def test_query_client_last_updated_succeeds(self):
220 self.assertTrue(query_client.LastUpdated(*('',) * 2))
221
222 @mock.patch('openVulnQuery.authorization.requests.post',
223 side_effect=mocked_req_post)
224 def test_client_smoke_init_succeeds_mocked(self, mock_post):
225 client = query_client.OpenVulnQueryClient(
226 CLIENT_ID, CLIENT_SECRET, REQUEST_TOKEN_URL, user_agent='foo')
227 self.assertIsInstance(client, query_client.OpenVulnQueryClient)
228 self.assertEqual(
229 client.auth_token, OAUTH2_RESPONSE_BOGUS_BUT_OK['access_token'])
230 self.assertEqual(
231 client.auth_url, REQUEST_TOKEN_URL)
232
233 @mock.patch('openVulnQuery.query_client.requests.get',
234 side_effect=mocked_req_get)
235 @mock.patch('openVulnQuery.authorization.requests.post',
236 side_effect=mocked_req_post)
237 def test_client_smoke_fails_non_topic_mocked(self, mock_post, mock_get):
238 client = query_client.OpenVulnQueryClient(
239 CLIENT_ID, CLIENT_SECRET, REQUEST_TOKEN_URL, user_agent='foo')
240 self.assertRaises(
241 KeyError,
242 client.get_by,
243 'let_this_topic_be_non_existing',
244 None,
245 None,
246 **{})
247
248 @mock.patch('openVulnQuery.query_client.requests.get',
249 side_effect=mocked_req_get)
250 @mock.patch('openVulnQuery.authorization.requests.post',
251 side_effect=mocked_req_post)
252 def test_client_cvrf_succeeds_advisory_mocked(self, mock_post, mock_get):
253 client = query_client.OpenVulnQueryClient(
254 CLIENT_ID, CLIENT_SECRET, REQUEST_TOKEN_URL, user_agent='foo')
255 advisories_as_cvrf = client.get_by(
256 'advisory',

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected