Ejemplo n.º 1
0
        def test_get_latest_commit_fails(self, mocker, integration,
                                         requests_mock, mock_results,
                                         mocked_status, expected):
            """
            Given:
                - A project with no successful commit in master in Iron Bank.
                - A project that does not exists in Iron Bank.
            When:
                Validating docker image of Iron Bank pack.
            Then:
                Validates we show the correct error.
            """
            api_url = 'https://repo1.dso.mil/api/v4/projects/dsop%2Fopensource%2Fpalo-alto-networks%2Ftest%2Ftest_project/pipelines'
            requests_mock.get(api_url,
                              status_code=mocked_status,
                              json=mock_results)

            DockerImageValidator.is_iron_bank = True
            docker_image_name = 'test/test_project:1.0.2'
            DockerImageValidator.yml_docker_image = docker_image_name
            DockerImageValidator.file_path = integration.yml.path

            with pytest.raises(Exception) as e:
                DockerImageValidator._get_latest_commit(
                    api_url, docker_image_name)

            assert str(e.value) == expected
Ejemplo n.º 2
0
        def test_get_latest_commit(self, integration, requests_mock):
            """
            Given:
                An example existing project with successful commits in master in Iron Bank.
            When:
                Validating docker image of Iron Bank pack.
            Then:
                Validates we extract correctly the commit id.
            """
            api_url = 'https://repo1.dso.mil/api/v4/projects/dsop%2Fopensource%2Fpalo-alto-networks%2Ftest%2Ftest_project/pipelines'
            requests_mock.get(
                api_url,
                json=[{
                    'id':
                    433333,
                    'project_id':
                    7070,
                    'sha':
                    'sha_1',
                    'ref':
                    'master',
                    'status':
                    'success',
                    'created_at':
                    '2021-08-19T09:18:35.547Z',
                    'updated_at':
                    '2021-08-19T09:38:21.743Z',
                    'web_url':
                    'https://repo1.dso.mil/dsop/opensource/palo-alto-networks/test/test_project/-/pipelines/433333'
                }, {
                    'id':
                    432507,
                    'project_id':
                    7070,
                    'sha':
                    'sha_2',
                    'ref':
                    'master',
                    'status':
                    'success',
                    'created_at':
                    '2021-08-18T22:19:19.843Z',
                    'updated_at':
                    '2021-08-18T22:40:29.950Z',
                    'web_url':
                    'https://repo1.dso.mil/dsop/opensource/palo-alto-networks/test/test_project/-/pipelines/432507'
                }])

            DockerImageValidator.file_path = integration.yml.path
            DockerImageValidator.is_iron_bank = True
            docker_image_name = 'test/test_project:1.0.2'
            DockerImageValidator.yml_docker_image = docker_image_name
            res = DockerImageValidator._get_latest_commit(
                api_url, docker_image_name)
            assert 'sha_1' == res