def test_sync_cve_md_positive(self, pg_db_conn, monkeypatch, caplog, cleanup): # pylint: disable=unused-argument """Test calling sync_cve_md with vmaas responding with data""" monkeypatch.setattr(vmaas_sync, 'paging', lambda endpoint, cve_request: (True, CVES_RESPONSE)) with caplog.at_level(logging.INFO): with DatabasePool(1): result = sync_cve_md() assert result self.check_sync_logs(caplog.records, 0) caplog.clear()
def test_sync_cve_md_negative(self, pg_db_conn, monkeypatch, caplog, cleanup): # pylint: disable=unused-argument """Test calling sync_cve_md with vmaas responding with nothing""" monkeypatch.setattr(vmaas_sync, 'paging', lambda endpoint, cve_request: (False, {})) with caplog.at_level(logging.INFO): with DatabasePool(1): result = sync_cve_md() assert not result assert caplog.records[0].msg == 'Syncing CVE metadata' caplog.clear()
def test_sync_cve_md_negative(self, pg_db_conn, monkeypatch, caplog, cleanup): # pylint: disable=unused-argument """Test calling sync_cve_md with vmaas responding with nothing""" monkeypatch.setattr('vmaas_sync.vmaas_sync.vmaas_post_request', lambda endpoint, cve_request, session: None) with caplog.at_level(logging.INFO): with DatabasePool(1): result = sync_cve_md(TestMqueueWriter()) assert not result assert caplog.records[0].msg == 'Syncing CVE metadata' assert caplog.records[1].msg.startswith('Downloading CVE metadata') assert caplog.records[2].msg == 'Finished syncing CVE metadata' caplog.clear()
def test_sync_cve_md_delete(self, pg_db_conn, monkeypatch, caplog, cleanup): # pylint: disable=unused-argument """Test calling sync_cve_md with vmaas responding with data""" cves = CVES_RESPONSE.copy() del cves['cve_list']['CVE-2017-3'] del cves['cve_list']['CVE-2018-1'] monkeypatch.setattr(vmaas_sync, 'paging', lambda endpoint, cve_request: (True, cves)) with caplog.at_level(logging.INFO): with DatabasePool(1): result = sync_cve_md() assert result assert caplog.records[2].msg.startswith('Deleting') assert caplog.records[3].msg == 'Finished deleting unnecessary CVE metadata' assert caplog.records[4].msg.startswith('Unable to delete') caplog.clear()