Unit Test for all function in OpenVulnQueryClient
| 152 | @pytest.mark.skip(reason='Out of sync and requires / triggers token usage as' |
| 153 | ' well as api access') |
| 154 | class OpenVulnQueryClientTestCvrf(unittest.TestCase): |
| 155 | """Unit Test for all function in OpenVulnQueryClient""" |
| 156 | |
| 157 | def setUp(self): |
| 158 | self.open_vuln_client = query_client.OpenVulnQueryClient( |
| 159 | config.CLIENT_ID, |
| 160 | config.CLIENT_SECRET) |
| 161 | self.adv_format = "cvrf" |
| 162 | |
| 163 | @mock.patch("query_client.OpenVulnQueryClient.get_request", |
| 164 | side_effect=mocked_get_requests) |
| 165 | def test_get_by_cve(self, mock_get_requests): |
| 166 | """Checks if get_by_cve function calls request args with correct arguments""" |
| 167 | exp_args = "cvrf/cve/%s" % test_cve |
| 168 | response = self.open_vuln_client.get_by_cve(self.adv_format, test_cve) |
| 169 | mock_get_requests.assert_called_with(exp_args) |
| 170 | |
| 171 | @mock.patch("query_client.OpenVulnQueryClient.get_request", |
| 172 | side_effect=mocked_get_requests) |
| 173 | def test_get_by_advisory(self, mock_get_requests): |
| 174 | """Checks if get_by_advisory function calls request args with correct arguments""" |
| 175 | exp_args = "cvrf/advisory/%s" % test_advisory_id |
| 176 | response = self.open_vuln_client.get_by_advisory(self.adv_format, |
| 177 | test_advisory_id) |
| 178 | mock_get_requests.assert_called_with(exp_args) |
| 179 | |
| 180 | @mock.patch("query_client.OpenVulnQueryClient.get_request", |
| 181 | side_effect=mocked_get_requests) |
| 182 | def test_get_by_year(self, mock_get_requests): |
| 183 | """Checks if get_by_year function calls request args with correct arguments""" |
| 184 | exp_args = "cvrf/year/%s" % test_year |
| 185 | response = self.open_vuln_client.get_by_year(self.adv_format, |
| 186 | year=test_year) |
| 187 | mock_get_requests.assert_called_with(exp_args) |
| 188 | |
| 189 | @mock.patch("query_client.OpenVulnQueryClient.get_request", |
| 190 | side_effect=mocked_get_requests) |
| 191 | def test_get_by_severity(self, mock_get_requests): |
| 192 | """Checks if get_by_severity function calls request args with correct arguments""" |
| 193 | exp_args = "cvrf/severity/%s" % test_severity |
| 194 | response = self.open_vuln_client.get_by_severity(self.adv_format, |
| 195 | severity=test_severity) |
| 196 | mock_get_requests.assert_called_with(exp_args) |
| 197 | |
| 198 | @mock.patch("query_client.OpenVulnQueryClient.get_request", |
| 199 | side_effect=mocked_get_requests) |
| 200 | def test_get_by_all(self, mock_get_requests): |
| 201 | """Checks if get_by_all function calls request args with correct arguments""" |
| 202 | exp_args = "cvrf/all" |
| 203 | response = self.open_vuln_client.get_by_all(self.adv_format, "all") |
| 204 | mock_get_requests.assert_called_with(exp_args) |
| 205 | |
| 206 | @mock.patch("requests.get", side_effect=mocked_requests_lib_get) |
| 207 | def test_get_requests(self, mock_get): |
| 208 | """Checks if _get_requests function returns correct output""" |
| 209 | test_path = "cvrf/cve/%s" % test_cve |
| 210 | response = self.open_vuln_client.get_request(test_path) |
| 211 | self.assertDictEqual(json.loads(response_generic), response) |
nothing calls this directly
no outgoing calls
no test coverage detected