Пример #1
0
 def test_delete_tag(self, mock_delete):
     host = _DEFAULT_HOST
     client = RegistryClient(host=host, auth=ApiAuth(''))
     client.delete_tag('pack', 'tag1')
     mock_delete.assert_called_once_with(
         url=('https://artifactregistry.googleapis.com/v1/projects/'
              'proj/locations/us-central1/repositories'
              '/repo/packages/pack/tags/tag1'),
         data='',
         headers=None,
         auth=mock.ANY)
Пример #2
0
 def test_get_version(self, mock_get):
     host = _DEFAULT_HOST
     client = RegistryClient(host=host, auth=ApiAuth(''))
     client.get_version('pack', 'sha256:abcde12345')
     mock_get.assert_called_once_with(
         url=('https://artifactregistry.googleapis.com/v1/projects/'
              'proj/locations/us-central1/repositories'
              '/repo/packages/pack/versions/sha256:abcde12345'),
         data='',
         headers=None,
         auth=mock.ANY)
Пример #3
0
 def test_download_pipeline(self, mock_open, mock_get, version, tag,
                            file_name, expected_url, expected_file_name):
     mock_open.reset_mock()
     host = _DEFAULT_HOST
     client = RegistryClient(host=host, auth=ApiAuth(''))
     client.download_pipeline(package_name='pack',
                              version=version,
                              tag=tag,
                              file_name=file_name)
     mock_get.assert_called_once_with(url=expected_url,
                                      data='',
                                      headers=None,
                                      auth=mock.ANY)
     mock_open.assert_called_once_with(expected_file_name, 'wb')
Пример #4
0
 def test_list_tags_empty(self, mock_get):
     host = _DEFAULT_HOST
     mock_response = requests.Response()
     mock_response.status_code = 200
     mock_response._content = json.dumps({}).encode('utf-8')
     mock_get.return_value = mock_response
     client = RegistryClient(host=host, auth=ApiAuth(''))
     tags = client.list_tags('pack')
     self.assertEqual(tags, {})
     mock_get.assert_called_once_with(
         url=('https://artifactregistry.googleapis.com/v1/projects/'
              'proj/locations/us-central1/repositories'
              '/repo/packages/pack/tags'),
         data='',
         headers=None,
         auth=mock.ANY)
Пример #5
0
 def test_update_tag(self, mock_patch):
     host = _DEFAULT_HOST
     client = RegistryClient(host=host, auth=ApiAuth(''))
     client.update_tag('pack', 'sha256:abcde12345', 'tag1')
     expected_data = json.dumps({
         'name':
         '',
         'version': ('projects/proj/locations/us-central1/repositories'
                     '/repo/packages/pack/versions/sha256:abcde12345')
     })
     mock_patch.assert_called_once_with(
         url=('https://artifactregistry.googleapis.com/v1/projects/'
              'proj/locations/us-central1/repositories'
              '/repo/packages/pack/tags/tag1?updateMask=version'),
         data=expected_data,
         headers={
             'Content-type': 'application/json',
         },
         auth=mock.ANY)
Пример #6
0
 def test_upload_pipeline(self, mock_open, mock_post, tags, expected_tags):
     mock_open.reset_mock()
     mock_post.return_value.text = 'package_name/sha256:abcde12345'
     mock_open.return_value.__enter__.return_value = 'file_content'
     mock_open.return_value.__exit__.return_value = False
     host = _DEFAULT_HOST
     client = RegistryClient(host=host, auth=ApiAuth(''))
     package_name, version = client.upload_pipeline(
         file_name='pipeline.yaml',
         tags=tags,
         extra_headers={'description': 'nothing'})
     mock_post.assert_called_once_with(url=host,
                                       data={'tags': expected_tags},
                                       headers={'description': 'nothing'},
                                       files={'content': 'file_content'},
                                       auth=mock.ANY)
     mock_open.assert_called_once_with('pipeline.yaml', 'rb')
     self.assertEqual(package_name, 'package_name')
     self.assertEqual(version, 'sha256:abcde12345')
Пример #7
0
 def test_load_config(self):
     host = _DEFAULT_HOST
     client = RegistryClient(host=host, auth=ApiAuth(''))
     expected_config = {
         'host':
         host,
         'upload_url':
         host,
         'download_version_url':
         f'{host}/{{package_name}}/{{version}}',
         'download_tag_url':
         f'{host}/{{package_name}}/{{tag}}',
         'get_package_url':
         ('https://artifactregistry.googleapis.com/v1/projects/'
          'proj/locations/us-central1/repositories'
          '/repo/packages/{package_name}'),
         'list_packages_url':
         ('https://artifactregistry.googleapis.com/v1/projects/'
          'proj/locations/us-central1/repositories'
          '/repo/packages'),
         'delete_package_url':
         ('https://artifactregistry.googleapis.com/v1/projects/'
          'proj/locations/us-central1/repositories'
          '/repo/packages/{package_name}'),
         'get_tag_url':
         ('https://artifactregistry.googleapis.com/v1/projects/'
          'proj/locations/us-central1/repositories'
          '/repo/packages/{package_name}/tags/{tag}'),
         'list_tags_url':
         ('https://artifactregistry.googleapis.com/v1/projects/'
          'proj/locations/us-central1/repositories'
          '/repo/packages/{package_name}/tags'),
         'delete_tag_url':
         ('https://artifactregistry.googleapis.com/v1/projects/'
          'proj/locations/us-central1/repositories'
          '/repo/packages/{package_name}/tags/{tag}'),
         'create_tag_url':
         ('https://artifactregistry.googleapis.com/v1/projects/'
          'proj/locations/us-central1/repositories'
          '/repo/packages/{package_name}/tags?tagId={tag}'),
         'update_tag_url':
         ('https://artifactregistry.googleapis.com/v1/projects/'
          'proj/locations/us-central1/repositories'
          '/repo/packages/{package_name}/tags/{tag}?updateMask=version'),
         'get_version_url':
         ('https://artifactregistry.googleapis.com/v1/projects/'
          'proj/locations/us-central1/repositories'
          '/repo/packages/{package_name}/versions/{version}'),
         'list_versions_url':
         ('https://artifactregistry.googleapis.com/v1/projects/'
          'proj/locations/us-central1/repositories'
          '/repo/packages/{package_name}/versions'),
         'delete_version_url':
         ('https://artifactregistry.googleapis.com/v1/projects/'
          'proj/locations/us-central1/repositories'
          '/repo/packages/{package_name}/versions/{version}'),
         'package_format':
         ('projects/proj/locations/us-central1/repositories'
          '/repo/packages/{package_name}'),
         'tag_format': ('projects/proj/locations/us-central1/repositories'
                        '/repo/packages/{package_name}/tags/{tag}'),
         'version_format':
         ('projects/proj/locations/us-central1/repositories'
          '/repo/packages/{package_name}/versions/{version}')
     }
     self.assertEqual(expected_config, client._config)
Пример #8
0
 def test_is_ar_host(self, host, expected):
     client = RegistryClient(host=host, auth=ApiAuth(''))
     self.assertEqual(client._is_ar_host(), expected)
Пример #9
0
 def test_download_pipeline_tag_error(self):
     client = RegistryClient(host=_DEFAULT_HOST, auth=ApiAuth(''))
     with self.assertRaises(ValueError):
         client.download_pipeline(package_name='pack',
                                  tag='sha256:abcde12345')