コード例 #1
0
    def test_create_registry_ignoring_ssl(self):
        registry = Registry()

        registry.ignore_ssl()

        self.assertEqual(registry.ssl, False)
        self.assertEqual(registry.http_params['verify'], False)
コード例 #2
0
    def test_create_registry_with_ssl(self):
        registry = Registry()

        registry.set_ssl_certificate('/path/to/ssl/cert.crt')

        self.assertEqual(registry.ssl, '/path/to/ssl/cert.crt')
        self.assertEqual(registry.http_params['verify'],
                         '/path/to/ssl/cert.crt')
コード例 #3
0
    def test_get_url_with_https(self):
        registry = Registry()

        registry.set_credentials('username', 'password')

        url = registry.get_url('_catalog')

        self.assertEqual(url, 'https://localhost:5000/v2/_catalog')
コード例 #4
0
    def test_delete_tag(self, mock_obj):
        registry = Registry()

        registry.delete_tag('image', 'tag')
        self.assertIn(
            mock.call(
                registry.get_url('{0}/manifests/{1}'.format('image', 'tag')),
                **registry.http_params), mock_obj.call_args_list)
コード例 #5
0
    def test_get_tags(self, mock_obj):
        registry = Registry()

        tags = registry.get_tags('image')

        self.assertEqual(tags, ['latest', '1.0.0'])
        self.assertIn(
            mock.call(registry.get_url('image/tags/list'),
                      **registry.http_params), mock_obj.call_args_list)
コード例 #6
0
    def test_get_images_with_connection_error(self, mock_obj):
        registry = Registry()

        self.assertRaises(error.ConnectionError, registry.get_images)
        self.assertIn(
            mock.call(registry.get_url('_catalog'),
                      **registry.http_params,
                      params=registry.get_pagination(10, None)),
            mock_obj.call_args_list)
コード例 #7
0
    def test_create_registry_with_credentials(self):
        registry = Registry()

        registry.set_credentials('username', 'password')

        self.assertEqual(registry.username, 'username')
        self.assertEqual(registry.password, 'password')

        self.assertIn('auth', registry.http_params)
コード例 #8
0
    def test_validate_registry_url_in_browser(self):
        url = b'http://hostname:6000/v2'

        registry = Registry(host='hostname', port=6000)
        registry.get_images = MagicMock(return_value=({}, None))
        setattr(app, 'registry', registry)

        rv = self.app.get('/')

        self.assertIn(url, rv.data)
コード例 #9
0
    def test_get_inexistent_image(self, mock_obj):
        registry = Registry()

        self.assertRaises(error.NotFoundError, registry.get_images)

        self.assertIn(
            mock.call(registry.get_url('_catalog'),
                      **registry.http_params,
                      params=registry.get_pagination(10, None)),
            mock_obj.call_args_list)
コード例 #10
0
    def test_get_images(self, mock_obj):
        registry = Registry()

        images, link = registry.get_images()

        self.assertEqual(images, ['hello-world', 'postgres'])
        self.assertEqual(link, '?n=2&last=b')
        self.assertIn(
            mock.call(registry.get_url('_catalog'),
                      **registry.http_params,
                      params=registry.get_pagination(10, None)),
            mock_obj.call_args_list)
コード例 #11
0
    def test_get_manifests(self, mock_obj):
        registry = Registry()

        manifests_data = registry.get_manifests('image', 'tag')

        self.assertEqual(
            manifests_data, {
                'manifests': {},
                'digest':
                'sha256:9e81e4ce4899448e5e7aea69a72dfd1df989a7a0fe7365ad63be1133f05acf10'
            })
        self.assertIn(
            mock.call(
                registry.get_url('{0}/manifests/{1}'.format('image', 'tag')),
                **registry.http_params), mock_obj.call_args_list)
コード例 #12
0
    def test_validate_error_in_browser(self):
        url = b'http://hostname:6000/v2'

        registry = Registry(host='hostname', port=6000)
        setattr(app, 'registry', registry)

        rv = self.app.get('/')

        self.assertIn(b'Error', rv.data)
コード例 #13
0
    def test_get_image_name_from_link(self):
        link = '?last=httpd&n=1'
        image = Registry.get_image_from_link(link)

        self.assertEqual('httpd', image)
コード例 #14
0
    def test_create_minimal_configured_registry(self):
        registry = Registry()

        self.assertEqual(registry.host, 'localhost')
        self.assertEqual(registry.port, 5000)
コード例 #15
0
    def test_get_url_with_http(self):
        registry = Registry()

        url = registry.get_url('_catalog')

        self.assertEqual(url, 'http://localhost:5000/v2/_catalog')
コード例 #16
0
    def test_get_url_withouth_param(self):
        registry = Registry()

        url = registry.get_url()

        self.assertEqual(url, 'http://localhost:5000/v2')
コード例 #17
0
    def test_get_images_with_integrity_error(self, mock_obj):
        registry = Registry()

        self.assertRaises(error.IntegrityError, registry.get_images)
コード例 #18
0
    def test_http_params_contains_docker_v2_header(self):
        registry = Registry()

        self.assertEqual(
            registry.http_params['headers']['Accept'],
            'application/vnd.docker.distribution.manifest.v2+json')
コード例 #19
0
    def test_get_pagination(self):
        registry = Registry()

        pagination = registry.get_pagination(10, None)

        self.assertEqual({'n': 10}, pagination)
コード例 #20
0
    def test_get_pagination_with_last(self):
        registry = Registry()

        pagination = registry.get_pagination(10, '?last=httpd&n=1')

        self.assertEqual({'n': 10, 'last': 'httpd'}, pagination)
コード例 #21
0
    def test_get_images_bad_link(self, mock_obj):
        registry = Registry()

        self.assertRaises(error.IntegrityError, registry.get_images)
コード例 #22
0
    def test_get_data_or_throw_error(self):
        registry = Registry()

        response = requests.Response()
        self.assertRaises(error.NotFoundError,
                          registry.get_data_or_throw_error, response)