• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python importer_mocks.get_basic_config函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pulp_rpm.devel.importer_mocks.get_basic_config函数的典型用法代码示例。如果您正苦于以下问题:Python get_basic_config函数的具体用法?Python get_basic_config怎么用?Python get_basic_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_basic_config函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_invalid_config

 def test_invalid_config(self):
     config = importer_mocks.get_basic_config(**{importer_constants.KEY_MAX_SPEED: -1.0,
                                                 importer_constants.KEY_FEED: 'http://test.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, 'The configuration parameter <max_speed> must be set to a positive '
                                     'numerical value, but is currently set to <-1.0>.')
开发者ID:pombredanne,项目名称:rcm-pulp-rpm,代码行数:7,代码来源:test_iso_importer_configuration.py


示例2: test_download_succeeded_honors_validate_units_set_true

    def test_download_succeeded_honors_validate_units_set_true(self, download_failed):
        """
        We have a setting that makes download validation optional. This test ensures that
        download_succeeded()
        honors that setting.
        """
        # In this config, we will set validate_units to False, which should make our
        # "wrong_checksum" OK
        config = importer_mocks.get_basic_config(
            **{importer_constants.KEY_FEED: 'http://fake.com/iso_feed/',
               importer_constants.KEY_VALIDATE: True})

        iso_sync_run = ISOSyncRun(self.sync_conduit, config)

        destination = os.path.join(self.temp_dir, 'test.txt')
        with open(destination, 'w') as test_file:
            test_file.write('Boring test data.')
        unit = MagicMock()
        unit.storage_path = destination
        iso = models.ISO('test.txt', 114, 'wrong checksum', unit)
        iso.url = 'http://fake.com'
        report = DownloadReport(iso.url, destination, iso)

        # Let's fake having downloaded the whole file
        iso.bytes_downloaded = iso.size
        report.bytes_downloaded = iso.size
        iso_sync_run.progress_report._state = SyncProgressReport.STATE_ISOS_IN_PROGRESS

        iso_sync_run.download_succeeded(report)

        # Because we fail validation, the save_unit step will not be called
        self.assertEqual(self.sync_conduit.save_unit.call_count, 0)
        # The download should be marked failed
        self.assertEqual(download_failed.call_count, 1)
        download_failed.assert_called_once_with(report)
开发者ID:hjensas,项目名称:pulp_rpm,代码行数:35,代码来源:test_sync.py


示例3: test_validate

 def test_validate(self):
     config = importer_mocks.get_basic_config(
         **{importer_constants.KEY_MAX_SPEED: 1.0, importer_constants.KEY_FEED: "http://test.com"}
     )
     status, error_message = configuration.validate(config)
     self.assertTrue(status is True)
     self.assertEqual(error_message, None)
开发者ID:pcreech,项目名称:pulp_rpm,代码行数:7,代码来源:test_configuration.py


示例4: test_validate_str

 def test_validate_str(self):
     parameters = {importer_constants.KEY_PROXY_PORT: '3128', importer_constants.KEY_PROXY_HOST: 'http://test.com',
                   importer_constants.KEY_FEED: 'http://test.com'}
     config = importer_mocks.get_basic_config(**parameters)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is True)
     self.assertEqual(error_message, None)
开发者ID:pombredanne,项目名称:rcm-pulp-rpm,代码行数:7,代码来源:test_iso_importer_configuration.py


示例5: test_upload_unit_validate_unset

    def test_upload_unit_validate_unset(self, remove, validate):
        """
        Assert correct behavior from upload_unit() when the validation setting is not set. This
        should default to validating the upload.
        """
        # Set up the test
        file_data = "This is a file.\n"
        working_dir = os.path.join(self.temp_dir, "working")
        os.mkdir(working_dir)
        pkg_dir = os.path.join(self.temp_dir, "content")
        os.mkdir(pkg_dir)
        repo = mock.MagicMock(spec=Repository)
        repo.working_dir = working_dir
        # Set the checksum incorrect. The upload should be unsuccessful since the default is to
        # validate
        unit_key = {"name": "test.iso", "size": 16, "checksum": "Wrong"}
        metadata = {}
        temp_file_location = os.path.join(self.temp_dir, "test.iso")
        with open(temp_file_location, "w") as temp_file:
            temp_file.write(file_data)
        sync_conduit = importer_mocks.get_sync_conduit(pkg_dir=pkg_dir)
        # validate isn't set, so default should happen
        config = importer_mocks.get_basic_config()

        # Run the upload. This should report a failure
        report = self.iso_importer.upload_unit(
            repo, ids.TYPE_ID_ISO, unit_key, metadata, temp_file_location, sync_conduit, config
        )

        self.assertEqual(report["success_flag"], False)
        self.assertEqual(
            report["summary"],
            (
                "Downloading <test.iso> failed checksum validation. The manifest specified the "
                "checksum to be Wrong, but it was "
                "f02d5a72cd2d57fa802840a76b44c6c6920a8b8e6b90b20e26c03876275069e0."
            ),
        )

        # The conduit's init_unit method should have been called
        expected_rel_path = os.path.join(
            unit_key["name"], unit_key["checksum"], str(unit_key["size"]), unit_key["name"]
        )
        modified_metadata = metadata.copy()
        modified_metadata[server_constants.PULP_USER_METADATA_FIELDNAME] = {}
        sync_conduit.init_unit.assert_called_once_with(ids.TYPE_ID_ISO, unit_key, modified_metadata, expected_rel_path)

        # The file should have been moved to its final destination
        self.assertFalse(os.path.exists(temp_file_location))
        would_be_destination = os.path.join(pkg_dir, expected_rel_path)
        self.assertFalse(os.path.exists(would_be_destination))
        # The file should have been removed
        remove.assert_called_once_with(would_be_destination)

        # validate() should have been called with the full_validation=True flag
        iso = validate.mock_calls[0][1][0]
        validate.assert_called_once_with(iso, full_validation=True)

        # The conduit's save_unit method should have been called
        self.assertEqual(sync_conduit.save_unit.call_count, 0)
开发者ID:goosemania,项目名称:pulp_rpm,代码行数:60,代码来源:test_importer.py


示例6: test_validate

 def test_validate(self):
     config = importer_mocks.get_basic_config(
         **{importer_constants.KEY_PROXY_HOST: 'http://fake.com/',
            importer_constants.KEY_FEED: 'http://test.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is True)
     self.assertEqual(error_message, None)
开发者ID:AndreaGiardini,项目名称:pulp_rpm,代码行数:7,代码来源:test_configuration.py


示例7: test_required_when_other_parameters_are_present

 def test_required_when_other_parameters_are_present(self):
     for parameters in [
         {
             importer_constants.KEY_PROXY_PASS: "flock_of_seagulls",
             importer_constants.KEY_PROXY_USER: "big_kahuna_burger",
             importer_constants.KEY_FEED: "http://fake.com",
         },
         {importer_constants.KEY_PROXY_PORT: "3037", importer_constants.KEY_FEED: "http://fake.com"},
     ]:
         # Each of the above configurations should cause the validator to complain about the
         # proxy_url
         # missing
         config = importer_mocks.get_basic_config(**parameters)
         status, error_message = configuration.validate(config)
         self.assertTrue(status is False)
         expected_message = (
             "The configuration parameter <%(proxy_host)s> is required when any of the "
             "following "
             "other parameters are defined: %(proxy_pass)s, %(proxy_port)s, %(proxy_user)s."
         )
         expected_message = expected_message % {
             "proxy_pass": importer_constants.KEY_PROXY_PASS,
             "proxy_user": importer_constants.KEY_PROXY_USER,
             "proxy_port": importer_constants.KEY_PROXY_PORT,
             "proxy_host": importer_constants.KEY_PROXY_HOST,
         }
         self.assertEqual(error_message, expected_message)
开发者ID:pcreech,项目名称:pulp_rpm,代码行数:27,代码来源:test_configuration.py


示例8: test_client_key_requires_client_cert

 def test_client_key_requires_client_cert(self):
     config = importer_mocks.get_basic_config(**{importer_constants.KEY_SSL_CLIENT_KEY: 'Client Key!',
                                                 importer_constants.KEY_FEED: 'http://test.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, 'The configuration parameter <ssl_client_key> requires the '
                                     '<ssl_client_cert> parameter to also be set.')
开发者ID:pombredanne,项目名称:rcm-pulp-rpm,代码行数:7,代码来源:test_iso_importer_configuration.py


示例9: test_required_when_other_parameters_are_present

 def test_required_when_other_parameters_are_present(self):
     for parameters in [
         {importer_constants.KEY_MAX_SPEED: '1024'}, {importer_constants.KEY_MAX_DOWNLOADS: 2},
         {importer_constants.KEY_PROXY_PASS: 'flock_of_seagulls',
          importer_constants.KEY_PROXY_USER: 'big_kahuna_burger',
          importer_constants.KEY_PROXY_HOST: 'http://test.com'},
         {importer_constants.KEY_PROXY_HOST: 'http://test.com', importer_constants.KEY_PROXY_PORT: '3037'},
         {importer_constants.KEY_PROXY_HOST: 'http://test.com'},
         {importer_constants.KEY_UNITS_REMOVE_MISSING: True},
         {importer_constants.KEY_SSL_CA_CERT: 'cert'},
         {importer_constants.KEY_SSL_CLIENT_CERT: 'cert'},
         {importer_constants.KEY_SSL_CLIENT_CERT: 'cert', importer_constants.KEY_SSL_CLIENT_KEY: 'key'},
         {importer_constants.KEY_VALIDATE: True}]:
             # Each of the above configurations should cause the validator to complain about the feed_url
             # missing
             config = importer_mocks.get_basic_config(**parameters)
             status, error_message = configuration.validate(config)
             self.assertTrue(status is False)
             self.assertEqual(
                 error_message,
                 'The configuration parameter <%(feed)s> is required when any of the following other '
                 'parameters are defined: %(max_speed)s, %(num_threads)s, %(proxy_pass)s, %(proxy_port)s, '
                 '%(proxy_host)s, %(proxy_user)s, %(remove_missing_units)s, %(ssl_ca_cert)s, '
                 '%(ssl_client_cert)s, %(ssl_client_key)s, %(validate_units)s.' % {
                     'feed': importer_constants.KEY_FEED, 'max_speed': importer_constants.KEY_MAX_SPEED,
                     'num_threads': importer_constants.KEY_MAX_DOWNLOADS,
                     'proxy_pass': importer_constants.KEY_PROXY_PASS,
                     'proxy_port': importer_constants.KEY_PROXY_PORT,
                     'proxy_host': importer_constants.KEY_PROXY_HOST,
                     'proxy_user': importer_constants.KEY_PROXY_USER,
                     'remove_missing_units': importer_constants.KEY_UNITS_REMOVE_MISSING,
                     'ssl_ca_cert': importer_constants.KEY_SSL_CA_CERT,
                     'ssl_client_cert': importer_constants.KEY_SSL_CLIENT_CERT,
                     'ssl_client_key': importer_constants.KEY_SSL_CLIENT_KEY,
                     'validate_units': importer_constants.KEY_VALIDATE})
开发者ID:pombredanne,项目名称:rcm-pulp-rpm,代码行数:35,代码来源:test_iso_importer_configuration.py


示例10: test_valid_config

 def test_valid_config(self):
     config = importer_mocks.get_basic_config(
         **{importer_constants.KEY_UNITS_REMOVE_MISSING: True, importer_constants.KEY_FEED: "http://feed.com"}
     )
     status, error_message = configuration.validate(config)
     self.assertTrue(status is True)
     self.assertEqual(error_message, None)
开发者ID:pcreech,项目名称:pulp_rpm,代码行数:7,代码来源:test_configuration.py


示例11: test_client_cert_is_non_string

 def test_client_cert_is_non_string(self):
     config = importer_mocks.get_basic_config(**{importer_constants.KEY_SSL_CLIENT_CERT: 8,
                                                 importer_constants.KEY_FEED: 'http://test.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, "The configuration parameter <ssl_client_cert> should be a string, "
                                     "but it was <type 'int'>.")
开发者ID:pombredanne,项目名称:rcm-pulp-rpm,代码行数:7,代码来源:test_iso_importer_configuration.py


示例12: test_string_true

 def test_string_true(self):
     config = importer_mocks.get_basic_config(
         **{importer_constants.KEY_VALIDATE: "true", importer_constants.KEY_FEED: "http://feed.com"}
     )
     status, error_message = configuration.validate(config)
     self.assertTrue(status is True)
     self.assertEqual(error_message, None)
开发者ID:pcreech,项目名称:pulp_rpm,代码行数:7,代码来源:test_configuration.py


示例13: test_password_is_non_string

 def test_password_is_non_string(self):
     parameters = {importer_constants.KEY_PROXY_PASS: 7, importer_constants.KEY_PROXY_USER: "the_dude",
                   importer_constants.KEY_FEED: 'http://test.com'}
     config = importer_mocks.get_basic_config(**parameters)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, "The configuration parameter <proxy_password> should be a string, "
                                     "but it was <type 'int'>.")
开发者ID:pombredanne,项目名称:rcm-pulp-rpm,代码行数:8,代码来源:test_iso_importer_configuration.py


示例14: test_validate

 def test_validate(self):
     params = {importer_constants.KEY_PROXY_PASS: 'duderino', importer_constants.KEY_PROXY_USER: 'the_dude',
               importer_constants.KEY_PROXY_HOST: 'http://fake.com/',
               importer_constants.KEY_FEED: 'http://test.com'}
     config = importer_mocks.get_basic_config(**params)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is True)
     self.assertEqual(error_message, None)
开发者ID:pombredanne,项目名称:rcm-pulp-rpm,代码行数:8,代码来源:test_iso_importer_configuration.py


示例15: test_zero

 def test_zero(self):
     parameters = {importer_constants.KEY_PROXY_PORT: 0, importer_constants.KEY_PROXY_HOST: 'http://test.com',
                   importer_constants.KEY_FEED: 'http://test.com'}
     config = importer_mocks.get_basic_config(**parameters)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, 'The configuration parameter <proxy_port> must be set to a positive '
                                     'integer, but is currently set to <0>.')
开发者ID:pombredanne,项目名称:rcm-pulp-rpm,代码行数:8,代码来源:test_iso_importer_configuration.py


示例16: test_invalid_config

 def test_invalid_config(self):
     config = importer_mocks.get_basic_config(**{importer_constants.KEY_VALIDATE: 1,
                                                 importer_constants.KEY_FEED: 'http://feed.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     expected_message = ('The configuration parameter <%(validate)s> may only be set to a '
                         'boolean value, but is currently set to <1>.')
     expected_message = expected_message % {'validate': importer_constants.KEY_VALIDATE}
     self.assertEqual(error_message, expected_message)
开发者ID:AndreaGiardini,项目名称:pulp_rpm,代码行数:9,代码来源:test_configuration.py


示例17: test_validate_config

    def test_validate_config(self):
        """
        We already have a seperate test module for config validation, but we can get 100% test coverage with
        this!
        """
        config = importer_mocks.get_basic_config(
            **{importer_constants.KEY_FEED: "http://test.com/feed", importer_constants.KEY_MAX_SPEED: 128.8})
        # We'll pass None for the parameters that don't get used by validate_config
        status, error_message = self.iso_importer.validate_config(None, config)
        self.assertTrue(status)
        self.assertEqual(error_message, None)

        config = importer_mocks.get_basic_config(**{importer_constants.KEY_FEED: "http://test.com/feed",
                                                    importer_constants.KEY_MAX_SPEED: -42})
        status, error_message = self.iso_importer.validate_config(None, config)
        self.assertFalse(status)
        self.assertEqual(error_message, 'The configuration parameter <max_speed> must be set to a positive '
                                        'numerical value, but is currently set to <-42.0>.')
开发者ID:preethit,项目名称:pulp_rpm,代码行数:18,代码来源:test_iso_importer.py


示例18: test_sync_no_feed

    def test_sync_no_feed(self):
        repo = mock.MagicMock(spec=Repository)
        pkg_dir = os.path.join(self.temp_dir, "content")
        sync_conduit = importer_mocks.get_sync_conduit(pkg_dir=pkg_dir)
        config = {importer_constants.KEY_FEED: None}
        config = importer_mocks.get_basic_config(**config)

        # Now run the sync
        self.assertRaises(ValueError, self.iso_importer.sync_repo, repo, sync_conduit, config)
开发者ID:goosemania,项目名称:pulp_rpm,代码行数:9,代码来源:test_importer.py


示例19: test_url_is_non_string

 def test_url_is_non_string(self):
     config = importer_mocks.get_basic_config(**{importer_constants.KEY_PROXY_HOST: 7,
                                                 importer_constants.KEY_FEED: 'http://test.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     expected_message = ("The configuration parameter <%(proxy_host)s> should be a string, but it was "
                         "<type 'int'>.")
     expected_message = expected_message % {'proxy_host': importer_constants.KEY_PROXY_HOST}
     self.assertEqual(error_message, expected_message)
开发者ID:pombredanne,项目名称:rcm-pulp-rpm,代码行数:9,代码来源:test_iso_importer_configuration.py


示例20: test_upload_unit_validate_false

    def test_upload_unit_validate_false(self, validate):
        """
        Assert correct behavior from upload_unit() when the validation setting is False.
        """
        # Set up the test
        file_data = "This is a file.\n"
        working_dir = os.path.join(self.temp_dir, "working")
        os.mkdir(working_dir)
        pkg_dir = os.path.join(self.temp_dir, "content")
        os.mkdir(pkg_dir)
        repo = mock.MagicMock(spec=Repository)
        repo.working_dir = working_dir
        # Set the checksum incorrect. The upload should be successful no matter what since
        # validation will be set to False
        unit_key = {"name": "test.iso", "size": 16, "checksum": "Wrong"}
        metadata = {}
        temp_file_location = os.path.join(self.temp_dir, "test.iso")
        with open(temp_file_location, "w") as temp_file:
            temp_file.write(file_data)
        sync_conduit = importer_mocks.get_sync_conduit(pkg_dir=pkg_dir)
        config = importer_mocks.get_basic_config(**{importer_constants.KEY_VALIDATE: "false"})

        # Run the upload. This should be successful, since we have set validation off.
        report = self.iso_importer.upload_unit(
            repo, ids.TYPE_ID_ISO, unit_key, metadata, temp_file_location, sync_conduit, config
        )

        # The import should have been successful
        self.assertEqual(report["success_flag"], True)
        self.assertEqual(report["summary"], None)

        # The conduit's init_unit method should have been called
        expected_rel_path = os.path.join(
            unit_key["name"], unit_key["checksum"], str(unit_key["size"]), unit_key["name"]
        )
        modified_metadata = metadata.copy()
        modified_metadata[server_constants.PULP_USER_METADATA_FIELDNAME] = {}
        sync_conduit.init_unit.assert_called_once_with(ids.TYPE_ID_ISO, unit_key, modified_metadata, expected_rel_path)

        # The file should have been moved to its final destination
        self.assertFalse(os.path.exists(temp_file_location))
        expected_destination = os.path.join(pkg_dir, expected_rel_path)
        self.assertTrue(os.path.exists(expected_destination))
        with open(expected_destination) as iso_file:
            self.assertEqual(iso_file.read(), file_data)

        # validate() should still have been called, but with the full_validation=False flag
        # We need to get the ISO itself for our assertion, since it is technically the first
        # argument
        iso = validate.mock_calls[0][1][0]
        validate.assert_called_once_with(iso, full_validation=False)

        # The conduit's save_unit method should have been called
        self.assertEqual(sync_conduit.save_unit.call_count, 1)
        saved_unit = sync_conduit.save_unit.mock_calls[0][1][0]
        self.assertEqual(saved_unit.unit_key, unit_key)
开发者ID:goosemania,项目名称:pulp_rpm,代码行数:56,代码来源:test_importer.py



注:本文中的pulp_rpm.devel.importer_mocks.get_basic_config函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python repo_file.RepoFile类代码示例发布时间:2022-05-25
下一篇:
Python version_utils.encode函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap