def test_poll_discovery_occurrence_fails(self):
     # try with no discovery occurrence
     try:
         samples.poll_discovery_finished(self.image_url, 5, PROJECT_ID)
     except RuntimeError:
         pass
     else:
         # we expect timeout error
         assert False
    def test_poll_discovery_occurrence(self):
        # create discovery occurrence
        note_id = 'discovery-note-{}'.format(uuid.uuid4())
        client = containeranalysis_v1.ContainerAnalysisClient()
        grafeas_client = client.get_grafeas_client()
        note = {'discovery': {'analysis_kind': NoteKind.DISCOVERY}}
        grafeas_client.\
            create_note(parent=f"projects/{PROJECT_ID}", note_id=note_id, note=note)
        occurrence = {
            'note_name': f"projects/{PROJECT_ID}/notes/{note_id}",
            'resource_uri': self.image_url,
            'discovery': {
                'analysis_status':
                DiscoveryOccurrence.AnalysisStatus.FINISHED_SUCCESS
            }
        }
        created = grafeas_client.\
            create_occurrence(parent=f"projects/{PROJECT_ID}",
                              occurrence=occurrence)

        disc = samples.poll_discovery_finished(self.image_url, 10, PROJECT_ID)
        status = disc.discovery.analysis_status
        assert disc is not None
        assert status == DiscoveryOccurrence.AnalysisStatus.FINISHED_SUCCESS

        # clean up
        samples.delete_occurrence(basename(created.name), PROJECT_ID)
        samples.delete_note(note_id, PROJECT_ID)
Exemplo n.º 3
0
    def test_poll_discovery_occurrence(self):
        # try with no discovery occurrence
        try:
            samples.poll_discovery_finished(self.image_url, 5, PROJECT_ID)
        except RuntimeError:
            pass
        else:
            # we expect timeout error
            assert False

        # create discovery occurrence
        note_id = 'discovery-note-{}'.format(uuid.uuid4())
        client = containeranalysis_v1.ContainerAnalysisClient()
        grafeas_client = client.get_grafeas_client()
        note = {
            'discovery': {
                'analysis_kind': NoteKind.DISCOVERY
            }
        }
        grafeas_client.\
            create_note(grafeas_client.project_path(PROJECT_ID), note_id, note)
        occurrence = {
            'note_name': grafeas_client.note_path(PROJECT_ID, note_id),
            'resource_uri': self.image_url,
            'discovery': {
                'analysis_status': DiscoveryOccurrence.AnalysisStatus
                                                      .FINISHED_SUCCESS
            }
        }
        created = grafeas_client.\
            create_occurrence(grafeas_client.project_path(PROJECT_ID),
                              occurrence)

        # poll again
        disc = samples.poll_discovery_finished(self.image_url, 10, PROJECT_ID)
        status = disc.discovery.analysis_status
        assert disc is not None
        assert status == DiscoveryOccurrence.AnalysisStatus.FINISHED_SUCCESS

        # clean up
        samples.delete_occurrence(basename(created.name), PROJECT_ID)
        samples.delete_note(note_id, PROJECT_ID)