Example #1
0
    def test_process_distributor_serve_protocol_new_values(self):
        # Setup
        distributor_config = {'http': True, 'https': False}
        command = repo_create_update.PkgRepoCreateCommand(self.context)

        # Test
        command.process_distributor_serve_protocol(distributor_config)

        # Verify
        self.assertEqual(distributor_config['http'], True)
        self.assertEqual(distributor_config['https'], False)
Example #2
0
    def test_process_yum_distributor_serve_protocol_defaults(self):
        # Setup
        distributor_config = {}  # will be populated in this call
        command = repo_create_update.PkgRepoCreateCommand(self.context)

        # Test
        command.process_distributor_serve_protocol(distributor_config)

        # Verify
        self.assertEqual(distributor_config['http'], False)
        self.assertEqual(distributor_config['https'], True)
Example #3
0
    def test_process_relative_url_specified(self):
        # Setup
        repo_id = 'specified'
        importer_config = {}
        distributor_config = {'relative_url': 'wombat'}
        command = repo_create_update.PkgRepoCreateCommand(self.context)

        # Test
        command.process_relative_url(repo_id, importer_config,
                                     distributor_config)

        # Verify
        self.assertTrue('relative_url' in distributor_config)
        self.assertEqual(distributor_config['relative_url'], 'wombat')
Example #4
0
    def test_process_relative_url_no_feed(self):
        # Setup
        repo_id = 'no-feed-repo'
        importer_config = {}
        distributor_config = {}  # will be populated in this call
        command = repo_create_update.PkgRepoCreateCommand(self.context)

        # Test
        command.process_relative_url(repo_id, importer_config,
                                     distributor_config)

        # Verify
        self.assertTrue('relative_url' in distributor_config)
        self.assertEqual(distributor_config['relative_url'], repo_id)
Example #5
0
    def test_process_relative_url_with_feed(self):
        # Setup
        repo_id = 'feed-repo'
        importer_config = {constants.KEY_FEED: 'http://localhost/foo/bar/baz'}
        distributor_config = {}  # will be populated in this call
        command = repo_create_update.PkgRepoCreateCommand(self.context)

        # Test
        command.process_relative_url(repo_id, importer_config,
                                     distributor_config)

        # Verify
        self.assertTrue('relative_url' in distributor_config)
        self.assertEqual(distributor_config['relative_url'], '/foo/bar/baz')
Example #6
0
    def test_create_structure(self):
        command = repo_create_update.PkgRepoCreateCommand(self.context)

        self.assertTrue(isinstance(command, ImporterConfigMixin))

        # Ensure the required option groups
        found_group_names = set([o.name for o in command.option_groups])
        self.assertTrue(repo_options.NAME_PUBLISHING in found_group_names)

        # Ensure the correct method is wired up
        self.assertEqual(command.method, command.run)

        # Ensure the correct metadata
        self.assertEqual(command.name, 'create')
        self.assertEqual(command.description, cudl.DESC_CREATE)
Example #7
0
    def test_run_through_cli(self):
        # Setup
        self.server_mock.request.return_value = 201, {}

        # Test
        command = repo_create_update.PkgRepoCreateCommand(self.context)
        self.cli.add_command(command)
        cmd = ["create", "--repo-id", "r", "--validate", "true"]
        self.cli.run(cmd)

        # Verify
        self.assertEqual(1, self.server_mock.request.call_count)

        body = self.server_mock.request.call_args[0][2]
        body = json.loads(body)

        self.assertEqual(body['id'], 'r')
        self.assertEqual(body['importer_config'][constants.KEY_VALIDATE],
                         True)  # not the string "true"
        dconfig = body['distributors'][0]['distributor_config']
        self.assertEquals(dict(http=False, https=True, relative_url='r'),
                          dconfig)
Example #8
0
    def test_run(self):
        # Setup

        data = {
            options.OPTION_REPO_ID.keyword: 'test-repo',
            options.OPTION_NAME.keyword: 'Test Name',
            options.OPTION_DESCRIPTION.keyword: 'Test Description',
            options.OPTION_NOTES.keyword: {
                'a': 'a'
            },
            self.options_bundle.opt_feed.keyword: 'http://localhost',
            self.options_bundle.opt_validate.keyword: True,
            self.options_bundle.opt_remove_missing.keyword: True,
            repo_options.OPT_SKIP.keyword: [ids.TYPE_ID_DEB],
            repo_options.OPT_RELATIVE_URL.keyword: '/repo',
            repo_options.OPT_SERVE_HTTP.keyword: True,
            repo_options.OPT_SERVE_HTTPS.keyword: True,
        }

        self.server_mock.request.return_value = 201, {}

        # Test
        command = repo_create_update.PkgRepoCreateCommand(self.context)
        command.run(**data)

        # Verify
        self.assertEqual(1, self.server_mock.request.call_count)

        body = self.server_mock.request.call_args[0][2]
        body = json.loads(body)

        self.assertEqual(body['display_name'], 'Test Name')
        self.assertEqual(body['description'], 'Test Description')
        self.assertEqual(body['notes'], {'_repo-type': 'deb-repo', 'a': 'a'})

        self.assertEqual(ids.TYPE_ID_IMPORTER, body['importer_type_id'])
        importer_config = body['importer_config']
        self.assertEqual(importer_config[constants.KEY_FEED],
                         'http://localhost')
        self.assertEqual(importer_config[repo_create_update.CONFIG_KEY_SKIP],
                         [ids.TYPE_ID_DEB])
        self.assertEqual(importer_config[constants.KEY_UNITS_REMOVE_MISSING],
                         True)

        # The API will be changing to be a dict for each distributor, not a
        # list. This code will have to change to look up the parts by key
        # instead of index.

        yum_distributor = body['distributors'][0]
        self.assertEqual(ids.TYPE_ID_DISTRIBUTOR,
                         yum_distributor['distributor_type_id'])
        self.assertEqual(True, yum_distributor['auto_publish'])
        self.assertEqual(ids.TYPE_ID_DISTRIBUTOR,
                         yum_distributor['distributor_id'])

        yum_config = yum_distributor['distributor_config']
        self.assertEqual(yum_config['relative_url'], '/repo')
        self.assertEqual(yum_config['http'], True)
        self.assertEqual(yum_config['https'], True)
        self.assertEqual(yum_config['skip'], [ids.TYPE_ID_DEB])

        self.assertEqual([TAG_SUCCESS], self.prompt.get_write_tags())