示例#1
0
    def test_positive_update_description(self):
        """Update content views description to valid one.

        :id: f5e46a3b-c317-4575-9c66-ef1da1926f66

        :expectedresults: Content view is updated successfully and has proper
            description

        :CaseImportance: Critical
        """
        name = gen_string('alpha', 8)
        desc = gen_string('alpha', 15)
        with Session(self) as session:
            make_contentview(
                session,
                org=self.organization.name,
                name=name,
                description=desc,
            )
            self.assertIsNotNone(self.content_views.search(name))
            for new_desc in valid_data_list():
                with self.subTest(new_desc):
                    self.content_views.update(name, new_description=new_desc)
                    self.content_views.search_and_click(name)
                    self.content_views.click(
                        tab_locators['contentviews.tab_details'])
                    self.assertEqual(
                        self.content_views.wait_until_element(
                            locators['contentviews.fetch_description']).text,
                        new_desc
                    )
    def test_positive_delete_by_name(self):
        """Test: Create new content view filter and assign it to existing
        content view by id. Try to delete that filter using different value
        types as a name

        @Feature: Content View Filter

        @Assert: Content view filter deleted successfully

        """
        for name in valid_data_list():
            with self.subTest(name):
                ContentView.filter_create({
                    'content-view-id': self.content_view['id'],
                    'name': name,
                    'type': 'rpm',
                })
                ContentView.filter_info({
                    u'content-view-id': self.content_view['id'],
                    u'name': name,
                })
                ContentView.filter_delete({
                    u'content-view-id': self.content_view['id'],
                    u'name': name,
                })
                with self.assertRaises(CLIReturnCodeError):
                    ContentView.filter_info({
                        u'content-view-id': self.content_view['id'],
                        u'name': name,
                    })
    def test_positive_update_description(self):
        """Create lifecycle environment then update its description

        @Feature: Lifecycle Environment

        @Assert: Lifecycle environment description is updated

        """
        new_lce = make_lifecycle_environment({
            'organization-id': self.org['id'],
        })
        for new_desc in valid_data_list():
            with self.subTest(new_desc):
                LifecycleEnvironment.update({
                    'description': new_desc,
                    'id': new_lce['id'],
                    'organization-id': self.org['id'],
                    'prior': new_lce['prior-lifecycle-environment'],
                })
                result = LifecycleEnvironment.info({
                    'id': new_lce['id'],
                    'organization-id': self.org['id'],
                })
                self.assertGreater(len(result), 0)
                self.assertEqual(result['description'], new_desc)
示例#4
0
    def test_positive_delete(self):
        """Create OpenScap content and then delete it.

        :id: 8eade129-5666-4e90-ba3e-f0c51a3090ce

        :Steps:

            1. Create an openscap content.
            2. Provide all the appropriate parameters.
            3. Delete the openscap content.

        :expectedresults: Deleting content for OpenScap is successful.

        :CaseImportance: Critical
        """
        with Session(self) as session:
            for content_name in valid_data_list():
                with self.subTest(content_name):
                    make_oscapcontent(
                        session,
                        name=content_name,
                        content_path=self.content_path,
                        content_org=self.org_name,
                    )
                    self.assertIsNotNone(
                        self.oscapcontent.search(content_name))
                    self.oscapcontent.delete(
                        content_name, dropdown_present=True)
    def test_positive_update_name(self):
        """Test: Create new content view filter and assign it to existing
        content view by id. Try to update that filter using different value
        types as a name

        @Feature: Content View Filter

        @Assert: Content view filter updated successfully and has proper and
        expected name

        """
        cvf_name = gen_string('utf8')
        ContentView.filter_create({
            'content-view-id': self.content_view['id'],
            'name': cvf_name,
            'type': 'rpm',
        })
        for new_name in valid_data_list():
            with self.subTest(new_name):
                ContentView.filter_update({
                    'content-view-id': self.content_view['id'],
                    'name': cvf_name,
                    'new-name': new_name,
                })
                cvf = ContentView.filter_info({
                    u'content-view-id': self.content_view['id'],
                    u'name': new_name,
                })
                self.assertEqual(cvf['name'], new_name)
                cvf_name = new_name  # updating cvf name for next iteration
    def test_positive_create_with_name_by_cv_id(self):
        """Test: Create new content view filter and assign it to existing
        content view by id. Use different value types as a name and random
        filter content type as a parameter for this filter

        @Feature: Content View Filter

        @Assert: Content view filter created successfully and has correct and
        expected parameters

        """
        for name in valid_data_list():
            with self.subTest(name):
                filter_content_type = gen_choice([
                    'rpm',
                    'package_group',
                    'erratum',
                ])
                ContentView.filter_create({
                    'content-view-id': self.content_view['id'],
                    'name': name,
                    'type': filter_content_type,
                })
                cvf = ContentView.filter_info({
                    u'content-view-id': self.content_view['id'],
                    u'name': name,
                })
                self.assertEqual(cvf['name'], name)
                self.assertEqual(cvf['type'], filter_content_type)
示例#7
0
    def test_positive_create(self):
        """Create OpenScap content.

        :id: 6580cffa-da37-40d5-affa-cfb1ff27c545

        :Steps:

            1. Create an openscap content.
            2. Provide all the appropriate parameters.

        :expectedresults: Whether creating  content for OpenScap is successful.

        :CaseImportance: Critical
        """
        with Session(self) as session:
            for content_name in valid_data_list():
                with self.subTest(content_name):
                    make_oscapcontent(
                        session,
                        name=content_name,
                        content_path=self.content_path,
                        content_org=self.org_name,
                    )
                    self.assertIsNotNone(
                        self.oscapcontent.search(content_name))
示例#8
0
    def test_positive_create_scap_content_with_valid_originalfile_name(self):
        """Create scap-content with valid original file name

        :id: 25441174-11cb-4d9b-9ec5-b1c69411b5bc

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Scap data stream ".xml" file.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "create" as sub-command.
            3. Pass valid parameters.

        :expectedresults: The scap-content is created.

        :CaseImportance: Critical
        """
        for name in valid_data_list():
            with self.subTest(name):
                scap_content = make_scapcontent({
                    'original-filename': name,
                    'scap-file': '/tmp/{0}'.format(self.file_name)})
                self.assertEqual(scap_content['original-filename'], name)
示例#9
0
    def test_positive_create_scap_content_with_valid_title(self):
        """Create scap-content with valid title

        :id: 68e9fbe2-e3c3-48e7-a774-f1260a3b7f4f

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Scap data stream ".xml" file.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "create" as sub-command.
            3. Pass valid parameters.

        :expectedresults: The scap-content is created successfully.

        :BZ: 1471801

        :CaseImportance: Critical
        """
        for title in valid_data_list():
            with self.subTest(title):
                scap_content = make_scapcontent({
                    'title': title,
                    'scap-file': '/tmp/{0}'.format(self.file_name)})
                self.assertEqual(scap_content['title'], title)
示例#10
0
    def test_positive_create_with_cv(self):
        """Create Activation key for all variations of Content Views

        @id: 2ad000f1-6c80-46aa-a61b-9ea62cefe91b

        @Assert: Activation key is created

        @CaseLevel: Integration
        """
        with Session(self.browser) as session:
            for cv_name in valid_data_list():
                with self.subTest(cv_name):
                    name = gen_string('alpha')
                    env_name = gen_string('alpha')
                    # Helper function to create and promote CV to next env
                    repo_id = self.create_sync_custom_repo()
                    self.cv_publish_promote(cv_name, env_name, repo_id)
                    make_activationkey(
                        session,
                        org=self.organization.name,
                        name=name,
                        env=env_name,
                        content_view=cv_name,
                    )
                    self.assertIsNotNone(self.activationkey.search(name))
示例#11
0
    def test_positive_delete(self):
        """@test: Create gpg key with valid name and valid gpg key via file
        import then delete it

        @feature: GPG Keys

        @assert: gpg key is deleted
        """
        for name in valid_data_list():
            with self.subTest(name):
                gpg_key = make_gpg_key({
                    'name': name,
                    'organization-id': self.org['id'],
                })
                result = GPGKey.exists(
                    {'organization-id': self.org['id']},
                    (self.search_key, gpg_key[self.search_key])
                )
                self.assertEqual(
                    gpg_key[self.search_key],
                    result[self.search_key]
                )
                GPGKey.delete({
                    'name': name,
                    'organization-id': self.org['id'],
                })
                result = GPGKey.exists(
                    {'organization-id': self.org['id']},
                    (self.search_key, gpg_key[self.search_key])
                )
                self.assertEqual(len(result), 0)
示例#12
0
    def test_postive_create_scap_policy_with_valid_name(self):
        """Create scap policy with valid name

        :id: c9327675-62b2-4e22-933a-02818ef68c11

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "create" as sub-command.
            3. Pass valid parameters and valid name.

        :expectedresults: The policy is created successfully.
        """
        for name in valid_data_list():
            with self.subTest(name):
                scap_policy = make_scap_policy({
                    'name': name,
                    'scap-content-id': self.scap_id_rhel6,
                    'scap-content-profile-id': self.scap_profile_id_rhel6,
                    'period': OSCAP_PERIOD['weekly'].lower(),
                    'weekday': OSCAP_WEEKDAY['friday'].lower()
                })
                self.assertEqual(scap_policy['name'], name)
示例#13
0
    def test_positive_update_description(self):
        """Update Description in an Activation key

        :id: 24988466-af1d-4dcd-80b7-9c7d317fb805

        :expectedresults: Activation key is updated

        :CaseImportance: Critical
        """
        name = gen_string('alpha')
        description = gen_string('alpha')
        with Session(self) as session:
            make_activationkey(
                session,
                org=self.organization.name,
                name=name,
                env=ENVIRONMENT,
                description=description,
            )
            self.assertIsNotNone(self.activationkey.search(name))
            for new_desc in valid_data_list():
                with self.subTest(new_desc):
                    self.activationkey.update(name, description=new_desc)
                    selected_desc = self.activationkey.get_attribute(
                        name, locators['ak.fetch_description'])
                    self.assertEqual(selected_desc, new_desc)
示例#14
0
    def test_positive_create_with_envs(self):
        """Create Activation key for all variations of Environments

        @id: f75e994a-6da1-40a3-9685-f8387388b3f0

        @Assert: Activation key is created

        @CaseLevel: Integration
        """
        with Session(self.browser) as session:
            for env_name in valid_data_list():
                with self.subTest(env_name):
                    name = gen_string('alpha')
                    cv_name = gen_string('alpha')
                    # Helper function to create and sync custom repository
                    repo_id = self.create_sync_custom_repo()
                    # Helper function to create and promote CV to next env
                    self.cv_publish_promote(cv_name, env_name, repo_id)
                    make_activationkey(
                        session,
                        org=self.organization.name,
                        name=name,
                        env=env_name,
                        content_view=cv_name,
                    )
                    self.assertIsNotNone(self.activationkey.search(name))
示例#15
0
    def test_positive_update_description(self):
        """Create new puppet-class and update its description to a valid
        one

        @id: 711fe4de-b62f-48b5-9845-2d8725eb3548

        @Assert: Puppet-Classes is updated successfully.
        """
        class_name = 'foreman_scap_client'
        param_name = 'ca file'
        with Session(self.browser):
            for description in valid_data_list():
                with self.subTest(description):
                    # Importing puppet classes from puppet-foreman_scap_client
                    # module for update process
                    if self.puppetclasses.search(class_name) is None:
                        self.puppetclasses.import_scap_client_puppet_classes()
                    self.assertIsNotNone(self.puppetclasses.search(class_name))
                    self.puppetclasses.update_class_parameter_description(
                        class_name, param_name, description)
                    self.assertEqual(
                        description,
                        self.puppetclasses.fetch_class_parameter_description(
                            class_name, param_name)
                    )
示例#16
0
    def test_positive_create_with_custom_org(self):
        """@test: Create gpg key with valid name and valid gpg key via file
        import using a new organization

        @feature: GPG Keys

        @assert: gpg key is created

        @BZ: 1172009
        """
        for name in valid_data_list():
            with self.subTest(name):
                gpg_key = make_gpg_key({
                    'key': VALID_GPG_KEY_FILE_PATH,
                    'name': name,
                    'organization-id': self.org['id'],
                })
                # Can we find the new object?
                result = GPGKey.exists(
                    {'organization-id': self.org['id']},
                    (self.search_key, gpg_key[self.search_key])
                )
                self.assertEqual(
                    gpg_key[self.search_key],
                    result[self.search_key]
                )
示例#17
0
    def test_positive_update_parameter_by_host_id(self):
        """Update existing host parameter by specifying host ID.

        @id: 56c43ab4-7fb0-44f5-9d54-107d3c1011bf

        @Assert: Host parameter was successfully updated with new value.

        """
        name = gen_string('alphanumeric').lower()
        old_value = gen_string('alphanumeric')
        Host.set_parameter({
            'host-id': self.host['id'],
            'name': name,
            'value': old_value,
        })
        for new_value in valid_data_list():
            with self.subTest(new_value):
                Host.set_parameter({
                    'host-id': self.host['id'],
                    'name': name,
                    'value': new_value,
                })
                self.host = Host.info({'id': self.host['id']})
                self.assertIn(name, self.host['parameters'].keys())
                self.assertEqual(new_value, self.host['parameters'][name])
示例#18
0
    def test_positive_add_template_by_name(self):
        """Add a provisioning template to organization by its name

        @id: bd46a192-488f-4da0-bf47-1f370ae5f55c

        @Assert: Template is added to the org

        @CaseLevel: Integration
        """
        for name in valid_data_list():
            with self.subTest(name):
                org = make_org()
                template = make_template({
                    'content': gen_string('alpha'),
                    'name': name,
                })
                Org.add_config_template({
                    'config-template': template['name'],
                    'name': org['name'],
                })
                org = Org.info({'name': org['name']})
                self.assertIn(
                    u'{0} ({1})'. format(template['name'], template['type']),
                    org['templates']
                )
示例#19
0
    def test_positive_update_name(self):
        """Create an external docker registry and update its name

        :id: 2b59f929-4a47-4216-b8b3-7f923d8e7de9

        :expectedresults: the external registry is updated with the new name

        :CaseImportance: Critical
        """
        with Session(self) as session:
            name = gen_string('utf8')
            make_registry(
                session,
                name=name,
                url=self.url,
                description=gen_string('utf8'),
            )
            try:
                registry_entity = entities.Registry(name=name).search()[0]
                self.assertIsNotNone(self.registry.search(name))
                for new_name in valid_data_list():
                    with self.subTest(new_name):
                        self.registry.update(name, new_name=new_name)
                        self.assertIsNotNone(self.registry.search(new_name))
                        name = new_name
            finally:
                registry_entity.delete()
示例#20
0
    def test_negative_create_same_name(self):
        """Create organization with valid values, then create a new one with
        same values

        @id: 07924e1f-1eff-4bae-b0db-e41b84966bc1

        @assert: organization is not created
        """
        for desc, name, label in zip(
                valid_data_list(),
                valid_org_names_list(),
                cycle(valid_labels_list()),
        ):
            with self.subTest(desc + name + label):
                Org.create({
                    'description': desc,
                    'label': label,
                    'name': name,
                })
                with self.assertRaises(CLIReturnCodeError):
                    Org.create({
                        'description': desc,
                        'label': label,
                        'name': name,
                    })
示例#21
0
    def test_positive_create_internal(self):
        """Create a Docker-based Compute Resource in the Satellite 6
        instance.

        :id: 78a65ed3-0dbf-413f-91cf-3a02f7ee12d1

        :expectedresults: Compute Resource can be created and listed.

        :CaseImportance: Critical
        """
        with Session(self) as session:
            for comp_name in valid_data_list():
                with self.subTest(comp_name):
                    make_resource(
                        session,
                        name=comp_name,
                        provider_type=FOREMAN_PROVIDERS['docker'],
                        parameter_list=[[
                            'URL',
                            settings.docker.get_unix_socket_url(),
                            'field'
                        ]],
                    )
                    self.assertIsNotNone(
                        self.compute_resource.search(comp_name))
示例#22
0
    def test_positive_create_external(self):
        """Create a Docker-based Compute Resource using an external
        Docker-enabled system.

        :id: 73ca3ee1-4353-4399-90ba-56560407246e

        :expectedresults: Compute Resource can be created and listed.

        :CaseImportance: Critical
        """
        with Session(self) as session:
            for comp_name in valid_data_list():
                with self.subTest(comp_name):
                    make_resource(
                        session,
                        name=comp_name,
                        provider_type=FOREMAN_PROVIDERS['docker'],
                        parameter_list=[[
                            'URL',
                            settings.docker.external_url,
                            'field'
                        ]],
                    )
                    self.assertIsNotNone(
                        self.compute_resource.search(comp_name))
示例#23
0
    def test_positive_create_with_policy_name(self):
        """Create OpenScap Policy.

        @id: cdf2bc8c-ce60-4d49-b4e9-9acbf1192bc2

        @Steps:

        1. Create an openscap content.
        2. Create an openscap Policy.
        3. Provide all the appropriate parameters.

        @Assert: Whether creating  Policy for OpenScap is successful.
        """
        content_name = gen_string('alpha')
        with Session(self.browser) as session:
            make_oscapcontent(
                session,
                name=content_name,
                content_path=self.content_path,
            )
            self.assertIsNotNone(
                self.oscapcontent.search(content_name))
            for policy_name in valid_data_list():
                with self.subTest(policy_name):
                    make_oscappolicy(
                        session,
                        content=content_name,
                        name=policy_name,
                        period=OSCAP_PERIOD['weekly'],
                        profile=OSCAP_PROFILE['c2s_rhel6'],
                        period_value=OSCAP_WEEKDAY['friday'],
                    )
                    self.assertIsNotNone(
                        self.oscappolicy.search(policy_name))
示例#24
0
    def test_positive_update_host_collection(self):
        """Test that host collection can be associated to Activation
        Keys

        @Feature: Activation key - Host

        @BZ: 1110476

        @Assert: Hosts are successfully associated to Activation key
        """
        for host_col_name in valid_data_list():
            with self.subTest(host_col_name):
                activation_key = self._make_activation_key()
                new_host_col_name = make_host_collection({"name": host_col_name})["name"]
                # Assert that name matches data passed
                self.assertEqual(new_host_col_name, host_col_name)
                ActivationKey.add_host_collection(
                    {
                        u"host-collection": new_host_col_name,
                        u"name": activation_key["name"],
                        u"organization-id": self.org["id"],
                    }
                )
                activation_key = ActivationKey.info({u"id": activation_key["id"]})
                self.assertEqual(activation_key["host-collection"], host_col_name)
    def test_positive_create(self):
        """Create new Tailoring Files using different values types as name

        :id: d6ae6b33-5af3-4b55-8ad4-6fa8e67e40f5

        :setup: Oscap enabled on capsule and scap tailoring file

        :steps:

            1. Navigate to Tailoring files menu
            2. Upload a valid tailoring file
            3. Give it a valid name

        :expectedresults: Tailoring file will be added to satellite

        :CaseImportance: Critical
        """
        with Session(self) as session:
            for tailoring_file_name in valid_data_list():
                with self.subTest(tailoring_file_name):
                    make_oscap_tailoringfile(
                        session,
                        name=tailoring_file_name,
                        tailoring_path=self.tailoring_path,
                        tailoring_loc=self.loc_name,
                        tailoring_org=self.org_name,
                    )
                    self.assertIsNotNone(
                        self.oscaptailoringfile.search(tailoring_file_name),
                        msg="Tailoring file name element not found")
示例#26
0
    def test_return_type(self):
        """This test validates return types for functions:

        1. :meth:`robottelo.datafactory.generate_strings_list`
        2. :meth:`robottelo.datafactory.invalid_emails_list`
        3. :meth:`robottelo.datafactory.invalid_names_list`
        4. :meth:`robottelo.datafactory.valid_data_list`
        5. :meth:`robottelo.datafactory.valid_emails_list`
        6. :meth:`robottelo.datafactory.valid_environments_list`
        7. :meth:`robottelo.datafactory.valid_labels_list`
        8. :meth:`robottelo.datafactory.valid_names_list`
        9. :meth:`robottelo.datafactory.valid_usernames_list`
        10. :meth:`robottelo.datafactory.invalid_id_list`

        """
        for item in itertools.chain(
                generate_strings_list(),
                invalid_emails_list(),
                invalid_names_list(),
                valid_data_list(),
                valid_emails_list(),
                valid_environments_list(),
                valid_labels_list(),
                valid_names_list(),
                valid_usernames_list(),):
            self.assertIsInstance(item, six.text_type)
        for item in invalid_id_list():
            if not (isinstance(item, (six.text_type, int)) or item is None):
                self.fail('Unexpected data type')
    def test_positive_update_description(self):
        """Update existing Host Collection entity description

        @id: 5ef92657-489f-46a2-9b3a-e40322ca86d8

        @Assert: Host Collection is updated
        """
        name = gen_string('alpha')
        with Session(self.browser) as session:
            make_host_collection(
                session,
                name=name,
                org=self.organization.name,
                description=gen_string('alpha'),
            )
            self.assertIsNotNone(self.hostcollection.search(name))
            for new_desc in valid_data_list():
                with self.subTest(new_desc):
                    self.hostcollection.update(name, description=new_desc)
                    self.assertIsNotNone(
                        self.hostcollection.wait_until_element(
                            common_locators['alert.success_sub_form'])
                    )
                    self.assertTrue(self.hostcollection.validate_field_value(
                        name, 'description', new_desc))
示例#28
0
    def test_positive_create_with_default_org(self):
        """Create gpg key with valid name and valid gpg key via file
        import using the default created organization

        @id: c64d4959-e53e-44c0-82da-dc4dd4c89733

        @assert: gpg key is created
        """
        org = Org.info({'name': DEFAULT_ORG})
        for name in valid_data_list():
            with self.subTest(name):
                gpg_key = make_gpg_key({
                    'key': VALID_GPG_KEY_FILE_PATH,
                    'name': name,
                    'organization-id': org['id'],
                })
                # Can we find the new object?
                result = GPGKey.exists(
                    {'organization-id': org['id']},
                    (self.search_key, gpg_key[self.search_key])
                )
                self.assertEqual(
                    gpg_key[self.search_key],
                    result[self.search_key]
                )
示例#29
0
    def test_positive_update_parameter_by_host_name(self):
        """Update existing host parameter by specifying host name.

        @Feature: Hosts

        @Assert: Host parameter was successfully updated with new value.

        """
        name = gen_string('alphanumeric').lower()
        old_value = gen_string('alphanumeric')
        Host.set_parameter({
            'host': self.host['name'],
            'name': name,
            'value': old_value,
        })
        for new_value in valid_data_list():
            with self.subTest(new_value):
                Host.set_parameter({
                    'host': self.host['name'],
                    'name': name,
                    'value': new_value,
                })
                self.host = Host.info({'id': self.host['id']})
                self.assertIn(name, self.host['parameters'].keys())
                self.assertEqual(new_value, self.host['parameters'][name])
示例#30
0
    def test_positive_update_login_page_footer_text(self):
        """Updates parameter "Login_page_footer_text" under General tab

        :id: 56a983c4-925f-4cbe-8fdb-ce344219d739

        :expectedresults: Parameter is updated successfully

        :CaseImportance: Critical
        """
        self.tab_locator = tab_locators['settings.tab_general']
        self.param_name = 'login_text'
        with Session(self) as session:
            self.original_value = self.settings.get_saved_value(
                self.tab_locator, self.param_name)
            for param_value in valid_data_list():
                with self.subTest(param_value):
                    edit_param(
                        session,
                        tab_locator=self.tab_locator,
                        param_name=self.param_name,
                        param_value=param_value,
                    )
                    self.saved_element = self.settings.get_saved_value(
                        self.tab_locator, self.param_name)
                    self.assertEqual(param_value, self.saved_element)
示例#31
0
class TestMedia:
    """Tests for ``api/v2/media``."""
    @pytest.fixture(scope='class')
    def class_media(self, module_org):
        return entities.Media(organization=[module_org]).create()

    @pytest.mark.tier1
    @pytest.mark.upgrade
    @pytest.mark.parametrize('name, new_name',
                             **parametrized(
                                 list(
                                     zip(valid_data_list().values(),
                                         valid_data_list().values()))))
    def test_positive_crud_with_name(self, module_org, name, new_name):
        """Create, update, delete media with valid name only

        :id: b07a4549-7dd5-4b36-a1b4-9f8d48ddfcb5

        :parametrized: yes

        :expectedresults: Media entity is created and has proper name

        :CaseImportance: Critical
        """
        media = entities.Media(organization=[module_org], name=name).create()
        assert media.name == name
        media = entities.Media(id=media.id, name=new_name).update(['name'])
        assert media.name == new_name
        media.delete()
        with pytest.raises(HTTPError):
            media.read()

    @pytest.mark.tier1
    @pytest.mark.parametrize('os_family', **parametrized(OPERATING_SYSTEMS))
    def test_positive_create_update_with_os_family(self, module_org,
                                                   os_family):
        """Create and update media with every OS family possible

        :id: d02404f0-b2ad-412c-b1cd-0548254f7c88

        :parametrized: yes

        :expectedresults: Media entity is created and has proper OS family
            assigned
        """
        media = entities.Media(organization=[module_org],
                               os_family=os_family).create()
        assert media.os_family == os_family
        new_os_family = new_os_family = random.choice(OPERATING_SYSTEMS)
        media.os_family = new_os_family
        assert media.update(['os_family']).os_family == new_os_family

    @pytest.mark.tier2
    def test_positive_create_with_location(self, module_org, module_location):
        """Create media entity assigned to non-default location

        :id: 1c4fa736-c145-46ca-9feb-c4046fc778c6

        :expectedresults: Media entity is created and has proper location

        :CaseLevel: Integration
        """
        media = entities.Media(organization=[module_org],
                               location=[module_location]).create()
        assert media.location[0].read().name == module_location.name

    @pytest.mark.tier2
    def test_positive_create_with_os(self, module_org):
        """Create media entity assigned to operation system entity

        :id: dec22198-ed07-480c-9306-fa5458baec0b

        :expectedresults: Media entity is created and assigned to expected OS

        :CaseLevel: Integration
        """
        os = entities.OperatingSystem().create()
        media = entities.Media(organization=[module_org],
                               operatingsystem=[os]).create()
        assert os.read().medium[0].read().name == media.name

    @pytest.mark.tier2
    def test_positive_create_update_url(self, module_org):
        """Create media entity providing the initial url path, then
        update that url to another valid one.

        :id: a183ee1f-1633-42cd-9132-cce451861b2a

        :expectedresults: Media entity is created and updated properly

        :CaseImportance: Medium
        """
        url = gen_url(subdomain=gen_string('alpha'))
        media = entities.Media(organization=[module_org], path_=url).create()
        assert media.path_ == url
        new_url = gen_url(subdomain=gen_string('alpha'))
        media = entities.Media(id=media.id, path_=new_url).update(['path_'])
        assert media.path_ == new_url

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
    def test_negative_create_with_invalid_name(self, name):
        """Try to create media entity providing an invalid name

        :id: 0934f4dc-f674-40fe-a639-035761139c83

        :parametrized: yes

        :expectedresults: Media entity is not created

        :CaseImportance: Medium
        """
        with pytest.raises(HTTPError):
            entities.Media(name=name).create()

    @pytest.mark.tier1
    def test_negative_create_with_invalid_url(self):
        """Try to create media entity providing an invalid URL

        :id: ae00b6bb-37ed-459e-b9f7-acc92ed0b262

        :expectedresults: Media entity is not created

        :CaseImportance: Medium
        """
        with pytest.raises(HTTPError):
            entities.Media(path_='NON_EXISTENT_URL').create()

    @pytest.mark.tier1
    def test_negative_create_with_invalid_os_family(self):
        """Try to create media entity providing an invalid OS family

        :id: 368b7eac-8c52-4071-89c0-1946d7101291

        :expectedresults: Media entity is not created

        :CaseImportance: Medium
        """
        with pytest.raises(HTTPError):
            entities.Media(os_family='NON_EXISTENT_OS').create()

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_name', **parametrized(invalid_values_list()))
    def test_negative_update_name(self, module_org, class_media, new_name):
        """Create media entity providing the initial name, then try to
        update its name to invalid one.

        :id: 1c7d3af1-8cef-454e-80b6-a8e95b5dfa8b

        :parametrized: yes

        :expectedresults: Media entity is not updated

        :CaseImportance: Medium
        """
        with pytest.raises(HTTPError):
            entities.Media(id=class_media.id, name=new_name).update(['name'])

    @pytest.mark.tier1
    def test_negative_update_url(self, module_org, class_media):
        """Try to update media with invalid url.

        :id: 6832f178-4adc-4bb1-957d-0d8d4fd8d9cd

        :expectedresults: Media entity is not updated

        :CaseImportance: Medium
        """
        with pytest.raises(HTTPError):
            entities.Media(id=class_media.id,
                           path_='NON_EXISTENT_URL').update(['path_'])

    @pytest.mark.tier1
    def test_negative_update_os_family(self, module_org, class_media):
        """Try to update media with invalid operation system.

        :id: f4c5438d-5f98-40b1-9bc7-c0741e81303a

        :expectedresults: Media entity is not updated

        :CaseImportance: Medium
        """
        with pytest.raises(HTTPError):
            entities.Media(id=class_media.id,
                           os_family='NON_EXISTENT_OS').update(['os_family'])
示例#32
0
    def test_positive_end_to_end_crud(self, module_org, module_location,
                                      module_user):
        """Create a new provisioning template with several attributes, update them,
        clone the provisioning template and then delete it

        :id: 8dfbb234-7a52-4873-be72-4de086472670

        :expectedresults: Template is created, with all the given attributes, updated, cloned and
                          deleted

        :CaseImportance: Critical
        """
        cfg = get_nailgun_config()
        cfg.auth = (module_user[1], module_user[2])
        name = gen_string('alpha')
        new_name = gen_string('alpha')
        template_kind = choice(entities.TemplateKind().search())

        template = entities.ProvisioningTemplate(
            name=name,
            organization=[module_org],
            location=[module_location],
            snippet=False,
            template_kind=template_kind,
        ).create()
        assert template.name == name
        assert len(template.organization
                   ) == 1, "Template should be assigned to a single org here"
        assert template.organization[0].id == module_org.id
        assert len(
            template.location
        ) == 1, "Template should be assigned to a single location here"
        assert template.location[0].id == module_location.id
        assert template.snippet is False, "Template snippet attribute is True instead of False"
        assert template.template_kind.id == template_kind.id

        # negative create
        with pytest.raises(HTTPError) as e1:
            entities.ProvisioningTemplate(
                name=gen_choice(invalid_names_list())).create()
        assert e1.value.response.status_code == 422

        invalid = entities.ProvisioningTemplate(snippet=False)
        invalid.create_missing()
        invalid.template_kind = None
        invalid.template_kind_name = gen_string('alpha')
        with pytest.raises(HTTPError) as e2:
            invalid.create(create_missing=False)
        assert e2.value.response.status_code == 422

        # update
        assert template.template_kind.id == template_kind.id, "Template kind id doesn't match"
        updated = entities.ProvisioningTemplate(cfg,
                                                id=template.id,
                                                name=new_name).update(['name'])
        assert updated.name == new_name, "The Provisioning template wasn't properly renamed"
        # clone

        template_origin = template.read_json()
        # remove unique keys
        unique_keys = ('updated_at', 'created_at', 'id', 'name')
        template_origin = {
            key: value
            for key, value in template_origin.items() if key not in unique_keys
        }

        dupe_name = gen_choice(list(valid_data_list().values()))
        dupe_json = entities.ProvisioningTemplate(id=template.clone(
            data={'name': dupe_name})['id']).read_json()
        dupe_template = entities.ProvisioningTemplate(id=dupe_json['id'])
        dupe_json = {
            key: value
            for key, value in dupe_json.items() if key not in unique_keys
        }
        assert template_origin == dupe_json

        # delete
        dupe_template.delete()
        template.delete()
        with pytest.raises(HTTPError) as e3:
            updated.read()
        assert e3.value.response.status_code == 404
    def test_positive_update_rh_product(self):
        """Update Content View in an Activation key

        @Feature: Activation key - Positive Update

        @Steps:

        1. Create an activation key
        2. Update the content view with another content view which has RH
           products

        @Assert: Activation key is updated
        """
        # Pick one of the valid data list items - data driven tests is not
        # necessary for this test
        cv2_name = random.choice(valid_data_list())
        name = gen_string('alpha')
        env1_name = gen_string('alpha')
        env2_name = gen_string('alpha')
        cv1_name = gen_string('alpha')
        rh_repo1 = {
            'name': ('Red Hat Enterprise Virtualization Agents for RHEL 6 '
                     'Server RPMs x86_64 6Server'),
            'product':
            'Red Hat Enterprise Linux Server',
            'reposet': ('Red Hat Enterprise Virtualization Agents '
                        'for RHEL 6 Server (RPMs)'),
            'basearch':
            'x86_64',
            'releasever':
            '6Server',
        }
        rh_repo2 = {
            'name': ('Red Hat Enterprise Virtualization Agents for RHEL 6 '
                     'Server RPMs i386 6Server'),
            'product':
            'Red Hat Enterprise Linux Server',
            'reposet': ('Red Hat Enterprise Virtualization Agents '
                        'for RHEL 6 Server (RPMs)'),
            'basearch':
            'i386',
            'releasever':
            '6Server',
        }
        org = entities.Organization().create()
        with manifests.clone() as manifest:
            upload_manifest(org.id, manifest.content)
        repo1_id = self.enable_sync_redhat_repo(rh_repo1, org.id)
        self.cv_publish_promote(cv1_name, env1_name, repo1_id, org.id)
        repo2_id = self.enable_sync_redhat_repo(rh_repo2, org.id)
        self.cv_publish_promote(cv2_name, env2_name, repo2_id, org.id)

        with Session(self.browser) as session:
            make_activationkey(
                session,
                org=org.name,
                name=name,
                env=env1_name,
                content_view=cv1_name,
            )
            self.assertIsNotNone(self.activationkey.search(name))
            cv_locator = locators['ak.selected_cv']
            selected_cv = self.activationkey.get_attribute(name, cv_locator)
            self.assertEqual(cv1_name, selected_cv)
            self.activationkey.update(name,
                                      content_view=cv2_name,
                                      env=env2_name)
            self.assertIsNotNone(
                self.activationkey.wait_until_element(
                    common_locators['alert.success']))
            selected_cv = self.activationkey.get_attribute(name, cv_locator)
            self.assertEqual(cv2_name, selected_cv)
示例#34
0
class TestOpenScap:
    """Tests related to the oscap cli hammer plugin"""
    @classmethod
    def fetch_scap_and_profile_id(cls, scap_name, scap_profile):
        """Extracts the scap ID and scap profile id

        :param scap_name: Scap title
        :param scap_profile: Scap profile you want to select

        :returns: scap_id and scap_profile_id
        """
        default_content = Scapcontent.info({'title': scap_name},
                                           output_format='json')
        scap_id = default_content['id']
        scap_profile_ids = [
            profile['id']
            for profile in default_content['scap-content-profiles']
            if scap_profile in profile['title']
        ]
        return scap_id, scap_profile_ids

    @pytest.mark.tier1
    def test_positive_list_default_content_with_admin(self):
        """List the default scap content with admin account

        :id: 32c41c22-6aef-424e-8e69-a65c00f1c811

        :setup:

            1. Oscap should be enabled.
            2. Default content should already be populated.
            3. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to shell from admin account.
            2. Execute the scap-content command with list as sub-command.

        :expectedresults: Default scap-content are listed.

        :BZ: 1749692

        :customerscenario: true

        :CaseImportance: Critical
        """
        scap_contents = [content['title'] for content in Scapcontent.list()]
        for title in OSCAP_DEFAULT_CONTENT.values():
            assert title in scap_contents

    @pytest.mark.tier1
    def test_negative_list_default_content_with_viewer_role(
            self, scap_content, default_viewer_role):
        """List the default scap content by user with viewer role

        :id: 1e909ffc-10d9-4bcd-b4bb-c26981912bb4

        :setup:

            1. Oscap should be enabled.
            2. Default content should already be populated.
            3. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell with viewer role.
            2. Execute the scap-content command with list as sub-Command.
            3. Execute the "scap-content" command with info as sub-command.
            4. Pass valid parameters.

        :expectedresults: The scap-content and it's info is not listed.

        :CaseImportance: Critical
        """
        result = Scapcontent.with_user(default_viewer_role.login,
                                       default_viewer_role.password).list()
        assert len(result) == 0
        with pytest.raises(CLIReturnCodeError):
            Scapcontent.with_user(default_viewer_role.login,
                                  default_viewer_role.password).info(
                                      {'title': scap_content['title']})

    @pytest.mark.tier1
    def test_positive_view_scap_content_info_admin(self):
        """View info of scap content with admin account

        :id: 539ea982-0701-43f5-bb91-e566e6687e35

        :setup:

            1. Oscap should be enabled.
            2. Default content should already be populated.
            3. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell as admin.
            2. Execute the "scap-content" command with info as sub-command.
            3. Pass valid "ID" of scap-content as argument.

        :expectedresults: The info of the scap-content is listed.

        :CaseImportance: Critical
        """
        title = gen_string('alpha')
        make_scapcontent({
            'title': title,
            'scap-file': settings.oscap.content_path
        })
        result = Scapcontent.info({'title': title})
        assert result['title'] == title

    @pytest.mark.tier1
    def test_negative_info_scap_content(self):
        """View info of scap content with invalid ID as parameter

        :id: 86f44fb1-2e2b-4004-83c1-4a62162ebea9

        :setup:

            1. Oscap should be enabled.
            2. Default content should already be populated.
            3. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell as admin.
            2. Execute the "scap-content" command with info as sub-command.
            3. Pass invalid "ID" of scap-content as argument.

        :expectedresults: The info of the scap-content is not listed.

        :CaseImportance: Critical
        """
        invalid_scap_id = gen_string('alpha')
        with pytest.raises(CLIReturnCodeError):
            Scapcontent.info({'id': invalid_scap_id})

    @pytest.mark.parametrize('title', **parametrized(valid_data_list()))
    @pytest.mark.tier1
    def test_positive_create_scap_content_with_valid_title(self, title):
        """Create scap-content with valid title

        :id: 68e9fbe2-e3c3-48e7-a774-f1260a3b7f4f

        :parametrized: yes

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Scap data stream ".xml" file.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "create" as sub-command.
            3. Pass valid parameters.

        :expectedresults: The scap-content is created successfully.

        :BZ: 1471801

        :CaseImportance: Critical
        """
        scap_content = make_scapcontent({
            'title':
            title,
            'scap-file':
            settings.oscap.content_path
        })
        assert scap_content['title'] == title

    @pytest.mark.tier1
    def test_negative_create_scap_content_with_same_title(self):
        """Create scap-content with same title

        :id: a8cbacc9-456a-4f6f-bd0e-4d1167a8b401

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Scap data stream ".xml" file.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "create" as sub-command.
            3. Pass valid parameters.
            4. Execute "scap-content" command with "create" as sub-command
               with same title

        :expectedresults: The scap-content is not created.

        :BZ: 1474172

        :CaseAutomation: Automated

        :CaseImportance: Critical
        """
        title = gen_string('alpha')
        scap_content = make_scapcontent({
            'title':
            title,
            'scap-file':
            settings.oscap.content_path
        })
        assert scap_content['title'] == title
        with pytest.raises(CLIFactoryError):
            make_scapcontent({
                'title': title,
                'scap-file': settings.oscap.content_path
            })

    @pytest.mark.parametrize('title', **parametrized(invalid_names_list()))
    @pytest.mark.tier1
    def test_negative_create_scap_content_with_invalid_title(self, title):
        """Create scap-content with invalid title

        :id: 90a2590e-a6ff-41f1-9e0a-67d4b16435c0

        :parametrized: yes

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Scap data stream ".xml" file.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "create" as sub-command.
            3. Pass valid parameters and invalid title.

        :expectedresults: The scap-content is not created.

        :CaseImportance: Critical
        """
        with pytest.raises(CLIFactoryError):
            make_scapcontent({
                'title': title,
                'scap-file': settings.oscap.content_path
            })

    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    @pytest.mark.tier1
    def test_positive_create_scap_content_with_valid_originalfile_name(
            self, name):
        """Create scap-content with valid original file name

        :id: 25441174-11cb-4d9b-9ec5-b1c69411b5bc

        :parametrized: yes

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Scap data stream ".xml" file.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "create" as sub-command.
            3. Pass valid parameters.

        :expectedresults: The scap-content is created.

        :CaseImportance: Critical
        """
        scap_content = make_scapcontent({
            'original-filename':
            name,
            'scap-file':
            settings.oscap.content_path
        })
        assert scap_content['original-filename'] == name

    @pytest.mark.parametrize('name', **parametrized(invalid_names_list()))
    @pytest.mark.tier1
    def test_negative_create_scap_content_with_invalid_originalfile_name(
            self, name):
        """Create scap-content with invalid original file name

        :id: 83feb67a-a6bf-4a99-923d-889e8d1013fa

        :parametrized: yes

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Scap data stream ".xml" file.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "create" as sub-command.
            3. Pass valid parameters and invalid title.

        :expectedresults: The scap-content is not created.

        :CaseImportance: Critical

        :BZ: 1482395
        """
        with pytest.raises(CLIFactoryError):
            make_scapcontent({
                'original-filename': name,
                'scap-file': settings.oscap.content_path
            })

    @pytest.mark.parametrize('title', **parametrized(valid_data_list()))
    @pytest.mark.tier1
    def test_negative_create_scap_content_without_dsfile(self, title):
        """Create scap-content without scap data stream xml file

        :id: ea811994-12cd-4382-9382-37fa806cc26f

        :parametrized: yes

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "create" as sub-command.
            3. Don't pass the scap-file parameter.

        :expectedresults: The scap-content is not created.

        :CaseImportance: Critical
        """
        with pytest.raises(CLIFactoryError):
            make_scapcontent({'title': title})

    @pytest.mark.tier1
    def test_positive_update_scap_content_with_newtitle(self):
        """Update scap content title

        :id: 2c32e94a-237d-40b9-8a3b-fca2ef26fe79

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "update" as sub-command.
            3. Pass valid parameters and newtitle parameter.

        :expectedresults: The scap-content is updated successfully.

        :CaseImportance: Critical

        :BZ: 1490302
        """
        title = gen_string('alpha')
        new_title = gen_string('alpha')
        scap_content = make_scapcontent({
            'title':
            title,
            'scap-file':
            settings.oscap.content_path
        })
        assert scap_content['title'] == title
        Scapcontent.update({'title': title, 'new-title': new_title})
        result = Scapcontent.info({'title': new_title}, output_format='json')
        assert result['title'] == new_title

    @pytest.mark.tier1
    def test_positive_delete_scap_content_with_id(self):
        """Delete a scap content with id as parameter

        :id: 11ae7652-65e0-4751-b1e0-246b27919238

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "delete" as sub-command.
            3. Pass ID as parameter.

        :expectedresults: The scap-content is deleted successfully.

        :CaseImportance: Critical
        """
        scap_content = make_scapcontent(
            {'scap-file': settings.oscap.content_path})
        Scapcontent.delete({'id': scap_content['id']})
        with pytest.raises(CLIReturnCodeError):
            Scapcontent.info({'id': scap_content['id']})

    @pytest.mark.tier1
    def test_positive_delete_scap_content_with_title(self):
        """Delete a scap content with title as parameter

        :id: aa4ca830-3250-4517-b40c-0256cdda5e0a

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "delete" as sub-command.
            3. Pass name as parameter.

        :expectedresults: The scap-content is deleted successfully.

        :CaseAutomation: Automated

        :CaseImportance: Critical
        """
        scap_content = make_scapcontent(
            {'scap-file': settings.oscap.content_path})
        Scapcontent.delete({'title': scap_content['title']})
        with pytest.raises(CLIReturnCodeError):
            Scapcontent.info({'title': scap_content['title']})

    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    @pytest.mark.tier2
    def test_postive_create_scap_policy_with_valid_name(
            self, name, scap_content):
        """Create scap policy with valid name

        :id: c9327675-62b2-4e22-933a-02818ef68c11

        :parametrized: yes

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "create" as sub-command.
            3. Pass valid parameters and valid name.

        :expectedresults: The policy is created successfully.
        """
        scap_policy = make_scap_policy({
            'name':
            name,
            'deploy-by':
            'puppet',
            'scap-content-id':
            scap_content["scap_id"],
            'scap-content-profile-id':
            scap_content["scap_profile_id"],
            'period':
            OSCAP_PERIOD['weekly'].lower(),
            'weekday':
            OSCAP_WEEKDAY['friday'].lower(),
        })
        assert scap_policy['name'] == name

    @pytest.mark.parametrize('name', **parametrized(invalid_names_list()))
    @pytest.mark.tier2
    def test_negative_create_scap_policy_with_invalid_name(
            self, name, scap_content):
        """Create scap policy with invalid name

        :id: 0d163968-7759-4cfd-9c4d-98533d8db925

        :parametrized: yes

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "create" as sub-command.
            3. Pass valid parameters and invalid name.

        :expectedresults: The policy is not created.
        """
        with pytest.raises(CLIFactoryError):
            make_scap_policy({
                'name':
                name,
                'deploy-by':
                'puppet',
                'scap-content-id':
                scap_content["scap_id"],
                'scap-content-profile-id':
                scap_content["scap_profile_id"],
                'period':
                OSCAP_PERIOD['weekly'].lower(),
                'weekday':
                OSCAP_WEEKDAY['friday'].lower(),
            })

    @pytest.mark.tier2
    def test_negative_create_scap_policy_without_content(self, scap_content):
        """Create scap policy without scap content

        :id: 88a8fba3-f45a-4e22-9ee1-f0d701f1135f

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "create" as sub-command.
            3. Pass valid parameters without passing the scap-content-id.

        :expectedresults: The policy is not created.
        """
        with pytest.raises(CLIFactoryError):
            make_scap_policy({
                'deploy-by':
                'puppet',
                'scap-content-profile-id':
                scap_content["scap_profile_id"],
                'period':
                OSCAP_PERIOD['weekly'].lower(),
                'weekday':
                OSCAP_WEEKDAY['friday'].lower(),
            })

    @pytest.mark.tier2
    def test_positive_associate_scap_policy_with_hostgroups(
            self, scap_content):
        """Associate hostgroups to scap policy

        :id: 916403a0-572d-4cf3-9155-3e3d0373577f

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. More than 1 hostgroups

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "create" as sub-command.
            3. Pass valid parameters.
            4. Associate multiple hostgroups with policy

        :expectedresults: The policy is created and associated successfully.
        """
        hostgroup = make_hostgroup()
        name = gen_string('alphanumeric')
        scap_policy = make_scap_policy({
            'name':
            name,
            'deploy-by':
            'puppet',
            'scap-content-id':
            scap_content["scap_id"],
            'scap-content-profile-id':
            scap_content["scap_profile_id"],
            'period':
            OSCAP_PERIOD['weekly'].lower(),
            'weekday':
            OSCAP_WEEKDAY['friday'].lower(),
            'hostgroups':
            hostgroup['name'],
        })
        assert scap_policy['hostgroups'][0] == hostgroup['name']

    @pytest.mark.tier2
    def test_positive_associate_scap_policy_with_hostgroup_via_ansible(
            self, scap_content):
        """Associate hostgroup to scap policy via ansible

        :id: 2df303c6-bff5-4977-a865-a3afabfb8726

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Created hostgroup
            4. Ansible role and Ansible variable

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "create" as sub-command.
            3. Pass valid parameters and deploy option as ansible
            4. Associate hostgroup with policy

        :expectedresults: The policy is created via ansible deploy option and
                          associated successfully.
        """
        hostgroup = make_hostgroup()
        name = gen_string('alphanumeric')
        scap_policy = make_scap_policy({
            'name':
            name,
            'deploy-by':
            'ansible',
            'scap-content-id':
            scap_content["scap_id"],
            'scap-content-profile-id':
            scap_content["scap_profile_id"],
            'period':
            OSCAP_PERIOD['weekly'].lower(),
            'weekday':
            OSCAP_WEEKDAY['friday'].lower(),
            'hostgroups':
            hostgroup['name'],
        })
        assert scap_policy['deployment-option'] == 'ansible'
        assert scap_policy['hostgroups'][0] == hostgroup['name']

    @pytest.mark.parametrize('deploy',
                             **parametrized(['manual', 'puppet', 'ansible']))
    @pytest.mark.upgrade
    @pytest.mark.tier2
    def test_positive_associate_scap_policy_with_tailoringfiles(
            self, deploy, scap_content, tailoring_file_path):
        """Associate tailoring file by name/id to scap policy with all deployments

        :id: d0f9b244-b92d-4889-ba6a-8973ea05bf43

        :parametrized: yes

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "create" as sub-command.
            3. Pass valid parameters.
            4. Associate tailoring file by name/id with policy

        :expectedresults: The policy is created and associated successfully.
        """
        tailoring_file_a = make_tailoringfile(
            {'scap-file': tailoring_file_path['satellite']})
        tailoring_file_profile_a_id = tailoring_file_a[
            'tailoring-file-profiles'][0]['id']
        tailoring_file_b = make_tailoringfile(
            {'scap-file': tailoring_file_path['satellite']})
        tailoring_file_profile_b_id = tailoring_file_b[
            'tailoring-file-profiles'][0]['id']

        scap_policy = make_scap_policy({
            'scap-content-id':
            scap_content["scap_id"],
            'deploy-by':
            deploy,
            'scap-content-profile-id':
            scap_content["scap_profile_id"],
            'period':
            OSCAP_PERIOD['weekly'].lower(),
            'weekday':
            OSCAP_WEEKDAY['friday'].lower(),
            'tailoring-file':
            tailoring_file_a['name'],
            'tailoring-file-profile-id':
            tailoring_file_profile_a_id,
        })
        assert scap_policy['deployment-option'] == deploy
        assert scap_policy['tailoring-file-id'] == tailoring_file_a['id']
        assert scap_policy[
            'tailoring-file-profile-id'] == tailoring_file_profile_a_id

        Scappolicy.update({
            'name':
            scap_policy['name'],
            'tailoring-file':
            tailoring_file_b['name'],
            'tailoring-file-profile-id':
            tailoring_file_profile_b_id,
        })
        scap_info = Scappolicy.info({'name': scap_policy['name']})
        assert scap_info['tailoring-file-id'] == tailoring_file_b['id']
        assert scap_info[
            'tailoring-file-profile-id'] == tailoring_file_profile_b_id

        Scappolicy.delete({'name': scap_policy['name']})
        with pytest.raises(CLIReturnCodeError):
            Scapcontent.info({'name': scap_policy['name']})

        scap_policy = make_scap_policy({
            'scap-content-id':
            scap_content["scap_id"],
            'deploy-by':
            deploy,
            'scap-content-profile-id':
            scap_content["scap_profile_id"],
            'period':
            OSCAP_PERIOD['weekly'].lower(),
            'weekday':
            OSCAP_WEEKDAY['friday'].lower(),
            'tailoring-file-id':
            tailoring_file_a['id'],
            'tailoring-file-profile-id':
            tailoring_file_profile_a_id,
        })
        assert scap_policy['deployment-option'] == deploy
        assert scap_policy['tailoring-file-id'] == tailoring_file_a['id']
        assert scap_policy[
            'tailoring-file-profile-id'] == tailoring_file_profile_a_id

        Scappolicy.update({
            'id':
            scap_policy['id'],
            'tailoring-file-id':
            tailoring_file_b['id'],
            'tailoring-file-profile-id':
            tailoring_file_profile_b_id,
        })
        scap_info = Scappolicy.info({'id': scap_policy['id']})
        assert scap_info['tailoring-file-id'] == tailoring_file_b['id']
        assert scap_info[
            'tailoring-file-profile-id'] == tailoring_file_profile_b_id

        Scappolicy.delete({'id': scap_policy['id']})
        with pytest.raises(CLIReturnCodeError):
            Scapcontent.info({'name': scap_policy['name']})

    @pytest.mark.parametrize('deploy',
                             **parametrized(['manual', 'puppet', 'ansible']))
    @pytest.mark.upgrade
    @pytest.mark.tier2
    def test_positive_scap_policy_end_to_end(self, deploy, scap_content):
        """List all scap policies and read info using id, name

        :id: d14ab43e-c7a9-4eee-b61c-420b07ca1da9

        :parametrized: yes

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Atleast 1 policy.

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "list" as sub-command.
            3. Execute "policy" command with "info" as sub-command.
            4. Pass ID as the parameter.
            5. Pass name as the parameter.

        :expectedresults: The policies are listed successfully and information is displayed.
        """
        hostgroup = make_hostgroup()
        name = gen_string('alphanumeric')
        scap_policy = make_scap_policy({
            'name':
            name,
            'deploy-by':
            deploy,
            'scap-content-id':
            scap_content["scap_id"],
            'scap-content-profile-id':
            scap_content["scap_profile_id"],
            'period':
            OSCAP_PERIOD['weekly'].lower(),
            'weekday':
            OSCAP_WEEKDAY['friday'].lower(),
            'hostgroups':
            hostgroup['name'],
        })
        result = Scappolicy.list()
        assert name in [policy['name'] for policy in result]
        assert Scappolicy.info({'id':
                                scap_policy['id']})['id'] == scap_policy['id']
        assert Scappolicy.info({'name': scap_policy['name']})['name'] == name

        Scappolicy.update({
            'id': scap_policy['id'],
            'period': OSCAP_PERIOD['monthly'].lower(),
            'day-of-month': 15,
        })
        scap_info = Scappolicy.info({'name': name})
        assert scap_info['period'] == OSCAP_PERIOD['monthly'].lower()
        assert scap_info['day-of-month'] == '15'
        Scappolicy.delete({'id': scap_policy['id']})
        with pytest.raises(CLIReturnCodeError):
            Scappolicy.info({'id': scap_policy['id']})

    @pytest.mark.upgrade
    @pytest.mark.tier2
    def test_positive_update_scap_policy_with_hostgroup(self, scap_content):
        """Update scap policy by addition of hostgroup

        :id: 21b9b82b-7c6c-4944-bc2f-67631e1d4086

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Atleast 1 policy and hostgroup.

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "update" as sub-command.
            3. Pass hostgoups as the parameter.

        :expectedresults: The scap policy is updated.
        """
        hostgroup = make_hostgroup()
        name = gen_string('alphanumeric')
        scap_policy = make_scap_policy({
            'name':
            name,
            'deploy-by':
            'puppet',
            'scap-content-id':
            scap_content["scap_id"],
            'scap-content-profile-id':
            scap_content["scap_profile_id"],
            'period':
            OSCAP_PERIOD['weekly'].lower(),
            'weekday':
            OSCAP_WEEKDAY['friday'].lower(),
            'hostgroups':
            hostgroup['name'],
        })
        assert scap_policy['hostgroups'][0] == hostgroup['name']
        assert scap_policy['deployment-option'] == 'puppet'
        new_hostgroup = make_hostgroup()
        Scappolicy.update({
            'id': scap_policy['id'],
            'deploy-by': 'ansible',
            'hostgroups': new_hostgroup['name']
        })
        scap_info = Scappolicy.info({'name': name})
        assert scap_info['hostgroups'][0] == new_hostgroup['name']
        # Assert if the deployment is updated
        assert scap_info['deployment-option'] == 'ansible'

    @pytest.mark.tier2
    def test_positive_update_scap_policy_period(self, scap_content):
        """Update scap policy by updating the period strategy
        from monthly to weekly

        :id: 4892bc3c-d886-49b4-a5b1-250d96b7e278

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Atleast 1 policy.

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "update" as sub-command.
            3. Pass period as parameter and weekday as parameter.

        :expectedresults: The scap policy is updated.
        """
        name = gen_string('alphanumeric')
        scap_policy = make_scap_policy({
            'name':
            name,
            'deploy-by':
            'puppet',
            'scap-content-id':
            scap_content["scap_id"],
            'scap-content-profile-id':
            scap_content["scap_profile_id"],
            'period':
            OSCAP_PERIOD['weekly'].lower(),
            'weekday':
            OSCAP_WEEKDAY['friday'].lower(),
        })
        assert scap_policy['period'] == OSCAP_PERIOD['weekly'].lower()
        Scappolicy.update({
            'id': scap_policy['id'],
            'period': OSCAP_PERIOD['monthly'].lower(),
            'day-of-month': 15,
        })
        scap_info = Scappolicy.info({'name': name})
        assert scap_info['period'] == OSCAP_PERIOD['monthly'].lower()
        assert scap_info['day-of-month'] == '15'

    @pytest.mark.tier2
    @pytest.mark.upgrade
    def test_positive_update_scap_policy_with_content(self, scap_content):
        """Update the scap policy by updating the scap content
        associated with the policy

        :id: 3c9df098-9ff8-4f48-a9a0-2ba21a8e48e0

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Atleast 1 policy.

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "update" as sub-command.
            3. Pass scap-content-id as parameter.

        :expectedresults: The scap policy is updated.
        """
        name = gen_string('alphanumeric')
        scap_policy = make_scap_policy({
            'name':
            name,
            'deploy-by':
            'puppet',
            'scap-content-id':
            scap_content["scap_id"],
            'scap-content-profile-id':
            scap_content["scap_profile_id"],
            'period':
            OSCAP_PERIOD['weekly'].lower(),
            'weekday':
            OSCAP_WEEKDAY['friday'].lower(),
        })
        assert scap_policy['scap-content-id'] == scap_content["scap_id"]
        scap_id, scap_profile_id = self.fetch_scap_and_profile_id(
            OSCAP_DEFAULT_CONTENT['rhel_firefox'], OSCAP_PROFILE['firefox'])
        Scappolicy.update({
            'name': name,
            'scap-content-id': scap_id,
            'scap-content-profile-id': scap_profile_id
        })
        scap_info = Scappolicy.info({'name': name})
        assert scap_info['scap-content-id'] == scap_id
        assert scap_info['scap-content-profile-id'] == scap_profile_id[0]

    @pytest.mark.tier2
    def test_positive_associate_scap_policy_with_single_server(
            self, scap_content):
        """Assign an audit policy to a single server

        :id: 30566c27-f466-4b4d-beaf-0a5bfda98b89

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. At least 1 policy and host.

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "update" as sub-command.
            3. Pass host name as the parameter.

        :expectedresults: The scap policy is updated.
        """
        host = entities.Host()
        host.create()
        name = gen_string('alpha')
        scap_policy = make_scap_policy({
            'name':
            name,
            'deploy-by':
            'puppet',
            'scap-content-id':
            scap_content["scap_id"],
            'scap-content-profile-id':
            scap_content["scap_profile_id"],
            'period':
            OSCAP_PERIOD['weekly'].lower(),
            'weekday':
            OSCAP_WEEKDAY['friday'].lower(),
        })
        host_name = host.name + "." + host.domain.name
        Scappolicy.update({'id': scap_policy['id'], 'hosts': host_name})
        hosts = Host.list(
            {'search': 'compliance_policy_id = {}'.format(scap_policy['id'])})
        assert host_name in [host['name'] for host in hosts]

    @pytest.mark.stubbed
    @pytest.mark.tier4
    def test_positive_list_arf_reports(self):
        """List all arf-reports

        :id: f364ea3c-ba74-4848-be39-df33f80fcd21

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Atleast 1 policy.
            4. A provisioned host with scap enabled.
            5. Reports from the host send to satellite.

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "list" as sub-command.

        :expectedresults: The arf-reports are listed successfully.

        :CaseAutomation: NotAutomated
        """

    @pytest.mark.upgrade
    @pytest.mark.stubbed
    @pytest.mark.tier4
    def test_positive_info_arf_report(self):
        """View information of arf-report

        :id: 5ac866f9-fc23-48a1-9766-a8a5f52cfd63

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Atleast 1 policy.
            4. A provisioned host with scap enabled
            5. Reports from the host send to satellite

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "info" as sub-command.
            3. Pass id as parameter.

        :expectedresults: The information of arf-report is listed successfully.

        :CaseAutomation: NotAutomated
        """

    @pytest.mark.stubbed
    @pytest.mark.tier4
    def test_positive_delete_arf_report(self):
        """Delete an arf-report
示例#35
0
:CaseComponent: UI

:TestType: Functional

:CaseImportance: High

:Upstream: No
"""
from nailgun import entities

from robottelo.datafactory import gen_string, valid_data_list
from robottelo.decorators import parametrize


@parametrize('name', **valid_data_list('ui'))
def test_positive_create(session, name):
    with session:
        session.architecture.create({'name': name})
        assert session.architecture.search(name)[0]['Name'] == name


def test_positive_create_with_os(session):
    name = gen_string('alpha')
    os_name = entities.OperatingSystem().create().name
    with session:
        session.architecture.create({
            'name': name,
            'operatingsystems.assigned': [os_name],
        })
        assert session.architecture.search(name)[0]['Name'] == name
示例#36
0
class TestOperatingSystem:
    """Tests for operating systems."""
    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    def test_positive_create_with_name(self, name):
        """Create operating system with valid name only

        :id: e95707bf-3344-4d85-866f-4642a8f66cff

        :parametrized: yes

        :expectedresults: Operating system entity is created and has proper
            name

        :CaseImportance: Critical
        """
        os = entities.OperatingSystem(name=name).create()
        assert os.name == name

    @pytest.mark.tier1
    @pytest.mark.parametrize('os_family', **parametrized(OPERATING_SYSTEMS))
    def test_positive_create_with_os_family(self, os_family):
        """Create operating system with every OS family possible

        :id: 6ad32d22-53cc-4bab-ac10-f466f75d7cc6

        :parametrized: yes

        :expectedresults: Operating system entity is created and has proper OS
            family assigned

        :CaseAutomation: Automated

        :CaseImportance: Critical
        """
        if is_open('BZ:1709683') and os_family == 'Debian':
            pytest.skip("BZ 1709683")
        os = entities.OperatingSystem(family=os_family).create()
        assert os.family == os_family

    @pytest.mark.tier1
    def test_positive_create_with_minor_version(self):
        """Create operating system with minor version

        :id: fc2e36ca-eb5c-440b-957e-390cd9820945

        :expectedresults: Operating system entity is created and has proper
            minor version

        :CaseImportance: Critical
        """
        minor_version = gen_string('numeric')
        os = entities.OperatingSystem(minor=minor_version).create()
        assert os.minor == minor_version

    @pytest.mark.tier1
    def test_positive_read_minor_version_as_string(self):
        """Create an operating system with an integer minor version.

        :id: b45e0b94-62f7-45ff-a19e-83c7a0f51339

        :expectedresults: The minor version can be read back as a string.

        :CaseImportance: Critical

        :BZ: 1230902
        """
        minor = int(gen_string('numeric', random.randint(1, 16)))
        operating_sys = entities.OperatingSystem(minor=minor).create()
        assert operating_sys.minor == str(minor)

    @pytest.mark.tier1
    @pytest.mark.parametrize('desc', **parametrized(valid_data_list()))
    def test_positive_create_with_description(self, desc):
        """Create operating system with description

        :id: 980e6411-da11-4fec-ae46-47722367ae40

        :parametrized: yes

        :expectedresults: Operating system entity is created and has proper
            description

        :CaseImportance: Critical
        """
        name = gen_string('utf8')
        os = entities.OperatingSystem(name=name, description=desc).create()
        assert os.name == name
        assert os.description == desc

    @pytest.mark.tier1
    @pytest.mark.parametrize('pass_hash', **parametrized(('SHA256', 'SHA512')))
    def test_positive_create_with_password_hash(self, pass_hash):
        """Create operating system with valid password hash option

        :id: 00830e71-b414-41ab-bc8f-03fd2fbd5a84

        :parametrized: yes

        :expectedresults: Operating system entity is created and has proper
            password hash type

        :CaseImportance: Critical
        """
        os = entities.OperatingSystem(password_hash=pass_hash).create()
        assert os.password_hash == pass_hash

    @pytest.mark.tier2
    def test_positive_create_with_arch(self):
        """Create an operating system that points at an architecture.

        :id: 6a3f7183-b0bf-4834-8c69-a49fe8d7ee5a

        :expectedresults: The operating system is created and points at the
            given architecture.

        :CaseLevel: Integration
        """
        arch = entities.Architecture().create()
        operating_sys = entities.OperatingSystem(architecture=[arch]).create()
        assert len(operating_sys.architecture) == 1
        assert operating_sys.architecture[0].id == arch.id

    @pytest.mark.tier2
    def test_positive_create_with_archs(self):
        """Create an operating system that points at multiple different
        architectures.

        :id: afd26c6a-bf54-4883-baa5-95f263e6fb36

        :expectedresults: The operating system is created and points at the
            expected architectures.

        :CaseLevel: Integration
        """
        amount = range(random.randint(3, 5))
        archs = [entities.Architecture().create() for _ in amount]
        operating_sys = entities.OperatingSystem(architecture=archs).create()
        assert len(operating_sys.architecture) == len(amount)
        assert {arch.id
                for arch in operating_sys.architecture
                } == {arch.id
                      for arch in archs}

    @pytest.mark.tier2
    def test_positive_create_with_ptable(self):
        """Create an operating system that points at a partition table.

        :id: bef37ff9-d8fa-4518-9073-0518aa9f9a42

        :expectedresults: The operating system is created and points at the
            given partition table.

        :CaseLevel: Integration
        """
        ptable = entities.PartitionTable().create()
        operating_sys = entities.OperatingSystem(ptable=[ptable]).create()
        assert len(operating_sys.ptable) == 1
        assert operating_sys.ptable[0].id == ptable.id

    @pytest.mark.tier2
    def test_positive_create_with_ptables(self):
        """Create an operating system that points at multiple different
        partition tables.

        :id: ed48a279-a222-45ce-81e4-72ae9422482a

        :expectedresults: The operating system is created and points at the
            expected partition tables.

        :CaseLevel: Integration
        """
        amount = range(random.randint(3, 5))
        ptables = [entities.PartitionTable().create() for _ in amount]
        operating_sys = entities.OperatingSystem(ptable=ptables).create()
        assert len(operating_sys.ptable) == len(amount)
        assert {ptable.id
                for ptable in operating_sys.ptable
                } == {ptable.id
                      for ptable in ptables}

    @pytest.mark.tier2
    def test_positive_create_with_media(self, module_org):
        """Create an operating system that points at a media.

        :id: 56fadee4-c676-48b6-a2db-e6fef9d2a575

        :expectedresults: The operating system is created and points at the
            given media.

        :CaseLevel: Integration
        """
        medium = entities.Media(organization=[module_org]).create()
        operating_sys = entities.OperatingSystem(medium=[medium]).create()
        assert len(operating_sys.medium) == 1
        assert operating_sys.medium[0].id == medium.id

    @pytest.mark.tier2
    def test_positive_create_with_template(self, module_org):
        """Create an operating system that points at a provisioning template.

        :id: df73ecba-5a1c-4201-9c2f-b2e03e8fec25

        :expectedresults: The operating system is created and points at the
            expected provisioning template.

        :CaseLevel: Integration
        """
        template = entities.ProvisioningTemplate(
            organization=[module_org]).create()
        operating_sys = entities.OperatingSystem(
            provisioning_template=[template]).create()
        assert len(operating_sys.provisioning_template) == 1
        assert operating_sys.provisioning_template[0].id == template.id

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
    def test_negative_create_with_invalid_name(self, name):
        """Try to create operating system entity providing an invalid
        name

        :id: cd4286fd-7128-4385-9c8d-ef979c22ee38

        :parametrized: yes

        :expectedresults: Operating system entity is not created

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.OperatingSystem(name=name).create()

    @pytest.mark.tier1
    def test_negative_create_with_invalid_os_family(self):
        """Try to create operating system entity providing an invalid
        operating system family

        :id: 205a433d-750b-4b06-9fd4-274303780d6d

        :expectedresults: Operating system entity is not created

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.OperatingSystem(family='NON_EXISTENT_OS').create()

    @pytest.mark.tier1
    def test_negative_create_with_too_long_description(self):
        """Try to create operating system entity providing too long
        description value

        :id: fe5fc36a-5994-4d8a-91f6-0425765b8c39

        :expectedresults: Operating system entity is not created

        :BZ: 1328935

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.OperatingSystem(
                description=gen_string('alphanumeric', 256)).create()

    @pytest.mark.tier1
    @pytest.mark.parametrize('major_version',
                             **parametrized((gen_string('numeric',
                                                        6), '', '-6')))
    def test_negative_create_with_invalid_major_version(self, major_version):
        """Try to create operating system entity providing incorrect
        major version value (More than 5 characters, empty value, negative
        number)

        :id: f2646bc2-d639-4079-bdcb-ff76679f1457

        :parametrized: yes

        :expectedresults: Operating system entity is not created

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.OperatingSystem(major=major_version).create()

    @pytest.mark.tier1
    @pytest.mark.parametrize('minor_version',
                             **parametrized((gen_string('numeric', 17), '-5')))
    def test_negative_create_with_invalid_minor_version(self, minor_version):
        """Try to create operating system entity providing incorrect
        minor version value (More than 16 characters and negative number)

        :id: dec4b456-153c-4a66-8b8e-b12ac7800e51

        :parametrized: yes

        :expectedresults: Operating system entity is not created

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.OperatingSystem(minor=minor_version).create()

    @pytest.mark.tier1
    def test_negative_create_with_invalid_password_hash(self):
        """Try to create operating system entity providing invalid
        password hash value

        :id: 9cfcb6d4-0601-4fc7-bd1e-8b8327129a69

        :expectedresults: Operating system entity is not created

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.OperatingSystem(password_hash='INVALID_HASH').create()

    @pytest.mark.tier1
    def test_negative_create_with_same_name_and_version(self):
        """Create operating system providing valid name and major
        version. Then try to create operating system using the same name and
        version

        :id: 3f2ca323-7789-4d2b-bf21-2454317147ff

        :expectedresults: Second operating system entity is not created

        :CaseImportance: Critical
        """
        os = entities.OperatingSystem().create()
        with pytest.raises(HTTPError):
            entities.OperatingSystem(name=os.name, major=os.major).create()

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_name', **parametrized(valid_data_list()))
    def test_positive_update_name(self, new_name):
        """Create operating system entity providing the initial name,
        then update its name to another valid name.

        :id: 2898e16a-865a-4de6-b2a5-bb0934fc2b76

        :parametrized: yes

        :expectedresults: Operating system entity is created and updated
            properly

        :CaseImportance: Critical
        """
        os = entities.OperatingSystem().create()
        os = entities.OperatingSystem(id=os.id, name=new_name).update(['name'])
        assert os.name == new_name

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_desc', **parametrized(valid_data_list()))
    def test_positive_update_description(self, new_desc):
        """Create operating entity providing the initial description,
        then update that description to another valid one.

        :id: c809700a-b6ab-4651-9bd0-d0d9bd6a47dd

        :parametrized: yes

        :expectedresults: Operating system entity is created and updated
            properly

        :CaseImportance: Critical
        """
        os = entities.OperatingSystem(description=gen_string('utf8')).create()
        os = entities.OperatingSystem(id=os.id, description=new_desc).update(
            ['description'])
        assert os.description == new_desc

    @pytest.mark.tier1
    def test_positive_update_major_version(self):
        """Create operating entity providing the initial major version,
        then update that version to another valid one.

        :id: e57fd4a3-f0ae-49fb-bd84-9a6ec606a2a2

        :expectedresults: Operating system entity is created and updated
            properly

        :CaseImportance: Critical
        """
        os = entities.OperatingSystem().create()
        new_major_version = gen_string('numeric', 5)
        os = entities.OperatingSystem(
            id=os.id, major=new_major_version).update(['major'])
        assert os.major == new_major_version

    @pytest.mark.tier1
    def test_positive_update_minor_version(self):
        """Create operating entity providing the initial minor version,
        then update that version to another valid one.

        :id: ca36f7cf-4487-4743-be06-52c5f47ffe71

        :expectedresults: Operating system entity is created and updated
            properly

        :CaseImportance: Critical
        """
        os = entities.OperatingSystem(minor=gen_string('numeric')).create()
        new_minor_version = gen_string('numeric')
        os = entities.OperatingSystem(
            id=os.id, minor=new_minor_version).update(['minor'])
        assert os.minor == new_minor_version

    @pytest.mark.tier1
    def test_positive_update_os_family(self):
        """Create operating entity providing the initial os family, then
        update that family to another valid one from the list.

        :id: 3d1f8fdc-d2de-4277-a0ba-07228a2fae82

        :expectedresults: Operating system entity is created and updated
            properly

        :CaseImportance: Critical
        """
        os = entities.OperatingSystem(family=OPERATING_SYSTEMS[0]).create()
        new_os_family = OPERATING_SYSTEMS[random.randint(
            1,
            len(OPERATING_SYSTEMS) - 1)]
        os = entities.OperatingSystem(id=os.id,
                                      family=new_os_family).update(['family'])
        assert os.family == new_os_family

    @pytest.mark.tier2
    @pytest.mark.upgrade
    def test_positive_update_arch(self):
        """Create an operating system that points at an architecture and
        then update it to point to another architecture

        :id: ad69b4a3-6371-4516-b5ce-f6298edf35b3

        :expectedresults: The operating system is updated and points at the
            expected architecture.

        :CaseLevel: Integration
        """
        arch_1 = entities.Architecture().create()
        arch_2 = entities.Architecture().create()
        os = entities.OperatingSystem(architecture=[arch_1]).create()
        assert len(os.architecture) == 1
        assert os.architecture[0].id == arch_1.id
        os = entities.OperatingSystem(id=os.id,
                                      architecture=[arch_2
                                                    ]).update(['architecture'])
        assert len(os.architecture) == 1
        assert os.architecture[0].id == arch_2.id

    @pytest.mark.tier2
    def test_positive_update_ptable(self):
        """Create an operating system that points at partition table and
        then update it to point to another partition table

        :id: 0dde5372-4b90-4c83-b497-31e94065adab

        :expectedresults: The operating system is updated and points at the
            expected partition table.

        :CaseLevel: Integration
        """
        ptable_1 = entities.PartitionTable().create()
        ptable_2 = entities.PartitionTable().create()
        os = entities.OperatingSystem(ptable=[ptable_1]).create()
        assert len(os.ptable) == 1
        assert os.ptable[0].id == ptable_1.id
        os = entities.OperatingSystem(id=os.id,
                                      ptable=[ptable_2]).update(['ptable'])
        assert len(os.ptable) == 1
        assert os.ptable[0].id == ptable_2.id

    @pytest.mark.tier2
    def test_positive_update_media(self, module_org):
        """Create an operating system that points at media entity and
        then update it to point to another media

        :id: 18b5f6b5-52ab-4722-8412-f0de85ad20fe

        :expectedresults: The operating system is updated and points at the
            expected media.

        :CaseLevel: Integration
        """
        media_1 = entities.Media(organization=[module_org]).create()
        media_2 = entities.Media(organization=[module_org]).create()
        os = entities.OperatingSystem(medium=[media_1]).create()
        assert len(os.medium) == 1
        assert os.medium[0].id == media_1.id
        os = entities.OperatingSystem(id=os.id,
                                      medium=[media_2]).update(['medium'])
        assert len(os.medium) == 1
        assert os.medium[0].id == media_2.id

    @pytest.mark.tier2
    @pytest.mark.upgrade
    def test_positive_update_medias(self, module_org):
        """Create an operating system that points at media entity and
        then update it to point to another multiple different medias.

        :id: 756c4aa8-278d-488e-b48f-a8d2ace4526e

        :expectedresults: The operating system is updated and points at the
            expected medias.

        :CaseLevel: Integration
        """
        initial_media = entities.Media(organization=[module_org]).create()
        os = entities.OperatingSystem(medium=[initial_media]).create()
        assert len(os.medium) == 1
        assert os.medium[0].id == initial_media.id
        amount = range(random.randint(3, 5))
        medias = [entities.Media().create() for _ in amount]
        os = entities.OperatingSystem(id=os.id,
                                      medium=medias).update(['medium'])
        assert len(os.medium) == len(amount)
        assert {medium.id
                for medium in os.medium} == {medium.id
                                             for medium in medias}

    @pytest.mark.tier2
    @pytest.mark.upgrade
    def test_positive_update_template(self, module_org):
        """Create an operating system that points at provisioning template and
        then update it to point to another template

        :id: 02125a7a-905a-492a-a49b-768adf4ac00c

        :expectedresults: The operating system is updated and points at the
            expected provisioning template.

        :CaseLevel: Integration
        """
        template_1 = entities.ProvisioningTemplate(
            organization=[module_org]).create()
        template_2 = entities.ProvisioningTemplate(
            organization=[module_org]).create()
        os = entities.OperatingSystem(
            provisioning_template=[template_1]).create()
        assert len(os.provisioning_template) == 1
        assert os.provisioning_template[0].id == template_1.id
        os = entities.OperatingSystem(id=os.id,
                                      provisioning_template=[
                                          template_2
                                      ]).update(['provisioning_template'])
        assert len(os.provisioning_template) == 1
        assert os.provisioning_template[0].id == template_2.id

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_name', **parametrized(invalid_values_list()))
    def test_negative_update_name(self, new_name):
        """Create operating system entity providing the initial name,
        then update its name to invalid one.

        :id: 3ba55d6e-99cb-4878-b41b-a59476d1db58

        :parametrized: yes

        :expectedresults: Operating system entity is not updated

        :CaseImportance: Critical
        """
        os = entities.OperatingSystem().create()
        with pytest.raises(HTTPError):
            os = entities.OperatingSystem(id=os.id,
                                          name=new_name).update(['name'])

    @pytest.mark.tier1
    def test_negative_update_major_version(self):
        """Create operating entity providing the initial major version,
        then update that version to invalid one.

        :id: de07c2f7-0896-493d-976c-e9f3a8a57025

        :expectedresults: Operating system entity is not updated

        :CaseImportance: Critical
        """
        os = entities.OperatingSystem().create()
        with pytest.raises(HTTPError):
            entities.OperatingSystem(id=os.id, major='-20').update(['major'])

    @pytest.mark.tier1
    def test_negative_update_minor_version(self):
        """Create operating entity providing the initial minor version,
        then update that version to invalid one.

        :id: 130d028f-302d-4c20-b35c-c7f024f3897b

        :expectedresults: Operating system entity is not updated

        :CaseImportance: Critical
        """
        os = entities.OperatingSystem(minor=gen_string('numeric')).create()
        with pytest.raises(HTTPError):
            entities.OperatingSystem(id=os.id,
                                     minor='INVALID_VERSION').update(['minor'])

    @pytest.mark.tier1
    def test_negative_update_os_family(self):
        """Create operating entity providing the initial os family, then
        update that family to invalid one.

        :id: fc11506e-8a46-470b-bde0-6fc5db98463f

        :expectedresults: Operating system entity is not updated

        :CaseImportance: Critical
        """
        os = entities.OperatingSystem(family=OPERATING_SYSTEMS[0]).create()
        with pytest.raises(HTTPError):
            entities.OperatingSystem(
                id=os.id, family='NON_EXISTENT_OS').update(['family'])

    @pytest.mark.tier1
    @pytest.mark.upgrade
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    def test_positive_delete(self, name):
        """Create new operating system entity and then delete it.

        :id: 3dbffb56-ad99-441d-921c-0fad6504d257

        :parametrized: yes

        :expectedresults: Operating System entity is deleted successfully

        :CaseImportance: Critical
        """
        os = entities.OperatingSystem(name=name).create()
        os.delete()
        with pytest.raises(HTTPError):
            os.read()
示例#37
0
class TestTailoringFiles:
    """Implements Tailoring Files tests in CLI."""
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    @pytest.mark.tier1
    def test_positive_create(self, tailoring_file_path, name):
        """Create new Tailoring Files using different values types as name

        :id: e1bb4de2-1b64-4904-bc7c-f0befa9dbd6f

        :steps:

            1. Create valid tailoring file with valid parameter

        :expectedresults: Tailoring file will be added to satellite

        :parametrized: yes
        """
        tailoring_file = make_tailoringfile({
            'name':
            name,
            'scap-file':
            tailoring_file_path['satellite']
        })
        assert tailoring_file['name'] == name

    @pytest.mark.tier1
    def test_positive_create_with_space(self, tailoring_file_path):
        """Create tailoring files with space in name

        :id: c98ef4e7-41c5-4a8b-8a0b-8d53100b75a8

        :steps:

            1. Create valid tailoring file with space in name

        :expectedresults: Tailoring file will be added to satellite

        :CaseImportance: Medium
        """
        name = gen_string('alphanumeric') + ' ' + gen_string('alphanumeric')
        tailoring_file = make_tailoringfile({
            'name':
            name,
            'scap-file':
            tailoring_file_path['satellite']
        })
        assert tailoring_file['name'] == name

    @pytest.mark.tier1
    def test_positive_get_info_of_tailoring_file(self, tailoring_file_path):
        """Get information of tailoring file

        :id: bc201194-e8c8-4385-a577-09f3455f5a4d

        :setup: tailoring file

        :steps:

            1. Create tailoring file with valid parameters
            2. Execute "tailoring-file" command with "info" as sub-command
               with valid parameter

        :expectedresults: Tailoring file information should be displayed

        :CaseImportance: Medium
        """
        name = gen_string('alphanumeric')
        make_tailoringfile({
            'name': name,
            'scap-file': tailoring_file_path['satellite']
        })
        result = TailoringFiles.info({'name': name})
        assert result['name'] == name

    @pytest.mark.tier1
    def test_positive_list_tailoring_file(self, tailoring_file_path):
        """List all created tailoring files

        :id: 2ea63c4b-eebe-468d-8153-807e86d1b6a2

        :setup: tailoring file

        :steps:

            1. Create different tailoring file with different valid name
            2. Execute "tailoring-file" command with "list" as sub-command

        :expectedresults: Tailoring files list should be displayed

        :CaseImportance: Medium
        """
        name = gen_string('alphanumeric')
        make_tailoringfile({
            'name': name,
            'scap-file': tailoring_file_path['satellite']
        })
        result = TailoringFiles.list()
        assert name in [tailoringfile['name'] for tailoringfile in result]

    @pytest.mark.tier1
    def test_negative_create_with_invalid_file(self, target_sat):
        """Create Tailoring files with invalid file

        :id: 86f5ce13-856c-4e58-997f-fa21093edd04

        :steps:

            1. Attempt to create tailoring file with invalid file

        :expectedresults: Tailoring file will not be added to satellite

        :CaseImportance: Medium
        """
        target_sat.put(get_data_file(SNIPPET_DATA_FILE),
                       f'/tmp/{SNIPPET_DATA_FILE}')
        name = gen_string('alphanumeric')
        with pytest.raises(CLIFactoryError):
            make_tailoringfile({
                'name': name,
                'scap-file': f'/tmp/{SNIPPET_DATA_FILE}'
            })

    @pytest.mark.parametrize('name', **parametrized(invalid_names_list()))
    @pytest.mark.tier1
    def test_negative_create_with_invalid_name(self, tailoring_file_path,
                                               name):
        """Create Tailoring files with invalid name

        :id: 973eee82-9735-49bb-b534-0de619aa0279

        :steps:

            1. Attempt to create tailoring file with invalid name parameter

        :expectedresults: Tailoring file will not be added to satellite

        :parametrized: yes

        :CaseImportance: Medium
        """
        with pytest.raises(CLIFactoryError):
            make_tailoringfile({
                'name': name,
                'scap-file': tailoring_file_path['satellite']
            })

    @pytest.mark.stubbed
    @pytest.mark.tier2
    def test_negative_associate_tailoring_file_with_different_scap(self):
        """Associate a tailoring file with different scap content

        :id: f36be738-eaa1-4f6b-aa6c-9924be5f1e96

        :steps:

            1. Execute "scap-content" command with "create" as sub-command
            2. Upload a Mutually exclusive tailoring file
            3. Associate the scap content with tailoring file

        :CaseAutomation: NotAutomated

        :expectedresults: Association should give some warning

        :CaseImportance: Medium
        """

    @pytest.mark.skip_if_open("BZ:1857572")
    @pytest.mark.tier2
    def test_positive_download_tailoring_file(self, tailoring_file_path,
                                              target_sat):
        """Download the tailoring file from satellite

        :id: 75d8c810-19a7-4285-bc3a-a1fb1a0e9088

        :steps:

            1.Create valid tailoring file with valid name
            2.Execute "tailoring-file" command with "download" as sub-command

        :expectedresults: The tailoring file should be downloaded

        BZ: 1857572

        :CaseImportance: Medium
        """
        name = gen_string('alphanumeric')
        file_path = f'/var{tailoring_file_path["satellite"]}'
        tailoring_file = make_tailoringfile({
            'name':
            name,
            'scap-file':
            tailoring_file_path['satellite']
        })
        assert tailoring_file['name'] == name
        result = TailoringFiles.download_tailoring_file({
            'name': name,
            'path': '/var/tmp/'
        })
        assert file_path in result
        result = target_sat.execute(f'find {file_path} 2> /dev/null')
        assert result.status == 0
        assert file_path == result.stdout.strip()

    @pytest.mark.tier1
    @pytest.mark.upgrade
    def test_positive_delete_tailoring_file(self, tailoring_file_path):
        """Delete tailoring file

        :id: 8bab5478-1ef1-484f-aafd-98e5cba7b1e7

        :steps:

            1. Create valid tailoring file with valid parameter
            2. Execute "tailoring-file" command with "delete" as sub-command

        :expectedresults: Tailoring file should be deleted

        :CaseImportance: Medium
        """
        tailoring_file = make_tailoringfile(
            {'scap-file': tailoring_file_path['satellite']})
        TailoringFiles.delete({'id': tailoring_file['id']})
        with pytest.raises(CLIReturnCodeError):
            TailoringFiles.info({'id': tailoring_file['id']})

    @pytest.mark.stubbed
    @pytest.mark.tier4
    @pytest.mark.pit_server
    @pytest.mark.pit_client
    @pytest.mark.upgrade
    def test_positive_oscap_run_with_tailoring_file_and_capsule(self):
        """End-to-End Oscap run with tailoring files and default capsule

        :id: 91fd3ccd-6177-4efd-8842-73fd14f53a85

        :steps:

            1. Execute "scap-content" command with "create" as sub-command
            2. Execute "tailoring-file" command with "create" as sub-command
            3. Execute "policy" command with "create" as sub-command
            4. Associate scap content with it’s tailoring file
            5. Associate the policy with a hostgroup
            6. Provision a host using the hostgroup
            7. Puppet should configure and fetch the scap content
               and tailoring file

        :CaseAutomation: NotAutomated

        :expectedresults: ARF report should be sent to satellite reflecting
                         the changes done via tailoring files
        """

    @pytest.mark.stubbed
    @pytest.mark.tier4
    @pytest.mark.upgrade
    def test_positive_oscap_run_with_tailoring_file_and_external_capsule(self):
        """End-to-End Oscap run with tailoring files and external capsule

        :id: 39d2e690-8410-4cc7-b873-bb5f658148cc

        :steps:

            1. Execute "scap-content" command with "create" as sub-command
            2. Execute "tailoring-file" command with "create" as sub-command
            3. Execute "policy" command with "create" as sub-command
            4. Associate scap content with it’s tailoring file
            5. Associate the policy with a hostgroup
            6. Provision a host using the hostgroup
            7. Puppet should configure and fetch the scap content
               and tailoring file from external capsule

        :CaseAutomation: NotAutomated

        :expectedresults: ARF report should be sent to satellite
                         reflecting the changes done via tailoring files
        """

    @pytest.mark.stubbed
    @pytest.mark.tier4
    @pytest.mark.upgrade
    def test_positive_fetch_tailoring_file_information_from_arfreports(self):
        """Fetch Tailoring file Information from Arf-reports
示例#38
0
                'repo_type': REPO_TYPE['yum'],
                'repo_content.upstream_url': FAKE_1_YUM_REPO,
            })
        # Synchronize the product
        result = session.product.synchronize(new_product_name)
        assert result['result'] == 'success'
        product_values = session.product.read(new_product_name)
        assert product_values['details']['repos_count'] == '1'
        assert product_values['details']['sync_state'] == 'Syncing Complete.'
        # Delete product
        session.product.delete(new_product_name)
        assert session.product.search(
            new_product_name)[0]['Name'] != new_product_name


@parametrize('product_name', **valid_data_list('ui'))
@tier2
def test_positive_create_in_different_orgs(session, product_name):
    """Create Product with same name but in different organizations

    :id: 469fc036-a48a-4c0a-9da9-33e73f903479

    :expectedresults: Product is created successfully in both
        organizations.

    :CaseLevel: Integration
    """
    orgs = [entities.Organization().create() for _ in range(2)]
    with session:
        for org in orgs:
            session.organization.select(org_name=org.name)
示例#39
0
    def test_positive_CRUD(self):
        """Create, update and delete subnet

        :id: d74a52a7-df56-44ef-89a3-081c14e81e43

        :expectedresults: Subnet is created, updated and deleted

        :CaseImportance: Critical
        """
        name = valid_data_list()[0]
        pool = sorted(valid_addr_pools()[0])
        mask = '255.255.255.0'
        # generate pool range from network address
        network = gen_ipaddr()
        from_ip = re.sub(r'\d+$', str(pool[0]), network)
        to_ip = re.sub(r'\d+$', str(pool[1]), network)
        domains_amount = random.randint(3, 5)
        domains = [make_domain() for _ in range(domains_amount)]
        gateway = gen_ipaddr(ip3=True)
        ipam_type = SUBNET_IPAM_TYPES['dhcp']
        subnet = make_subnet(
            {
                'name': name,
                'from': from_ip,
                'mask': mask,
                'network': network,
                'to': to_ip,
                'domain-ids': [domain['id'] for domain in domains],
                'gateway': gateway,
                'ipam': ipam_type,
            }
        )
        # Check if Subnet can be listed
        subnets_ids = [subnet_['id'] for subnet_ in Subnet.list()]
        self.assertIn(subnet['id'], subnets_ids)
        self.assertEqual(subnet['name'], name)
        self.assertEqual(subnet['start-of-ip-range'], from_ip)
        self.assertEqual(subnet['end-of-ip-range'], to_ip)
        self.assertEqual(len(subnet['domains']), domains_amount)
        for domain in domains:
            self.assertIn(domain['name'], subnet['domains'])
        self.assertIn(gateway, subnet['gateway-addr'])
        self.assertIn(ipam_type, subnet['ipam'])

        # update subnet
        new_name = valid_data_list()[0]
        pool = sorted(valid_addr_pools()[0])
        # generate pool range from network address
        new_network = gen_ipaddr()
        new_mask = '255.255.192.0'
        ip_from = re.sub(r'\d+$', str(pool[0]), new_network)
        ip_to = re.sub(r'\d+$', str(pool[1]), new_network)
        ipam_type = SUBNET_IPAM_TYPES['internal']
        Subnet.update(
            {
                'new-name': new_name,
                'from': ip_from,
                'id': subnet['id'],
                'to': ip_to,
                'mask': new_mask,
                'network': new_network,
                'ipam': ipam_type,
                'domain-ids': "",  # delete domains needed for subnet delete
            }
        )
        subnet = Subnet.info({'id': subnet['id']})
        self.assertEqual(subnet['name'], new_name)
        self.assertEqual(subnet['start-of-ip-range'], ip_from)
        self.assertEqual(subnet['end-of-ip-range'], ip_to)
        self.assertEqual(subnet['network-addr'], new_network)
        self.assertEqual(subnet['network-mask'], new_mask)
        self.assertIn(ipam_type, subnet['ipam'])

        # delete subnet
        Subnet.delete({'id': subnet['id']})
        with self.assertRaises(CLIReturnCodeError):
            Subnet.info({'id': subnet['id']})
示例#40
0
                'repo_content.upstream_url': FAKE_1_YUM_REPO,
            },
        )
        # Synchronize the product
        result = session.product.synchronize(new_product_name)
        assert result['result'] == 'success'
        product_values = session.product.read(new_product_name)
        assert product_values['details']['repos_count'] == '1'
        assert product_values['details']['sync_state'] == 'Syncing Complete.'
        # Delete product
        session.product.delete(new_product_name)
        assert session.product.search(
            new_product_name)[0]['Name'] != new_product_name


@pytest.mark.parametrize('product_name', **parametrized(valid_data_list('ui')))
@pytest.mark.tier2
def test_positive_create_in_different_orgs(session, product_name):
    """Create Product with same name but in different organizations

    :id: 469fc036-a48a-4c0a-9da9-33e73f903479

    :parametrized: yes

    :expectedresults: Product is created successfully in both
        organizations.

    :CaseLevel: Integration
    """
    orgs = [entities.Organization().create() for _ in range(2)]
    with session:
示例#41
0
def test_positive_CRUD(module_org):
    """Check if product can be created, updated, synchronized and deleted

    :id: 9d7b5ec8-59d0-4371-b5d2-d43145e4e2db

    :expectedresults: Product is created, updated, synchronized and deleted

    :BZ: 1422552

    :CaseImportance: Critical
    """
    desc = list(valid_data_list().values())[0]
    gpg_key = make_content_credential({'organization-id': module_org.id})
    name = list(valid_data_list().values())[0]
    label = valid_labels_list()[0]
    sync_plan = make_sync_plan({'organization-id': module_org.id})
    product = make_product(
        {
            'description': desc,
            'gpg-key-id': gpg_key['id'],
            'label': label,
            'name': name,
            'organization-id': module_org.id,
            'sync-plan-id': sync_plan['id'],
        },
    )
    assert product['name'] == name
    assert len(product['label']) > 0
    assert product['label'] == label
    assert product['description'] == desc
    assert product['gpg']['gpg-key-id'] == gpg_key['id']
    assert product['sync-plan-id'] == sync_plan['id']

    # update
    desc = list(valid_data_list().values())[0]
    new_gpg_key = make_content_credential({'organization-id': module_org.id})
    new_sync_plan = make_sync_plan({'organization-id': module_org.id})
    new_prod_name = gen_string('alpha', 8)
    Product.update(
        {
            'description': desc,
            'id': product['id'],
            'gpg-key-id': new_gpg_key['id'],
            'sync-plan-id': new_sync_plan['id'],
            'name': new_prod_name,
        }
    )
    product = Product.info({'id': product['id'], 'organization-id': module_org.id})
    assert product['name'] == new_prod_name
    assert product['description'] == desc
    assert product['gpg']['gpg-key-id'] == new_gpg_key['id']
    assert product['gpg']['gpg-key-id'] != gpg_key['id']
    assert product['sync-plan-id'] == new_sync_plan['id']
    assert product['sync-plan-id'] != sync_plan['id']

    # synchronize
    repo = make_repository(
        {
            'organization-id': module_org.id,
            'product-id': product['id'],
            'url': settings.repos.yum_0.url,
        },
    )
    Product.synchronize({'id': product['id'], 'organization-id': module_org.id})
    packages = Package.list({'product-id': product['id']})
    repo = Repository.info({'id': repo['id']})
    assert int(repo['content-counts']['packages']) == len(packages)
    assert len(packages) == FAKE_0_YUM_REPO_PACKAGES_COUNT

    # delete
    Product.remove_sync_plan({'id': product['id']})
    product = Product.info({'id': product['id'], 'organization-id': module_org.id})
    assert len(product['sync-plan-id']) == 0
    Product.delete({'id': product['id']})
    wait_for_tasks(
        search_query="label = Actions::Katello::Product::Destroy"
        f" and resource_id = {product['id']}",
        max_tries=10,
    )
    with pytest.raises(CLIReturnCodeError):
        Product.info({'id': product['id'], 'organization-id': module_org.id})
示例#42
0
    promote(cvv, lce.id)
    ak = entities.ActivationKey(
        content_view=cv, max_hosts=100, organization=org, environment=lce, auto_attach=True
    ).create()
    subscription = entities.Subscription(organization=org).search(
        query={'search': f'name="{DEFAULT_SUBSCRIPTION_NAME}"'}
    )[0]
    ak.add_subscriptions(data={'quantity': 1, 'subscription_id': subscription.id})
    return ak, org


# Tests for ``katello/api/v2/report_templates``.


@pytest.mark.tier1
@pytest.mark.parametrize('name', **parametrized(valid_data_list()))
def test_positive_CRUDL(name):
    """Create, Read, Update, Delete, List

    :id: a2a577db-144e-4761-a42e-e83885464786

    :parametrized: yes

    :setup: User with reporting access rights

    :steps:

        1. Create Report Template
        2. List Report Templates, verify it's there
        3. Read Report Template
        4. Update Report Template, read again
示例#43
0
class TestContentViewFilter:
    """Tests for content view filters."""
    @pytest.mark.tier2
    def test_negative_get_with_no_args(self):
        """Issue an HTTP GET to the base content view filters path.

        :id: da29fd90-cd96-49f9-b94e-71d4e3a35a57

        :expectedresults: An HTTP 200 response is received if a GET request is
            issued with no arguments specified.

        :CaseLevel: Integration

        :CaseImportance: Low
        """
        response = client.get(
            entities.AbstractContentViewFilter().path(),
            auth=get_credentials(),
            verify=False,
        )
        assert response.status_code == http.client.OK

    @pytest.mark.tier2
    def test_negative_get_with_bad_args(self):
        """Issue an HTTP GET to the base content view filters path.

        :id: e6fea726-930b-4b74-b784-41528811994f

        :expectedresults: An HTTP 200 response is received if a GET request is
            issued with bad arguments specified.

        :CaseLevel: Integration

        :CaseImportance: Low
        """
        response = client.get(
            entities.AbstractContentViewFilter().path(),
            auth=get_credentials(),
            verify=False,
            data={'foo': 'bar'},
        )
        assert response.status_code == http.client.OK

    @pytest.mark.tier2
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    def test_positive_create_erratum_with_name(self, name, content_view):
        """Create new erratum content filter using different inputs as a name

        :id: f78a133f-441f-4fcc-b292-b9eed228d755

        :parametrized: yes

        :expectedresults: Content view filter created successfully and has
            correct name and type

        :CaseLevel: Integration
        """
        cvf = entities.ErratumContentViewFilter(content_view=content_view,
                                                name=name).create()
        assert cvf.name == name
        assert cvf.type == 'erratum'

    @pytest.mark.tier2
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    def test_positive_create_pkg_group_with_name(self, name, content_view):
        """Create new package group content filter using different inputs as a name

        :id: f9bfb6bf-a879-4f1a-970d-8f4df533cd59

        :parametrized: yes

        :expectedresults: Content view filter created successfully and has
            correct name and type

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        cvf = entities.PackageGroupContentViewFilter(
            content_view=content_view,
            name=name,
        ).create()
        assert cvf.name == name
        assert cvf.type == 'package_group'

    @pytest.mark.tier2
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    def test_positive_create_rpm_with_name(self, name, content_view):
        """Create new RPM content filter using different inputs as a name

        :id: f1c88e72-7993-47ac-8fbc-c749d32bc768

        :parametrized: yes

        :expectedresults: Content view filter created successfully and has
            correct name and type

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        cvf = entities.RPMContentViewFilter(content_view=content_view,
                                            name=name).create()
        assert cvf.name == name
        assert cvf.type == 'rpm'

    @pytest.mark.tier2
    @pytest.mark.parametrize('inclusion', [True, False])
    def test_positive_create_with_inclusion(self, inclusion, content_view):
        """Create new content view filter with different inclusion values

        :id: 81130dc9-ae33-48bc-96a7-d54d3e99448e

        :parametrized: yes

        :expectedresults: Content view filter created successfully and has
            correct inclusion value

        :CaseLevel: Integration
        """
        cvf = entities.RPMContentViewFilter(content_view=content_view,
                                            inclusion=inclusion).create()
        assert cvf.inclusion == inclusion

    @pytest.mark.tier2
    @pytest.mark.parametrize('description', **parametrized(valid_data_list()))
    def test_positive_create_with_description(self, description, content_view):
        """Create new content filter using different inputs as a description

        :id: e057083f-e69d-46e7-b336-45faaf67fa52

        :parametrized: yes

        :expectedresults: Content view filter created successfully and has
            correct description

        :CaseLevel: Integration

        :CaseImportance: Low
        """
        cvf = entities.RPMContentViewFilter(
            content_view=content_view,
            description=description,
        ).create()
        assert cvf.description == description

    @pytest.mark.tier2
    def test_positive_create_with_repo(self, content_view, sync_repo):
        """Create new content filter with repository assigned

        :id: 7207d4cf-3ccf-4d63-a50a-1373b16062e2

        :expectedresults: Content view filter created successfully and has
            repository assigned

        :CaseLevel: Integration
        """
        cvf = entities.RPMContentViewFilter(
            content_view=content_view,
            inclusion=True,
            repository=[sync_repo],
        ).create()
        assert cvf.repository[0].id == sync_repo.id

    @pytest.mark.tier2
    @pytest.mark.parametrize('original_packages', [True, False])
    def test_positive_create_with_original_packages(self, original_packages,
                                                    content_view, sync_repo):
        """Create new content view filter with different 'original packages'
        option values

        :id: 789abd8a-9e9f-4c7c-b1ac-6b69f23f77dd

        :parametrized: yes

        :expectedresults: Content view filter created successfully and has
            'original packages' value

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        cvf = entities.RPMContentViewFilter(
            content_view=content_view,
            inclusion=True,
            repository=[sync_repo],
            original_packages=original_packages,
        ).create()
        assert cvf.original_packages == original_packages

    @pytest.mark.tier2
    def test_positive_create_with_docker_repos(self, module_product, sync_repo,
                                               content_view):
        """Create new docker repository and add to content view that has yum
        repo already assigned to it. Create new content view filter and assign
        it to the content view.

        :id: 2cd28bf3-cd8a-4943-8e63-806d3676ada1

        :expectedresults: Content view filter created successfully and has both
            repositories assigned (yum and docker)

        :CaseLevel: Integration
        """
        docker_repository = entities.Repository(
            content_type='docker',
            docker_upstream_name='busybox',
            product=module_product.id,
            url=CONTAINER_REGISTRY_HUB,
        ).create()
        content_view.repository = [sync_repo, docker_repository]
        content_view.update(['repository'])

        cvf = entities.RPMContentViewFilter(
            content_view=content_view,
            inclusion=True,
            repository=[sync_repo, docker_repository],
        ).create()
        assert len(cvf.repository) == 2
        for repo in cvf.repository:
            assert repo.id in (sync_repo.id, docker_repository.id)

    @pytest.mark.tier2
    @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL),
                        reason='Missing repos_hosting_url')
    def test_positive_create_with_module_streams(self, module_product,
                                                 sync_repo,
                                                 sync_repo_module_stream,
                                                 content_view):
        """Verify Include and Exclude Filters creation for modulemd (module streams)

        :id: 4734dcca-ea5b-47d6-8f5f-239da0dc7629

        :expectedresults: Content view filter created successfully for both
            Include and Exclude Type

        :CaseLevel: Integration
        """
        content_view.repository += [sync_repo_module_stream]
        content_view.update(['repository'])
        for inclusion in (True, False):
            cvf = entities.ModuleStreamContentViewFilter(
                content_view=content_view,
                inclusion=inclusion,
                repository=[sync_repo, sync_repo_module_stream],
            ).create()
            assert cvf.inclusion == inclusion
            assert len(cvf.repository) == 2
        assert content_view.id == cvf.content_view.id
        assert cvf.type == 'modulemd'

    @pytest.mark.tier2
    @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL),
                        reason='Missing repos_hosting_url')
    def test_positive_publish_with_content_view_filter_and_swid_tags(
            self, module_org, module_product):
        """Verify SWID tags content file should exist in publish content view
        version location even after applying content view filters.

        :id: 00ac640f-1dfc-4083-8405-5164650d71b5

        :steps:
            1. create product and repository with custom contents having swid tags
            2. sync the repository
            3. create the content view
            4. create content view filter
            5. apply content view filter to repository
            6. publish the content-view
            7. ssh into Satellite
            8. verify SWID tags content file exist in publish content view version location

        :expectedresults: SWID tags content file should exist in publish content view
            version location

        :CaseAutomation: Automated

        :CaseImportance: Critical

        :CaseLevel: Integration
        """
        swid_tag_repository = entities.Repository(
            product=module_product, url=CUSTOM_SWID_TAG_REPO).create()
        swid_tag_repository.sync()
        content_view = entities.ContentView(organization=module_org).create()
        content_view.repository = [swid_tag_repository]
        content_view.update(['repository'])

        cv_filter = entities.RPMContentViewFilter(
            content_view=content_view,
            inclusion=True,
            repository=[swid_tag_repository],
        ).create()
        assert len(cv_filter.repository) == 1
        cv_filter_rule = entities.ContentViewFilterRule(
            content_view_filter=cv_filter, name='walrus',
            version='1.0').create()
        assert cv_filter.id == cv_filter_rule.content_view_filter.id
        content_view.publish()
        content_view = content_view.read()
        content_view_version_info = content_view.version[0].read()
        assert len(content_view.repository) == 1
        assert len(content_view.version) == 1
        swid_repo_path = "{}/{}/content_views/{}/{}/custom/{}/{}/repodata".format(
            CUSTOM_REPODATA_PATH,
            module_org.name,
            content_view.name,
            content_view_version_info.version,
            module_product.name,
            swid_tag_repository.name,
        )
        result = ssh.command(f'ls {swid_repo_path} | grep swidtags.xml.gz')
        assert result.return_code == 0

    @pytest.mark.tier2
    @pytest.mark.parametrize('name', **parametrized(invalid_names_list()))
    def test_negative_create_with_invalid_name(self, name, content_view):
        """Try to create content view filter using invalid names only

        :id: 8cf4227b-75c4-4d6f-b94f-88e4eb586435

        :parametrized: yes

        :expectedresults: Content view filter was not created

        :CaseLevel: Integration

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.RPMContentViewFilter(content_view=content_view,
                                          name=name).create()

    @pytest.mark.tier2
    def test_negative_create_with_same_name(self, content_view):
        """Try to create content view filter using same name twice

        :id: 73a64ca7-07a3-49ee-8921-0474a16a23ff

        :expectedresults: Second content view filter was not created

        :CaseLevel: Integration

        :CaseImportance: Low
        """
        kwargs = {'content_view': content_view, 'name': gen_string('alpha')}
        entities.RPMContentViewFilter(**kwargs).create()
        with pytest.raises(HTTPError):
            entities.RPMContentViewFilter(**kwargs).create()

    @pytest.mark.tier2
    def test_negative_create_without_cv(self):
        """Try to create content view filter without providing content
        view

        :id: 3b5af53f-9533-482f-9ec9-b313cbb91dd7

        :expectedresults: Content view filter is not created

        :CaseLevel: Integration

        :CaseImportance: Low
        """
        with pytest.raises(HTTPError):
            entities.RPMContentViewFilter(content_view=None).create()

    @pytest.mark.tier2
    def test_negative_create_with_invalid_repo_id(self, content_view):
        """Try to create content view filter using incorrect repository
        id

        :id: aa427770-c327-4ca1-b67f-a9a94edca784

        :expectedresults: Content view filter is not created

        :CaseLevel: Integration

        :CaseImportance: Low
        """
        with pytest.raises(HTTPError):
            entities.RPMContentViewFilter(
                content_view=content_view,
                repository=[gen_integer(10000, 99999)],
            ).create()

    @pytest.mark.tier2
    def test_positive_delete_by_id(self, content_view):
        """Delete content view filter

        :id: 07caeb9d-419d-43f8-996b-456b0cc0f70d

        :expectedresults: Content view filter was deleted

        :CaseLevel: Integration

        :CaseImportance: Critical
        """
        cvf = entities.RPMContentViewFilter(content_view=content_view).create()
        cvf.delete()
        with pytest.raises(HTTPError):
            cvf.read()

    @pytest.mark.tier2
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    def test_positive_update_name(self, name, content_view):
        """Update content view filter with new name

        :id: f310c161-00d2-4281-9721-6e45cbc5e4ec

        :parametrized: yes

        :expectedresults: Content view filter updated successfully and name was
            changed

        :CaseLevel: Integration
        """
        cvf = entities.RPMContentViewFilter(content_view=content_view).create()
        cvf.name = name
        assert cvf.update(['name']).name == name

    @pytest.mark.tier2
    @pytest.mark.parametrize('description', **parametrized(valid_data_list()))
    def test_positive_update_description(self, description, content_view):
        """Update content view filter with new description

        :id: f2c5db28-0163-4cf3-929a-16ba1cb98c34

        :parametrized: yes

        :expectedresults: Content view filter updated successfully and
            description was changed

        :CaseLevel: Integration

        :CaseImportance: Low
        """
        cvf = entities.RPMContentViewFilter(content_view=content_view).create()
        cvf.description = description
        cvf = cvf.update(['description'])
        assert cvf.description == description

    @pytest.mark.tier2
    @pytest.mark.parametrize('inclusion', [True, False])
    def test_positive_update_inclusion(self, inclusion, content_view):
        """Update content view filter with new inclusion value

        :id: 0aedd2d6-d020-4a90-adcd-01694b47c0b0

        :parametrized: yes

        :expectedresults: Content view filter updated successfully and
            inclusion value was changed

        :CaseLevel: Integration
        """
        cvf = entities.RPMContentViewFilter(content_view=content_view).create()
        cvf.inclusion = inclusion
        cvf = cvf.update(['inclusion'])
        assert cvf.inclusion == inclusion

    @pytest.mark.tier2
    def test_positive_update_repo(self, module_product, sync_repo,
                                  content_view):
        """Update content view filter with new repository

        :id: 329ef155-c2d0-4aa2-bac3-79087ae49bdf

        :expectedresults: Content view filter updated successfully and has new
            repository assigned

        :CaseLevel: Integration
        """
        cvf = entities.RPMContentViewFilter(
            content_view=content_view,
            inclusion=True,
            repository=[sync_repo],
        ).create()
        new_repo = entities.Repository(product=module_product).create()
        new_repo.sync()
        content_view.repository = [new_repo]
        content_view.update(['repository'])
        cvf.repository = [new_repo]
        cvf = cvf.update(['repository'])
        assert len(cvf.repository) == 1
        assert cvf.repository[0].id == new_repo.id

    @pytest.mark.tier2
    def test_positive_update_repos(self, module_product, sync_repo,
                                   content_view):
        """Update content view filter with multiple repositories

        :id: 478fbb1c-fa1d-4fcd-93d6-3a7f47092ed3

        :expectedresults: Content view filter updated successfully and has new
            repositories assigned

        :CaseLevel: Integration

        :CaseImportance: Low
        """
        cvf = entities.RPMContentViewFilter(
            content_view=content_view,
            inclusion=True,
            repository=[sync_repo],
        ).create()
        repos = [
            entities.Repository(product=module_product).create()
            for _ in range(randint(3, 5))
        ]
        for repo in repos:
            repo.sync()
        content_view.repository = repos
        content_view.update(['repository'])
        cvf.repository = repos
        cvf = cvf.update(['repository'])
        assert {repo.id
                for repo in cvf.repository} == {repo.id
                                                for repo in repos}

    @pytest.mark.tier2
    @pytest.mark.parametrize('original_packages', [True, False])
    def test_positive_update_original_packages(self, original_packages,
                                               sync_repo, content_view):
        """Update content view filter with new 'original packages' option value

        :id: 0c41e57a-afa3-479e-83ba-01f09f0fd2b6

        :parametrized: yes

        :expectedresults: Content view filter updated successfully and
            'original packages' value was changed

        :CaseLevel: Integration
        """
        cvf = entities.RPMContentViewFilter(
            content_view=content_view,
            inclusion=True,
            repository=[sync_repo],
        ).create()
        cvf.original_packages = original_packages
        cvf = cvf.update(['original_packages'])
        assert cvf.original_packages == original_packages

    @pytest.mark.tier2
    def test_positive_update_repo_with_docker(self, module_product, sync_repo,
                                              content_view):
        """Update existing content view filter which has yum repository
        assigned with new docker repository

        :id: 909db0c9-764a-4ca8-9b56-cd8fedd543eb

        :expectedresults: Content view filter was updated successfully and has
            both repositories assigned (yum and docker)

        :CaseLevel: Integration
        """
        cvf = entities.RPMContentViewFilter(
            content_view=content_view,
            inclusion=True,
            repository=[sync_repo],
        ).create()
        docker_repository = entities.Repository(
            content_type='docker',
            docker_upstream_name='busybox',
            product=module_product.id,
            url=CONTAINER_REGISTRY_HUB,
        ).create()
        content_view.repository = [sync_repo, docker_repository]
        content_view = content_view.update(['repository'])
        cvf.repository = [sync_repo, docker_repository]
        cvf = cvf.update(['repository'])
        assert len(cvf.repository) == 2
        for repo in cvf.repository:
            assert repo.id in (sync_repo.id, docker_repository.id)

    @pytest.mark.tier2
    @pytest.mark.parametrize('name', **parametrized(invalid_names_list()))
    def test_negative_update_name(self, name, content_view):
        """Try to update content view filter using invalid names only

        :id: 9799648a-3900-4186-8271-6b2dedb547ab

        :parametrized: yes

        :expectedresults: Content view filter was not updated

        :CaseLevel: Integration

        :CaseImportance: Low
        """
        cvf = entities.RPMContentViewFilter(content_view=content_view).create()
        cvf.name = name
        with pytest.raises(HTTPError):
            cvf.update(['name'])

    @pytest.mark.tier2
    def test_negative_update_same_name(self, content_view):
        """Try to update content view filter's name to already used one

        :id: b68569f1-9f7b-4a95-9e2a-a5da348abff7

        :expectedresults: Content view filter was not updated

        :CaseLevel: Integration

        :CaseImportance: Low
        """
        name = gen_string('alpha', 8)
        entities.RPMContentViewFilter(content_view=content_view,
                                      name=name).create()
        cvf = entities.RPMContentViewFilter(content_view=content_view).create()
        cvf.name = name
        with pytest.raises(HTTPError):
            cvf.update(['name'])

    @pytest.mark.tier2
    def test_negative_update_cv_by_id(self, content_view):
        """Try to update content view filter using incorrect content
        view ID

        :id: a6477d5f-e4d2-44ba-84f5-8f9004b52eb2

        :expectedresults: Content view filter was not updated

        :CaseLevel: Integration
        """
        cvf = entities.RPMContentViewFilter(content_view=content_view).create()
        cvf.content_view.id = gen_integer(10000, 99999)
        with pytest.raises(HTTPError):
            cvf.update(['content_view'])

    @pytest.mark.tier2
    def test_negative_update_repo_by_id(self, sync_repo, content_view):
        """Try to update content view filter using incorrect repository
        ID

        :id: 43ded66a-331c-4160-820d-261f973a7be2

        :expectedresults: Content view filter was not updated

        :CaseLevel: Integration
        """
        cvf = entities.RPMContentViewFilter(
            content_view=content_view,
            repository=[sync_repo],
        ).create()
        cvf.repository[0].id = gen_integer(10000, 99999)
        with pytest.raises(HTTPError):
            cvf.update(['repository'])

    @pytest.mark.tier2
    def test_negative_update_repo(self, module_product, sync_repo,
                                  content_view):
        """Try to update content view filter with new repository which doesn't
        belong to filter's content view

        :id: e11ba045-da8a-4f26-a0b9-3b1149358717

        :expectedresults: Content view filter was not updated

        :CaseLevel: Integration

        :CaseImportance: Low
        """
        cvf = entities.RPMContentViewFilter(
            content_view=content_view,
            inclusion=True,
            repository=[sync_repo],
        ).create()
        new_repo = entities.Repository(product=module_product).create()
        new_repo.sync()
        cvf.repository = [new_repo]
        with pytest.raises(HTTPError):
            cvf.update(['repository'])
示例#44
0
class TestContentViewFilter:
    """Content View Filter CLI tests"""
    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    @pytest.mark.parametrize('filter_content_type',
                             ['rpm', 'package_group', 'erratum', 'modulemd'])
    def test_positive_create_with_name_by_cv_id(self, name,
                                                filter_content_type,
                                                module_org, content_view):
        """Create new content view filter and assign it to existing content
        view by id. Use different value types as a name and random filter
        content type as a parameter for this filter

        :id: 2cfdf72e-179d-4bba-8aab-288594cac836

        :parametrized: yes

        :expectedresults: Content view filter created successfully and has
            correct and expected parameters

        :CaseImportance: Critical
        """
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': name,
                'organization-id': module_org.id,
                'type': filter_content_type,
            }, )
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': name
        })
        assert cvf['name'] == name
        assert cvf['type'] == filter_content_type

    @pytest.mark.tier1
    @pytest.mark.parametrize('filter_content_type',
                             ['rpm', 'package_group', 'erratum', 'modulemd'])
    def test_positive_create_with_content_type_by_cv_id(
            self, filter_content_type, module_org, content_view):
        """Create new content view filter and assign it to existing content
        view by id. Use different content types as a parameter

        :id: b3e5a58b-eddc-4ceb-ae34-6c0ab5664784

        :parametrized: yes

        :expectedresults: Content view filter created successfully and has
            correct and expected parameters

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': cvf_name,
                'organization-id': module_org.id,
                'type': filter_content_type,
            }, )
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        assert cvf['type'] == filter_content_type

    @pytest.mark.tier1
    @pytest.mark.parametrize('inclusion', ['true', 'false'])
    def test_positive_create_with_inclusion_by_cv_id(self, inclusion,
                                                     module_org, content_view):
        """Create new content view filter and assign it to existing content
        view by id. Use different inclusions as a parameter

        :id: 4a18ee71-3f0d-4e8b-909e-999d722ebc0a

        :parametrized: yes

        :expectedresults: Content view filter created successfully and has
            correct and expected parameters

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'inclusion': inclusion,
                'name': cvf_name,
                'organization-id': module_org.id,
                'type': 'rpm',
            }, )
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        assert cvf['inclusion'] == inclusion

    @pytest.mark.tier1
    def test_positive_create_with_description_by_cv_id(self, module_org,
                                                       content_view):
        """Create new content view filter with description and assign it to
        existing content view.

        :id: e283a42a-122b-467c-8d00-d6487f657692

        :expectedresults: Content view filter created successfully and has
            proper description

        :CaseImportance: Low
        """
        description = gen_string('utf8')
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'description': description,
                'name': cvf_name,
                'organization-id': module_org.id,
                'type': 'package_group',
            }, )
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        assert cvf['description'] == description

    @pytest.mark.run_in_one_thread
    @pytest.mark.tier1
    def test_positive_create_with_default_taxonomies(self, module_org,
                                                     module_location,
                                                     content_view):
        """Create new content view filter and assign it to existing content
        view by name. Use default organization and location to find necessary
        content view

        :id: 5fd6db3f-5723-44a9-a138-864693680a2f

        :expectedresults: Content view filter created successfully and has
            correct and expected name

        :BZ: 1369609

        :CaseImportance: Critical
        """
        name = gen_string('alpha')
        Defaults.add({
            'param-name': 'organization_id',
            'param-value': module_org.id
        })
        Defaults.add({
            'param-name': 'location_id',
            'param-value': module_location.id
        })
        try:
            ContentView.filter.create(
                {
                    'content-view': content_view['name'],
                    'name': name,
                    'type': 'erratum',
                    'inclusion': 'true',
                }, )
            cvf = ContentView.filter.info({
                'content-view': content_view['name'],
                'name': name
            })
            assert cvf['name'] == name
        finally:
            Defaults.delete({'param-name': 'organization_id'})
            Defaults.delete({'param-name': 'location_id'})

    @pytest.mark.tier1
    def test_positive_list_by_name_and_org(self, module_org, content_view):
        """Create new content view filter and try to list it by its name and
        organization it belongs

        :id: e685892d-9dc3-48f2-8a09-8f861dceaf4e

        :expectedresults: Content view filter created and listed successfully

        :BZ: 1378018

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': cvf_name,
                'organization-id': module_org.id,
                'type': 'package_group',
            }, )
        cv_filters = ContentView.filter.list({
            'content-view':
            content_view['name'],
            'organization':
            module_org.name
        })
        assert len(cv_filters) >= 1
        assert cvf_name in [cvf['name'] for cvf in cv_filters]

    @pytest.mark.tier1
    def test_positive_create_by_cv_name(self, module_org, content_view):
        """Create new content view filter and assign it to existing content
        view by name. Use organization id for reference

        :id: 0fb2fbc2-0d81-451e-9b20-9e996e14c977

        :expectedresults: Content view filter created successfully

        :BZ: 1356906

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view': content_view['name'],
                'inclusion': 'true',
                'name': cvf_name,
                'organization-id': module_org.id,
                'type': 'package_group',
            }, )
        ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })

    @pytest.mark.tier1
    def test_positive_create_by_org_name(self, module_org, content_view):
        """Create new content view filter and assign it to existing content
        view by name. Use organization name for reference

        :id: 295847fe-51e4-483d-af2f-b972c8b5064c

        :expectedresults: Content view filter created successfully

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view': content_view['name'],
                'inclusion': 'false',
                'name': cvf_name,
                'organization': module_org.name,
                'type': 'erratum',
            }, )
        ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })

    @pytest.mark.tier1
    def test_positive_create_by_org_label(self, module_org, content_view):
        """Create new content view filter and assign it to existing content
        view by name. Use organization label for reference

        :id: f233e223-c08c-4ce1-b87a-9e055fdd7b83

        :expectedresults: Content view filter created successfully

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view': content_view['name'],
                'inclusion': 'true',
                'name': cvf_name,
                'organization-label': module_org.label,
                'type': 'erratum',
            }, )
        ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })

    @pytest.mark.tier1
    def test_positive_create_with_repo_by_id(self, module_org, sync_repo,
                                             content_view):
        """Create new content view filter and assign it to existing content
        view that has repository assigned to it. Use that repository id for
        proper filter assignment.

        :id: 6d517e09-6a6a-4eed-91fe-9459610c0062

        :expectedresults: Content view filter created successfully and has
            proper repository affected

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'inclusion': 'true',
                'name': cvf_name,
                'repository-ids': sync_repo['id'],
                'organization-id': module_org.id,
                'type': 'rpm',
            }, )
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        # Check that only one, specified above, repository is displayed
        assert len(cvf['repositories']) == 1
        assert cvf['repositories'][0]['name'] == sync_repo['name']

    @pytest.mark.tier1
    def test_positive_create_with_repo_by_name(self, module_org,
                                               module_product, sync_repo,
                                               content_view):
        """Create new content view filter and assign it to existing content
        view that has repository assigned to it. Use that repository name for
        proper filter assignment.

        :id: 1b38c7c1-c8cd-49af-adcf-9e05a9201767

        :expectedresults: Content view filter created successfully and has
            proper repository affected

        :BZ: 1228890

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'inclusion': 'false',
                'name': cvf_name,
                'product': module_product.name,
                'repositories': sync_repo['name'],
                'organization-id': module_org.id,
                'type': 'rpm',
            }, )
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        # Check that only one, specified above, repository is displayed
        assert len(cvf['repositories']) == 1
        assert cvf['repositories'][0]['name'] == sync_repo['name']

    @pytest.mark.tier1
    def test_positive_create_with_original_pkgs(self, sync_repo, content_view):
        """Create new content view filter and assign it to existing content
        view that has repository assigned to it. Enable 'original packages'
        option for that filter

        :id: 5491233a-9361-435f-87ad-dca97e6d5d2f

        :expectedresults: Content view filter created successfully and has
            proper repository affected

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'inclusion': 'true',
                'name': cvf_name,
                'original-packages': 'true',
                'repository-ids': sync_repo['id'],
                'type': 'rpm',
            }, )
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        assert cvf['repositories'][0]['name'] == sync_repo['name']

    @pytest.mark.tier2
    def test_positive_create_with_repos_yum_and_docker(self, module_org,
                                                       module_product,
                                                       sync_repo,
                                                       content_view):
        """Create new docker repository and add to content view that has yum
        repo already assigned to it. Create new content view filter and assign
        it to mentioned content view. Use these repositories id for proper
        filter assignment.

        :id: 8419a5fa-0530-42a7-964c-7c513443c5c8

        :expectedresults: Content view filter created successfully and has both
            repositories affected (yum and docker)
        """
        docker_repository = make_repository(
            {
                'content-type': 'docker',
                'docker-upstream-name': 'busybox',
                'organization-id': module_org.id,
                'product-id': module_product.id,
                'url': DOCKER_REGISTRY_HUB,
            }, )

        ContentView.add_repository({
            'id': content_view['id'],
            'repository-id': docker_repository['id']
        })
        repos = [sync_repo['id'], docker_repository['id']]
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'inclusion': 'true',
                'name': cvf_name,
                'repository-ids': repos,
                'organization-id': module_org.id,
                'type': 'rpm',
            }, )
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        assert len(cvf['repositories']) == 2
        for repo in cvf['repositories']:
            assert repo['id'] in repos

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
    def test_negative_create_with_invalid_name(self, name, module_org,
                                               content_view):
        """Try to create content view filter using invalid names only

        :id: f3497a23-6e34-4fee-9964-f95762fc737c

        :parametrized: yes

        :expectedresults: Content view filter is not created

        :CaseImportance: Low
        """
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.create(
                {
                    'content-view-id': content_view['id'],
                    'name': name,
                    'organization-id': module_org.id,
                    'type': 'rpm',
                }, )

    @pytest.mark.tier1
    def test_negative_create_with_same_name(self, module_org, content_view):
        """Try to create content view filter using same name twice

        :id: 7e7444f4-e2b5-406d-a210-49b4008c88d9

        :expectedresults: Second content view filter is not created

        :CaseImportance: Low
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': cvf_name,
                'organization-id': module_org.id,
                'type': 'rpm',
            }, )
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.create(
                {
                    'content-view-id': content_view['id'],
                    'name': cvf_name,
                    'organization-id': module_org.id,
                    'type': 'rpm',
                }, )

    @pytest.mark.tier1
    def test_negative_create_without_type(self, module_org, content_view):
        """Try to create content view filter without providing required
        parameter 'type'

        :id: 8af65427-d0f0-4661-b062-93e054079f44

        :expectedresults: Content view filter is not created

        :CaseImportance: Critical
        """
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.create(
                {
                    'content-view-id': content_view['id'],
                    'name': gen_string('utf8'),
                    'organization-id': module_org.id,
                }, )

    @pytest.mark.tier1
    def test_negative_create_without_cv(self):
        """Try to create content view filter without providing content
        view information which should be used as basis for filter

        :id: 4ed3828e-52e8-457c-a2af-bb03b00467e8

        :expectedresults: Content view filter is not created

        :CaseImportance: Critical
        """
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.create({
                'name': gen_string('utf8'),
                'type': 'rpm'
            })

    @pytest.mark.tier1
    def test_negative_create_with_invalid_repo_id(self, module_org,
                                                  content_view):
        """Try to create content view filter using incorrect repository

        :id: 21fdbeca-ad0a-4e29-93dc-f850b5639f4f

        :expectedresults: Content view filter is not created

        :CaseImportance: Critical
        """
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.create(
                {
                    'content-view-id': content_view['id'],
                    'name': gen_string('utf8'),
                    'repository-ids': gen_string('numeric', 6),
                    'organization-id': module_org.id,
                    'type': 'rpm',
                }, )

    @pytest.mark.tier2
    @pytest.mark.parametrize('new_name', **parametrized(valid_data_list()))
    def test_positive_update_name(self, new_name, module_org, content_view):
        """Create new content view filter and assign it to existing content
        view by id. Try to update that filter using different value types as a
        name

        :id: 70ba8916-5898-4911-9de8-21d2e0fb3df9

        :parametrized: yes

        :expectedresults: Content view filter updated successfully and has
            proper and expected name

        :CaseLevel: Integration

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        cvf = ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': cvf_name,
                'organization-id': module_org.id,
                'type': 'rpm',
            }, )
        ContentView.filter.update({
            'content-view-id': content_view['id'],
            'id': cvf['filter-id'],
            'new-name': new_name,
        })
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': new_name
        })
        assert cvf['name'] == new_name

    @pytest.mark.tier2
    def test_positive_update_repo_with_same_type(self, module_org,
                                                 module_product, sync_repo,
                                                 content_view):
        """Create new content view filter and apply it to existing content view
        that has repository assigned to it. Try to update that filter and
        change affected repository on another one.

        :id: b2f444fd-e65e-41ba-9941-620d3cdb260f

        :expectedresults: Content view filter updated successfully and has new
            repository affected

        :CaseLevel: Integration

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': cvf_name,
                'repository-ids': sync_repo['id'],
                'type': 'rpm',
            }, )
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        assert len(cvf['repositories']) == 1
        assert cvf['repositories'][0]['name'] == sync_repo['name']

        new_repo = make_repository(
            {
                'organization-id': module_org.id,
                'product-id': module_product.id
            }, )
        ContentView.add_repository({
            'id': content_view['id'],
            'repository-id': new_repo['id']
        })

        ContentView.filter.update({
            'content-view-id': content_view['id'],
            'name': cvf_name,
            'repository-ids': new_repo['id'],
        })

        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        assert len(cvf['repositories']) == 1
        assert cvf['repositories'][0]['name'] != sync_repo['name']
        assert cvf['repositories'][0]['name'] == new_repo['name']

    @pytest.mark.tier2
    @pytest.mark.upgrade
    def test_positive_update_repo_with_different_type(self, module_org,
                                                      module_product,
                                                      sync_repo, content_view):
        """Create new content view filter and apply it to existing content view
        that has repository assigned to it. Try to update that filter and
        change affected repository on another one. That new repository should
        have another type from initial one (e.g. yum->docker)

        :id: cf3daa0d-e918-4330-95ad-f88933579829

        :expectedresults: Content view filter updated successfully and has new
            repository affected

        :CaseLevel: Integration
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': cvf_name,
                'repository-ids': sync_repo['id'],
                'type': 'rpm',
            }, )
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        assert len(cvf['repositories']) == 1
        assert cvf['repositories'][0]['name'] == sync_repo['name']
        docker_repo = make_repository(
            {
                'content-type': 'docker',
                'docker-upstream-name': 'busybox',
                'organization-id': module_org.id,
                'product-id': module_product.id,
                'url': DOCKER_REGISTRY_HUB,
            }, )
        ContentView.add_repository({
            'id': content_view['id'],
            'repository-id': docker_repo['id']
        })
        ContentView.filter.update({
            'content-view-id': content_view['id'],
            'name': cvf_name,
            'repository-ids': docker_repo['id'],
        })
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        assert len(cvf['repositories']) == 1
        assert cvf['repositories'][0]['name'] != sync_repo['name']
        assert cvf['repositories'][0]['name'] == docker_repo['name']

    @pytest.mark.tier2
    def test_positive_update_inclusion(self, module_org, content_view):
        """Create new content view filter and assign it to existing content
        view by id. Try to update that filter and assign opposite inclusion
        value for it

        :id: 76b3c66d-8200-4cf0-8cd0-b57de4ff12b0

        :expectedresults: Content view filter updated successfully and has
            correct and expected value for inclusion parameter

        :CaseLevel: Integration
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'inclusion': 'true',
                'name': cvf_name,
                'organization-id': module_org.id,
                'type': 'rpm',
            }, )
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        assert cvf['inclusion'] == 'true'
        ContentView.filter.update({
            'content-view-id': content_view['id'],
            'name': cvf_name,
            'inclusion': 'false',
        })
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        assert cvf['inclusion'] == 'false'

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_name', **parametrized(invalid_values_list()))
    def test_negative_update_with_name(self, new_name, content_view):
        """Try to update content view filter using invalid names only

        :id: 6c40e452-f786-4e28-9f03-b1935b55b33a

        :parametrized: yes

        :expectedresults: Content view filter is not updated

        :BZ: 1328943

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create({
            'content-view-id': content_view['id'],
            'name': cvf_name,
            'type': 'rpm'
        })
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.update({
                'content-view-id': content_view['id'],
                'name': cvf_name,
                'new-name': new_name,
            })
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.info({
                'content-view-id': content_view['id'],
                'name': new_name
            })

    @pytest.mark.tier1
    def test_negative_update_with_same_name(self, module_org, content_view):
        """Try to update content view filter using name of already
        existing entity

        :id: 9c1b1c75-af57-4218-9e2d-e69d74f50e04

        :expectedresults: Content view filter is not updated

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': cvf_name,
                'organization-id': module_org.id,
                'type': 'rpm',
            }, )
        new_name = gen_string('alpha', 100)
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': new_name,
                'organization-id': module_org.id,
                'type': 'rpm',
            }, )
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.update({
                'content-view-id': content_view['id'],
                'name': new_name,
                'new-name': cvf_name,
            })

    @pytest.mark.tier1
    def test_negative_update_inclusion(self, module_org, content_view):
        """Try to update content view filter and assign incorrect inclusion
        value for it

        :id: 760400a8-49a5-4a31-924c-c232cb22ddad

        :expectedresults: Content view filter is not updated

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'inclusion': 'true',
                'name': cvf_name,
                'organization-id': module_org.id,
                'type': 'rpm',
            }, )
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.update({
                'content-view-id': content_view['id'],
                'inclusion': 'wrong_value',
                'name': cvf_name,
            })
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        assert cvf['inclusion'] == 'true'

    @pytest.mark.tier1
    def test_negative_update_with_non_existent_repo_id(self, sync_repo,
                                                       content_view):
        """Try to update content view filter using non-existing repository ID

        :id: 457af8c2-fb32-4164-9e19-98676f4ea063

        :expectedresults: Content view filter is not updated

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': cvf_name,
                'repository-ids': sync_repo['id'],
                'type': 'rpm',
            }, )
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.update({
                'content-view-id':
                content_view['id'],
                'name':
                cvf_name,
                'repository-ids':
                gen_string('numeric', 6),
            })

    @pytest.mark.tier1
    def test_negative_update_with_invalid_repo_id(self, module_org,
                                                  module_product, sync_repo,
                                                  content_view):
        """Try to update filter and assign repository which does not belong to
        filter content view

        :id: aa550619-c436-4184-bb29-2becadf69e5b

        :expectedresults: Content view filter is not updated

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': cvf_name,
                'repository-ids': sync_repo['id'],
                'type': 'rpm',
            }, )
        new_repo = make_repository(
            {
                'organization-id': module_org.id,
                'product-id': module_product.id
            }, )
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.update({
                'content-view-id': content_view['id'],
                'name': cvf_name,
                'repository-ids': new_repo['id'],
            })

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    def test_positive_delete_by_name(self, name, module_org, content_view):
        """Create new content view filter and assign it to existing content
        view by id. Try to delete that filter using different value types as a
        name

        :id: a01baf17-9c3c-4923-bfe0-865a4cbc4223

        :parametrized: yes

        :expectedresults: Content view filter deleted successfully

        :CaseImportance: Critical
        """
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': name,
                'organization-id': module_org.id,
                'type': 'rpm',
            }, )
        ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': name
        })
        ContentView.filter.delete({
            'content-view-id': content_view['id'],
            'name': name
        })
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.info({
                'content-view-id': content_view['id'],
                'name': name
            })

    @pytest.mark.tier1
    @pytest.mark.upgrade
    def test_positive_delete_by_id(self, module_org, content_view):
        """Create new content view filter and assign it to existing content
        view by id. Try to delete that filter using its id as a parameter

        :id: e3865a11-1ba0-481a-bfe0-f9235901946d

        :expectedresults: Content view filter deleted successfully

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': cvf_name,
                'organization-id': module_org.id,
                'type': 'rpm',
            }, )
        cvf = ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        ContentView.filter.delete({'id': cvf['filter-id']})
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.info({
                'content-view-id': content_view['id'],
                'name': cvf_name
            })

    @pytest.mark.tier1
    def test_positive_delete_by_org_name(self, module_org, content_view):
        """Create new content view filter and assign it to existing content
        view by id. Try to delete that filter using organization and content
        view names where that filter was applied

        :id: 61b25ae5-98d5-4b7d-9197-2b1935054a92

        :expectedresults: Content view filter deleted successfully

        :CaseImportance: Critical
        """
        cvf_name = gen_string('utf8')
        ContentView.filter.create(
            {
                'content-view-id': content_view['id'],
                'name': cvf_name,
                'organization-id': module_org.id,
                'type': 'rpm',
            }, )
        ContentView.filter.info({
            'content-view-id': content_view['id'],
            'name': cvf_name
        })
        ContentView.filter.delete({
            'content-view': content_view['name'],
            'name': cvf_name,
            'organization': module_org.name,
        })
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.info({
                'content-view-id': content_view['id'],
                'name': cvf_name
            })

    @pytest.mark.tier1
    def test_negative_delete_by_name(self, content_view):
        """Try to delete non-existent filter using generated name

        :id: 84509061-6652-4594-b68a-4566c04bc289

        :expectedresults: System returned error

        :CaseImportance: Critical
        """
        with pytest.raises(CLIReturnCodeError):
            ContentView.filter.delete({
                'content-view-id': content_view['id'],
                'name': gen_string('utf8')
            })
示例#45
0
class TestUser:
    """Tests for the ``users`` path."""
    @pytest.mark.tier1
    @pytest.mark.parametrize('username',
                             **parametrized(valid_usernames_list()))
    def test_positive_create_with_username(self, username):
        """Create User for all variations of Username

        :id: a9827cda-7f6d-4785-86ff-3b6969c9c00a

        :parametrized: yes

        :expectedresults: User is created

        :CaseImportance: Critical
        """
        user = entities.User(login=username).create()
        assert user.login == username

    @pytest.mark.tier1
    @pytest.mark.parametrize('firstname',
                             **parametrized(
                                 generate_strings_list(exclude_types=['html'],
                                                       max_length=50)))
    def test_positive_create_with_firstname(self, firstname):
        """Create User for all variations of First Name

        :id: 036bb958-227c-420c-8f2b-c607136f12e0

        :parametrized: yes

        :expectedresults: User is created

        :CaseImportance: Critical
        """
        if len(str.encode(firstname)) > 50:
            firstname = firstname[:20]
        user = entities.User(firstname=firstname).create()
        assert user.firstname == firstname

    @pytest.mark.tier1
    @pytest.mark.parametrize('lastname',
                             **parametrized(
                                 generate_strings_list(exclude_types=['html'],
                                                       max_length=50)))
    def test_positive_create_with_lastname(self, lastname):
        """Create User for all variations of Last Name

        :id: 95d3b571-77e7-42a1-9c48-21f242e8cdc2

        :parametrized: yes

        :expectedresults: User is created

        :CaseImportance: Critical
        """
        if len(str.encode(lastname)) > 50:
            lastname = lastname[:20]
        user = entities.User(lastname=lastname).create()
        assert user.lastname == lastname

    @pytest.mark.tier1
    @pytest.mark.parametrize('mail', **parametrized(valid_emails_list()))
    def test_positive_create_with_email(self, mail):
        """Create User for all variations of Email

        :id: e68caf51-44ba-4d32-b79b-9ab9b67b9590

        :parametrized: yes

        :expectedresults: User is created

        :CaseImportance: Critical
        """
        user = entities.User(mail=mail).create()
        assert user.mail == mail

    @pytest.mark.tier1
    @pytest.mark.parametrize('description', **parametrized(valid_data_list()))
    def test_positive_create_with_description(self, description):
        """Create User for all variations of Description

        :id: 1463d71c-b77d-4223-84fa-8370f77b3edf

        :parametrized: yes

        :expectedresults: User is created

        :CaseImportance: Critical
        """
        user = entities.User(description=description).create()
        assert user.description == description

    @pytest.mark.tier1
    @pytest.mark.parametrize('password',
                             **parametrized(
                                 generate_strings_list(exclude_types=['html'],
                                                       max_length=50)))
    def test_positive_create_with_password(self, password):
        """Create User for all variations of Password

        :id: 53d0a419-0730-4f7d-9170-d855adfc5070

        :parametrized: yes

        :expectedresults: User is created

        :CaseImportance: Critical
        """
        user = entities.User(password=password).create()
        assert user is not None

    @pytest.mark.tier1
    @pytest.mark.upgrade
    @pytest.mark.parametrize('mail', **parametrized(valid_emails_list()))
    def test_positive_delete(self, mail):
        """Create random users and then delete it.

        :id: df6059e7-85c5-42fa-99b5-b7f1ef809f52

        :parametrized: yes

        :expectedresults: The user cannot be fetched after deletion.

        :CaseImportance: Critical
        """
        user = entities.User(mail=mail).create()
        user.delete()
        with pytest.raises(HTTPError):
            user.read()

    @pytest.mark.tier1
    @pytest.mark.parametrize('login', **parametrized(valid_usernames_list()))
    def test_positive_update_username(self, create_user, login):
        """Update a user and provide new username.

        :id: a8e218b1-7256-4f20-91f3-3958d58ea5a8

        :parametrized: yes

        :expectedresults: The user's ``Username`` attribute is updated.

        :CaseImportance: Critical
        """
        create_user.login = login
        user = create_user.update(['login'])
        assert user.login == login

    @pytest.mark.tier1
    @pytest.mark.parametrize('login', **parametrized(invalid_usernames_list()))
    def test_negative_update_username(self, create_user, login):
        """Update a user and provide new login.

        :id: 9eefcba6-66a3-41bf-87ba-3e032aee1db2

        :parametrized: yes

        :expectedresults: The user's ``login`` attribute is updated.

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            create_user.login = login
            create_user.update(['login'])

    @pytest.mark.tier1
    @pytest.mark.parametrize('firstname',
                             **parametrized(
                                 generate_strings_list(exclude_types=['html'],
                                                       max_length=50)))
    def test_positive_update_firstname(self, create_user, firstname):
        """Update a user and provide new firstname.

        :id: a1287d47-e7d8-4475-abe8-256e6f2034fc

        :parametrized: yes

        :expectedresults: The user's ``firstname`` attribute is updated.

        :CaseImportance: Critical
        """
        if len(str.encode(firstname)) > 50:
            firstname = firstname[:20]
        create_user.firstname = firstname
        user = create_user.update(['firstname'])
        assert user.firstname == firstname

    @pytest.mark.tier1
    @pytest.mark.parametrize('lastname',
                             **parametrized(
                                 generate_strings_list(exclude_types=['html'],
                                                       max_length=50)))
    def test_positive_update_lastname(self, create_user, lastname):
        """Update a user and provide new lastname.

        :id: 25c6c9df-5db2-4827-89bb-b8fd0658a9b9

        :parametrized: yes

        :expectedresults: The user's ``lastname`` attribute is updated.

        :CaseImportance: Critical
        """
        if len(str.encode(lastname)) > 50:
            lastname = lastname[:20]
        create_user.lastname = lastname
        user = create_user.update(['lastname'])
        assert user.lastname == lastname

    @pytest.mark.tier1
    @pytest.mark.parametrize('mail', **parametrized(valid_emails_list()))
    def test_positive_update_email(self, create_user, mail):
        """Update a user and provide new email.

        :id: 3ae70631-7cee-4a4a-9c2f-b428273f1311

        :parametrized: yes

        :expectedresults: The user's ``mail`` attribute is updated.

        :CaseImportance: Critical
        """
        create_user.mail = mail
        user = create_user.update(['mail'])
        assert user.mail == mail

    @pytest.mark.tier1
    @pytest.mark.parametrize('mail', **parametrized(invalid_emails_list()))
    def test_negative_update_email(self, create_user, mail):
        """Update a user and provide new email.

        :id: 0631dce1-694c-4815-971d-26ff1934da98

        :parametrized: yes

        :expectedresults: The user's ``mail`` attribute is updated.

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            create_user.mail = mail
            create_user.update(['mail'])

    @pytest.mark.tier1
    @pytest.mark.parametrize('description', **parametrized(valid_data_list()))
    def test_positive_update_description(self, create_user, description):
        """Update a user and provide new email.

        :id: a1d764ad-e9bb-4e5e-b8cd-3c52e1f128f6

        :parametrized: yes

        :expectedresults: The user's ``Description`` attribute is updated.

        :CaseImportance: Critical
        """
        create_user.description = description
        user = create_user.update(['description'])
        assert user.description == description

    @pytest.mark.tier1
    @pytest.mark.parametrize('admin_enable', [True, False])
    def test_positive_update_admin(self, admin_enable):
        """Update a user and provide the ``admin`` attribute.

        :id: b5fedf65-37f5-43ca-806a-ac9a7979b19d

        :parametrized: yes

        :expectedresults: The user's ``admin`` attribute is updated.

        :CaseImportance: Critical
        """
        user = entities.User(admin=admin_enable).create()
        user.admin = not admin_enable
        assert user.update().admin == (not admin_enable)

    @pytest.mark.tier1
    @pytest.mark.parametrize('mail', **parametrized(invalid_emails_list()))
    def test_negative_create_with_invalid_email(self, mail):
        """Create User with invalid Email Address

        :id: ebbd1f5f-e71f-41f4-a956-ce0071b0a21c

        :parametrized: yes

        :expectedresults: User is not created. Appropriate error shown.

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.User(mail=mail).create()

    @pytest.mark.tier1
    @pytest.mark.parametrize('invalid_name',
                             **parametrized(invalid_usernames_list()))
    def test_negative_create_with_invalid_username(self, invalid_name):
        """Create User with invalid Username

        :id: aaf157a9-0375-4405-ad87-b13970e0609b

        :parametrized: yes

        :expectedresults: User is not created. Appropriate error shown.

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.User(login=invalid_name).create()

    @pytest.mark.tier1
    @pytest.mark.parametrize('invalid_name',
                             **parametrized(invalid_names_list()))
    def test_negative_create_with_invalid_firstname(self, invalid_name):
        """Create User with invalid Firstname

        :id: cb1ca8a9-38b1-4d58-ae32-915b47b91657

        :parametrized: yes

        :expectedresults: User is not created. Appropriate error shown.

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.User(firstname=invalid_name).create()

    @pytest.mark.tier1
    @pytest.mark.parametrize('invalid_name',
                             **parametrized(invalid_names_list()))
    def test_negative_create_with_invalid_lastname(self, invalid_name):
        """Create User with invalid Lastname

        :id: 59546d26-2b6b-400b-990f-0b5d1c35004e

        :parametrized: yes

        :expectedresults: User is not created. Appropriate error shown.

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.User(lastname=invalid_name).create()

    @pytest.mark.tier1
    def test_negative_create_with_blank_authorized_by(self):
        """Create User with blank authorized by

        :id: 1fe2d1e3-728c-4d89-97ae-3890e904f413

        :expectedresults: User is not created. Appropriate error shown.

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.User(auth_source='').create()
示例#46
0
class TestOperatingSystem:
    """Test class for Operating System CLI."""

    @pytest.mark.tier1
    def test_positive_search_by_name(self):
        """Search for newly created OS by name

        :id: ff9f667c-97ca-49cd-902b-a9b18b5aa021

        :expectedresults: Operating System is created and listed

        :CaseImportance: Critical
        """
        os_list_before = OperatingSys.list()
        os = make_os()
        os_list = OperatingSys.list({'search': 'name=%s' % os['name']})
        os_info = OperatingSys.info({'id': os_list[0]['id']})
        assert os['id'] == os_info['id']
        os_list_after = OperatingSys.list()
        assert len(os_list_after) > len(os_list_before)

    @pytest.mark.tier1
    def test_positive_search_by_title(self):
        """Search for newly created OS by title

        :id: a555e848-f1f2-4326-aac6-9de8ff45abee

        :expectedresults: Operating System is created and listed

        :CaseImportance: Critical
        """
        os_list_before = OperatingSys.list()
        os = make_os()
        os_list = OperatingSys.list({'search': 'title=\\"%s\\"' % os['title']})
        os_info = OperatingSys.info({'id': os_list[0]['id']})
        assert os['id'] == os_info['id']
        os_list_after = OperatingSys.list()
        assert len(os_list_after) > len(os_list_before)

    @pytest.mark.tier1
    def test_positive_list(self):
        """Displays list for operating system

        :id: fca309c5-edff-4296-a800-55470669935a

        :expectedresults: Operating System is created and listed

        :CaseImportance: Critical
        """
        os_list_before = OperatingSys.list()
        name = gen_string('alpha')
        os = make_os({'name': name})
        os_list = OperatingSys.list({'search': 'name=%s' % name})
        os_info = OperatingSys.info({'id': os_list[0]['id']})
        assert os['id'] == os_info['id']
        os_list_after = OperatingSys.list()
        assert len(os_list_after) > len(os_list_before)

    @pytest.mark.tier1
    def test_positive_info_by_id(self):
        """Displays info for operating system by its ID

        :id: b8f23b53-439a-4726-9757-164d99d5ed05

        :expectedresults: Operating System is created and can be looked up by
            its ID

        :CaseImportance: Critical
        """
        os = make_os()
        os_info = OperatingSys.info({'id': os['id']})
        # Info does not return major or minor but a concat of name,
        # major and minor
        assert os['id'] == os_info['id']
        assert os['name'] == os_info['name']
        assert str(os['major-version']) == os_info['major-version']
        assert str(os['minor-version']) == os_info['minor-version']

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    def test_positive_create_with_name(self, name):
        """Create Operating System for all variations of name

        :id: d36eba9b-ccf6-4c9d-a07f-c74eebada89b

        :parametrized: yes

        :expectedresults: Operating System is created and can be found

        :CaseImportance: Critical
        """
        os = make_os({'name': name})
        assert os['name'] == name

    @pytest.mark.tier1
    def test_positive_create_with_arch_medium_ptable(self):
        """Create an OS pointing to an arch, medium and partition table.

        :id: 05bdb2c6-0d2e-4141-9e07-3ada3933b577

        :expectedresults: An operating system is created.

        :CaseImportance: Critical
        """
        architecture = make_architecture()
        medium = make_medium()
        ptable = make_partition_table()
        operating_system = make_os(
            {
                'architecture-ids': architecture['id'],
                'medium-ids': medium['id'],
                'partition-table-ids': ptable['id'],
            }
        )

        for attr in ('architectures', 'installation-media', 'partition-tables'):
            assert len(operating_system[attr]) == 1
        assert operating_system['architectures'][0] == architecture['name']
        assert operating_system['installation-media'][0] == medium['name']
        assert operating_system['partition-tables'][0] == ptable['name']

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
    def test_negative_create_with_name(self, name):
        """Create Operating System using invalid names

        :id: 848a20ce-292a-47d8-beea-da5916c43f11

        :parametrized: yes

        :expectedresults: Operating System is not created

        :CaseImportance: Critical
        """
        with pytest.raises(CLIFactoryError):
            make_os({'name': name})

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_name', **parametrized(valid_data_list()))
    def test_positive_update_name(self, new_name):
        """Positive update of operating system name

        :id: 49b655f7-ba9b-4bb9-b09d-0f7140969a40

        :parametrized: yes

        :expectedresults: Operating System name is updated

        :CaseImportance: Critical
        """
        os = make_os({'name': gen_alphanumeric()})
        OperatingSys.update({'id': os['id'], 'name': new_name})
        result = OperatingSys.info({'id': os['id']})
        assert result['id'] == os['id']
        assert result['name'] != os['name']

    @pytest.mark.tier1
    def test_positive_update_major_version(self):
        """Update an Operating System's major version.

        :id: 38a89dbe-6d1c-4602-a4c1-664425668de8

        :expectedresults: Operating System major version is updated

        :CaseImportance: Critical
        """
        os = make_os()
        # New value for major
        major = int(os['major-version']) + 1
        OperatingSys.update({'id': os['id'], 'major': major})
        os = OperatingSys.info({'id': os['id']})
        assert int(os['major-version']) == major

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_name', **parametrized(invalid_values_list()))
    def test_negative_update_name(self, new_name):
        """Negative update of system name

        :id: 4b18ff6d-7728-4245-a1ce-38e62c05f454

        :parametrized: yes

        :expectedresults: Operating System name is not updated

        :CaseImportance: Critical
        """
        os = make_os({'name': gen_alphanumeric()})
        with pytest.raises(CLIReturnCodeError):
            OperatingSys.update({'id': os['id'], 'name': new_name})
        result = OperatingSys.info({'id': os['id']})
        assert result['name'] == os['name']

    @pytest.mark.tier1
    @pytest.mark.upgrade
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    def test_positive_delete_by_id(self, name):
        """Successfully deletes Operating System by its ID

        :id: a67a7b01-081b-42f8-a9ab-1f41166d649e

        :parametrized: yes

        :expectedresults: Operating System is deleted

        :CaseImportance: Critical
        """
        os = make_os({'name': name})
        OperatingSys.delete({'id': os['id']})
        with pytest.raises(CLIReturnCodeError):
            OperatingSys.info({'id': os['id']})

    @pytest.mark.tier1
    @pytest.mark.parametrize('test_data', **parametrized(negative_delete_data()))
    def test_negative_delete_by_id(self, test_data):
        """Delete Operating System using invalid data

        :id: d29a9c95-1fe3-4a7a-9f7b-127be065856d

        :parametrized: yes

        :expectedresults: Operating System is not deleted

        :CaseImportance: Critical
        """
        os = make_os()
        # The delete method requires the ID which we will not pass
        with pytest.raises(CLIReturnCodeError):
            OperatingSys.delete(test_data)
        # Now make sure that it still exists
        result = OperatingSys.info({'id': os['id']})
        assert os['id'] == result['id']
        assert os['name'] == result['name']

    @pytest.mark.tier2
    def test_positive_add_arch(self):
        """Add Architecture to operating system

        :id: 99add22d-d936-4232-9441-beff85867040

        :expectedresults: Architecture is added to Operating System

        :CaseLevel: Integration
        """
        architecture = make_architecture()
        os = make_os()
        OperatingSys.add_architecture({'architecture-id': architecture['id'], 'id': os['id']})
        os = OperatingSys.info({'id': os['id']})
        assert len(os['architectures']) == 1
        assert architecture['name'] == os['architectures'][0]

    @pytest.mark.tier2
    @pytest.mark.upgrade
    def test_positive_add_template(self):
        """Add provisioning template to operating system

        :id: 0ea9eb88-2d27-423d-a9d3-fdd788b4e28a

        :expectedresults: Provisioning template is added to Operating System

        :CaseLevel: Integration
        """
        template = make_template()
        os = make_os()
        default_template_name = os['default-templates'][0]
        OperatingSys.add_provisioning_template(
            {'provisioning-template': template['name'], 'id': os['id']}
        )
        os = OperatingSys.info({'id': os['id']})
        assert len(os['templates']) == 2
        provision_template_name = f"{template['name']} ({template['type']})"
        assert default_template_name in os['templates']
        assert provision_template_name in os['templates']

    @pytest.mark.tier2
    def test_positive_add_ptable(self):
        """Add partition table to operating system

        :id: beba676f-b4e4-48e1-bb0c-18ad91847566

        :expectedresults: Partition table is added to Operating System

        :CaseLevel: Integration
        """
        # Create a partition table.
        ptable_name = make_partition_table()['name']
        # Create an operating system.
        os_id = make_os()['id']
        # Add the partition table to the operating system.
        OperatingSys.add_ptable({'id': os_id, 'partition-table': ptable_name})
        # Verify that the operating system has a partition table.
        os = OperatingSys.info({'id': os_id})
        assert len(os['partition-tables']) == 1
        assert os['partition-tables'][0] == ptable_name

    @pytest.mark.tier2
    def test_positive_update_parameters_attributes(self):
        """Update os-parameters-attributes to operating system

        :id: 5d566eea-b323-4128-9356-3bf39943e4d4

        :BZ: 1713553

        :expectedresults: Os-parameters-attributes are updated to Operating System
        """
        param_name = gen_string('alpha')
        param_value = gen_string('alpha')
        os_id = make_os()['id']
        OperatingSys.update(
            {
                'id': os_id,
                'os-parameters-attributes': 'name={}, value={}'.format(
                    param_name + '\\', param_value
                ),
            }
        )
        os = OperatingSys.info({'id': os_id}, output_format='json')
        assert param_name == os['parameters'][0]['name']
        assert param_value == os['parameters'][0]['value']
示例#47
0
class TestDiscoveryRule:
    """Implements Foreman discovery Rules tests in CLI."""
    @pytest.fixture(scope='function')
    def discoveryrule_factory(self, class_org, class_location,
                              class_hostgroup):
        def _create_discoveryrule(org, loc, hostgroup, options=None):
            """Makes a new discovery rule and asserts its success"""
            options = options or {}

            searches = [
                'cpu_count = 1',
                'disk_count < 5',
                'memory > 500',
                'model = KVM',
                'Organization = Default_Organization',
                'last_report = Today',
                'subnet =  192.168.100.0',
                'facts.architecture != x86_64',
            ]

            if not any(
                    options.get(key)
                    for key in ['organizations', 'organization-ids']):
                options['organization-ids'] = org.id
            if not any(
                    options.get(key)
                    for key in ['locations', 'locations-ids']):
                options['location-ids'] = loc.id
            if not any(
                    options.get(key)
                    for key in ['hostgroup', 'hostgroup-ids']):
                options['hostgroup-id'] = hostgroup.id
            if options.get('search') is None:
                options['search'] = gen_choice(searches)

            # create a simple object from the dictionary that the CLI factory provides
            # This allows for consistent attributized access of all fixture entities in the tests
            return AttrDict(make_discoveryrule(options))

        return partial(_create_discoveryrule,
                       org=class_org,
                       loc=class_location,
                       hostgroup=class_hostgroup)

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    def test_positive_create_with_name(self, name, discoveryrule_factory):
        """Create Discovery Rule using different names

        :id: 066e66bc-c572-4ae9-b458-90daf83bab54

        :expectedresults: Rule should be successfully created

        :CaseImportance: Critical

        :parametrized: yes
        """
        rule = discoveryrule_factory(options={'name': name})
        assert rule.name == name

    @pytest.mark.tier1
    def test_positive_create_with_search(self, discoveryrule_factory):
        """Create Discovery Rule using different search queries

        :id: 2383e898-a968-4183-a270-55e9350e0596

        :expectedresults: Rule should be successfully created and has expected
            search value

        :CaseImportance: Critical
        """
        search_query = 'cpu_count = 2'
        rule = discoveryrule_factory(options={'search': search_query})
        assert rule.search == search_query

    @pytest.mark.tier2
    def test_positive_create_with_hostname(self, discoveryrule_factory):
        """Create Discovery Rule using valid hostname

        :id: deee22c3-dcfd-4940-b27c-cca137ec9a92

        :expectedresults: Rule should be successfully created and has expected
            hostname value

        :CaseLevel: Component
        """
        host_name = 'myhost'
        rule = discoveryrule_factory(options={'hostname': host_name})
        assert rule['hostname-template'] == host_name

    @pytest.mark.tier1
    def test_positive_create_with_org_loc_id(self, discoveryrule_factory,
                                             class_org, class_location,
                                             class_hostgroup):
        """Create discovery rule by associating org and location ids

        :id: bdb4c581-d27a-4d1a-920b-89689e68a57f

        :expectedresults: Rule was created and with given org & location names.

        :BZ: 1377990, 1523221

        :CaseImportance: Critical
        """
        rule = discoveryrule_factory(
            options={
                'hostgroup-id': class_hostgroup.id,
                'organization-ids': class_org.id,
                'location-ids': class_location.id,
            })
        assert class_org.name in rule.organizations
        assert class_location.name in rule.locations

    @pytest.mark.tier2
    def test_positive_create_with_org_loc_name(self, discoveryrule_factory,
                                               class_org, class_location,
                                               class_hostgroup):
        """Create discovery rule by associating org and location names

        :id: f0d550ae-16d8-48ec-817e-d2e5b7405b46

        :expectedresults: Rule was created and with given org & location names.

        :BZ: 1377990
        """
        rule = discoveryrule_factory(
            options={
                'hostgroup-id': class_hostgroup.id,
                'organizations': class_org.name,
                'locations': class_location.name,
            })
        assert class_org.name in rule.organizations
        assert class_location.name in rule.locations

    @pytest.mark.tier2
    def test_positive_create_with_hosts_limit(self, discoveryrule_factory):
        """Create Discovery Rule providing any number from range 1..100 for
        hosts limit option

        :id: c28422c2-1f6a-4045-b722-f9f9d864e963

        :expectedresults: Rule should be successfully created and has expected
            hosts limit value

        :CaseLevel: Component
        """
        hosts_limit = '5'
        rule = discoveryrule_factory(options={'hosts-limit': hosts_limit})
        assert rule['hosts-limit'] == hosts_limit

    @pytest.mark.tier1
    def test_positive_create_with_max_count(self, discoveryrule_factory):
        """Create Discovery Rule providing any number from range 1..100 for
        max count option

        :id: 590ca353-d3d7-4700-be34-13de00f46276

        :expectedresults: Rule should be successfully created and has max_count
            set as per given value

        :CaseLevel: Component
        """
        max_count = '10'
        rule = discoveryrule_factory(options={'max-count': max_count})
        assert rule['hosts-limit'] == max_count

    @pytest.mark.tier1
    def test_positive_create_with_priority(self, discoveryrule_factory):
        """Create Discovery Rule providing any number from range 1..100 for
        priority option

        :id: 8ef58279-0ad3-41a4-b8dd-65594afdb655

        :expectedresults: Rule should be successfully created and has expected
            priority value

        :CaseImportance: Critical
        """
        available = set(range(
            1, 1000)) - {AttrDict(r).priority
                         for r in DiscoveryRule.list()}
        rule_priority = random.sample(available, 1)
        rule = discoveryrule_factory(options={'priority': rule_priority[0]})
        assert rule.priority == str(rule_priority[0])

    @pytest.mark.tier2
    def test_positive_create_disabled_rule(self, discoveryrule_factory):
        """Create Discovery Rule in disabled state

        :id: 8837a0c6-e19a-4c33-8b87-07b6f69dbb0f

        :expectedresults: Disabled rule should be successfully created

        :CaseLevel: Component
        """
        rule = discoveryrule_factory(options={'enabled': 'false'})
        assert rule.enabled == 'false'

    @pytest.mark.tier3
    @pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
    def test_negative_create_with_invalid_name(self, name,
                                               discoveryrule_factory):
        """Create Discovery Rule with invalid names

        :id: a0350dc9-8f5b-4673-be88-a5e35d1f8ca7

        :expectedresults: Error should be raised and rule should not be created

        :CaseImportance: Medium

        :CaseLevel: Component

        :parametrized: yes
        """
        with pytest.raises(CLIFactoryError):
            discoveryrule_factory(options={'name': name})

    @pytest.mark.tier3
    @pytest.mark.parametrize('name', **parametrized(invalid_hostnames_list()))
    def test_negative_create_with_invalid_hostname(self, name,
                                                   discoveryrule_factory):
        """Create Discovery Rule with invalid hostname

        :id: 0ae51085-30d0-44f9-9e49-abe928a8a4b7

        :expectedresults: Error should be raised and rule should not be created

        :CaseImportance: Medium

        :CaseLevel: Component

        :BZ: 1378427

        :parametrized: yes
        """
        with pytest.raises(CLIFactoryError):
            discoveryrule_factory(options={'hostname': name})

    @pytest.mark.tier3
    def test_negative_create_with_too_long_limit(self, discoveryrule_factory):
        """Create Discovery Rule with too long host limit value

        :id: 12dbb023-c963-4ead-a81e-ad53033de947

        :expectedresults: Validation error should be raised and rule should not
            be created

        :CaseImportance: Medium
        """
        with pytest.raises(CLIFactoryError):
            discoveryrule_factory(options={'hosts-limit': '9999999999'})

    @pytest.mark.tier1
    def test_negative_create_with_same_name(self, discoveryrule_factory):
        """Create Discovery Rule with name that already exists

        :id: 0906cf64-ed0b-49af-844f-1af22f81ab94

        :expectedresults: Error should be raised and rule should not be created

        :CaseImportance: Medium
        """
        name = gen_string('alpha')
        discoveryrule_factory(options={'name': name})
        with pytest.raises(CLIFactoryError):
            discoveryrule_factory(options={'name': name})

    @pytest.mark.tier1
    def test_positive_delete(self, discoveryrule_factory):
        """Delete existing Discovery Rule

        :id: c9b88a94-13c4-496f-a5c1-c088187250dc

        :expectedresults: Rule should be successfully deleted

        :CaseImportance: Critical
        """
        rule = discoveryrule_factory()
        DiscoveryRule.delete({'id': rule.id})
        with pytest.raises(CLIReturnCodeError):
            DiscoveryRule.info({'id': rule.id})

    @pytest.mark.tier3
    def test_positive_update_name(self, discoveryrule_factory):
        """Update discovery rule name

        :id: 1045e2c4-e1f7-42c9-95f7-488fc79bf70b

        :expectedresults: Rule name is updated

        :CaseLevel: Component

        :CaseImportance: Medium
        """
        rule = discoveryrule_factory()
        new_name = gen_string('numeric')
        DiscoveryRule.update({'id': rule.id, 'name': new_name})
        rule = AttrDict(DiscoveryRule.info({'id': rule.id}))
        assert rule.name == new_name

    @pytest.mark.tier2
    def test_positive_update_org_loc_by_id(self, discoveryrule_factory):
        """Update org and location of selected discovery rule using org/loc ids

        :id: 26da79aa-30e5-4052-98ae-141de071a68a

        :expectedresults: Rule was updated and with given org & location.

        :BZ: 1377990

        :CaseLevel: Component
        """
        new_org = AttrDict(make_org())
        new_loc = AttrDict(make_location())
        new_hostgroup = AttrDict(
            make_hostgroup({
                'organization-ids': new_org.id,
                'location-ids': new_loc.id
            }))
        rule = discoveryrule_factory()
        DiscoveryRule.update({
            'id': rule.id,
            'organization-ids': new_org.id,
            'location-ids': new_loc.id,
            'hostgroup-id': new_hostgroup.id,
        })
        rule = AttrDict(DiscoveryRule.info({'id': rule.id}))
        assert new_org.name in rule.organizations
        assert new_loc.name in rule.locations

    @pytest.mark.tier3
    def test_positive_update_org_loc_by_name(self, discoveryrule_factory):
        """Update org and location of selected discovery rule using org/loc
        names

        :id: 7a5d61ac-6a2d-48f6-a00d-df437a7dc3c4

        :expectedresults: Rule was updated and with given org & location.

        :BZ: 1377990

        :CaseLevel: Component

        :CaseImportance: Medium
        """
        new_org = AttrDict(make_org())
        new_loc = AttrDict(make_location())
        new_hostgroup = AttrDict(
            make_hostgroup({
                'organization-ids': new_org.id,
                'location-ids': new_loc.id
            }))
        rule = discoveryrule_factory()
        DiscoveryRule.update({
            'id': rule.id,
            'organizations': new_org.name,
            'locations': new_loc.name,
            'hostgroup-id': new_hostgroup.id,
        })
        rule = AttrDict(DiscoveryRule.info({'id': rule.id}))
        assert new_org.name in rule.organizations
        assert new_loc.name in rule.locations

    @pytest.mark.tier2
    def test_positive_update_query(self, discoveryrule_factory):
        """Update discovery rule search query

        :id: 86943095-acc5-40ff-8e3c-88c76b36333d

        :expectedresults: Rule search field is updated

        :CaseLevel: Component
        """
        rule = discoveryrule_factory()
        new_query = 'model = KVM'
        DiscoveryRule.update({'id': rule.id, 'search': new_query})
        rule = AttrDict(DiscoveryRule.info({'id': rule.id}))
        assert rule.search == new_query

    @pytest.mark.tier2
    def test_positive_update_hostgroup(self, discoveryrule_factory, class_org):
        """Update discovery rule host group

        :id: 07992a3f-2aa9-4e45-b2e8-ef3d2f255292

        :expectedresults: Rule host group is updated

        :CaseLevel: Component
        """
        new_hostgroup = AttrDict(
            make_hostgroup({'organization-ids': class_org.id}))
        rule = discoveryrule_factory()
        DiscoveryRule.update({'id': rule.id, 'hostgroup': new_hostgroup.name})
        rule = DiscoveryRule.info({'id': rule.id})
        # AttrDict doesn't support attributized access on key with a hyphen
        assert rule['host-group'] == new_hostgroup.name

    @pytest.mark.tier2
    def test_positive_update_hostname(self, discoveryrule_factory):
        """Update discovery rule hostname value

        :id: 4c123488-92df-42f6-afe3-8a88cd90ffc2

        :expectedresults: Rule host name is updated

        :CaseLevel: Component
        """
        new_hostname = gen_string('alpha')
        rule = discoveryrule_factory()
        DiscoveryRule.update({'id': rule.id, 'hostname': new_hostname})
        rule = AttrDict(DiscoveryRule.info({'id': rule.id}))
        assert rule['hostname-template'] == new_hostname

    @pytest.mark.tier2
    def test_positive_update_limit(self, discoveryrule_factory):
        """Update discovery rule limit value

        :id: efa6f5bc-4d56-4449-90f5-330affbcfb09

        :expectedresults: Rule host limit field is updated

        :CaseLevel: Component
        """
        rule = discoveryrule_factory(options={'hosts-limit': '5'})
        new_limit = '10'
        DiscoveryRule.update({'id': rule.id, 'hosts-limit': new_limit})
        rule = AttrDict(DiscoveryRule.info({'id': rule.id}))
        assert rule['hosts-limit'] == new_limit

    @pytest.mark.tier1
    def test_positive_update_priority(self, discoveryrule_factory):
        """Update discovery rule priority value

        :id: 0543cc73-c692-4bbf-818b-37353ec98986

        :expectedresults: Rule priority is updated

        :CaseImportance: Critical
        """
        available = set(range(
            1, 1000)) - {AttrDict(r).priority
                         for r in DiscoveryRule.list()}
        rule_priority = random.sample(available, 1)
        rule = discoveryrule_factory(options={'priority': rule_priority[0]})
        assert rule.priority == str(rule_priority[0])
        available = set(range(
            1, 1000)) - {AttrDict(r).priority
                         for r in DiscoveryRule.list()}
        rule_priority = random.sample(available, 1)
        DiscoveryRule.update({'id': rule.id, 'priority': rule_priority[0]})
        rule = AttrDict(DiscoveryRule.info({'id': rule.id}))
        assert rule.priority == str(rule_priority[0])

    @pytest.mark.tier1
    def test_positive_update_disable_enable(self, discoveryrule_factory):
        """Update discovery rule enabled state. (Disabled->Enabled)

        :id: 64e8b21b-2ab0-49c3-a12d-02dbdb36647a

        :expectedresults: Rule is successfully enabled

        :CaseImportance: Critical
        """
        rule = discoveryrule_factory(options={'enabled': 'false'})
        assert rule.enabled == 'false'
        DiscoveryRule.update({'id': rule.id, 'enabled': 'true'})
        rule = AttrDict(DiscoveryRule.info({'id': rule.id}))
        assert rule.enabled == 'true'

    @pytest.mark.tier3
    @pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
    def test_negative_update_name(self, name, discoveryrule_factory):
        """Update discovery rule name using invalid names only

        :id: 8293cc6a-d983-460a-b76e-221ad02b54b7

        :expectedresults: Rule name is not updated

        :CaseLevel: Component

        :CaseImportance: Medium

        :parametrized: yes
        """
        rule = discoveryrule_factory()
        with pytest.raises(CLIReturnCodeError):
            DiscoveryRule.update({'id': rule.id, 'name': name})

    @pytest.mark.tier3
    def test_negative_update_hostname(self, discoveryrule_factory):
        """Update discovery rule host name using number as a value

        :id: c382dbc7-9509-4060-9038-1617f7fef038

        :expectedresults: Rule host name is not updated

        :CaseImportance: Medium

        :CaseLevel: Component
        """
        rule = discoveryrule_factory()
        with pytest.raises(CLIReturnCodeError):
            DiscoveryRule.update({'id': rule.id, 'hostname': '$#@!*'})

    @pytest.mark.tier3
    def test_negative_update_limit(self, discoveryrule_factory):
        """Update discovery rule host limit using invalid values

        :id: e3257d8a-91b9-406f-bd74-0fd1fb05bb77

        :expectedresults: Rule host limit is not updated

        :CaseLevel: Component

        :CaseImportance: Medium
        """
        rule = discoveryrule_factory()
        host_limit = gen_string('alpha')
        with pytest.raises(CLIReturnCodeError):
            DiscoveryRule.update({'id': rule.id, 'hosts-limit': host_limit})

    @pytest.mark.tier3
    def test_negative_update_priority(self, discoveryrule_factory):
        """Update discovery rule priority using invalid values

        :id: 0778dd00-aa19-4062-bdf3-752e1b546ec2

        :expectedresults: Rule priority is not updated

        :CaseLevel: Component

        :CaseImportance: Medium
        """
        rule = discoveryrule_factory()
        priority = gen_string('alpha')
        with pytest.raises(CLIReturnCodeError):
            DiscoveryRule.update({'id': rule.id, 'priority': priority})
from robottelo.datafactory import valid_data_list


@pytest.fixture(scope='module')
def module_lce(module_org):
    return entities.LifecycleEnvironment(
        organization=module_org, description=gen_string('alpha')
    ).create()


@pytest.fixture
def lce(module_org):
    return entities.LifecycleEnvironment(organization=module_org).create()


@pytest.mark.parametrize('name', **parametrized(valid_data_list()))
@pytest.mark.tier1
def test_positive_create_with_name(name):
    """Create lifecycle environment with valid name only

    :id: ec1d985a-6a39-4de6-b635-c803ecedd832

    :expectedresults: Lifecycle environment is created and has proper name

    :CaseImportance: Critical

    :parametrized: yes
    """
    assert entities.LifecycleEnvironment(name=name).create().name == name

示例#49
0
        assert session.activationkey.search(name) == name
        session.activationkey.update(
            name,
            {
                'details.name': new_name,
                'details.description': description,
            },
        )
        ak = session.activationkey.read(new_name)
        assert ak['details']['name'] == new_name
        assert ak['details']['description'] == description


@tier2
@upgrade
@parametrize('cv_name', **valid_data_list('ui'))
def test_positive_create_with_cv(session, module_org, cv_name):
    """Create Activation key for all variations of Content Views

    :id: 2ad000f1-6c80-46aa-a61b-9ea62cefe91b

    :expectedresults: Activation key is created

    :CaseLevel: Integration
    """
    name = gen_string('alpha')
    env_name = gen_string('alpha')
    repo_id = create_sync_custom_repo(module_org.id)
    cv_publish_promote(
        cv_name, env_name, repo_id, module_org.id)
    with session:
示例#50
0
    repos_collection.setup_virtual_machine(rhel7_contenthost, default_sat)
    with session:
        session.organization.select(org.name)
        chost = session.contenthost.read(rhel7_contenthost.hostname,
                                         widget_names='details')
        assert chost['details']['registered_by'] == f'Activation Key {ak_name}'
        ak_values = session.activationkey.read(ak_name,
                                               widget_names='content_hosts')
        assert len(ak_values['content_hosts']['table']) == 1
        assert ak_values['content_hosts']['table'][0][
            'Name'] == rhel7_contenthost.hostname


@pytest.mark.tier2
@pytest.mark.upgrade
@pytest.mark.parametrize('cv_name', **parametrized(valid_data_list('ui')))
def test_positive_create_with_cv(session, module_org, cv_name):
    """Create Activation key for all variations of Content Views

    :id: 2ad000f1-6c80-46aa-a61b-9ea62cefe91b

    :parametrized: yes

    :expectedresults: Activation key is created

    :CaseLevel: Integration
    """
    name = gen_string('alpha')
    env_name = gen_string('alpha')
    repo_id = create_sync_custom_repo(module_org.id)
    cv_publish_promote(cv_name, env_name, repo_id, module_org.id)
示例#51
0
    def test_positive_CRUD(self):
        """Create User with various parameters, updating and deleting

        :id: 2d430243-8512-46ee-8d21-7ccf0c7af807

        :expectedresults: User is created with parameters, parameters
                          are updated, user is deleted

        :CaseImportance: Critical
        """
        # create with params
        mail = random.choice(valid_emails_list())
        user_params = {
            'login': random.choice(valid_usernames_list()),
            'firstname': random.choice(valid_usernames_list()),
            'lastname': random.choice(valid_usernames_list()),
            'mail': mail.replace('"', r'\"').replace('`', r'\`'),
            'description': random.choice(list(valid_data_list().values())),
        }
        user = make_user(user_params)
        user['firstname'], user['lastname'] = user['name'].split()
        user_params.pop('mail')
        user_params['email'] = mail
        for key in user_params:
            assert user_params[key] == user[
                key], f'values for key "{key}" do not match'

        # list by firstname and lastname
        result = User.list(
            {'search': 'firstname = {}'.format(user_params['firstname'])})
        # make sure user is in list result
        assert {user['id'], user['login'], user['name']} == {
            result[0]['id'],
            result[0]['login'],
            result[0]['name'],
        }
        result = User.list(
            {'search': 'lastname = {}'.format(user_params['lastname'])})
        # make sure user is in list result
        assert {user['id'], user['login'], user['name']} == {
            result[0]['id'],
            result[0]['login'],
            result[0]['name'],
        }
        # update params
        new_mail = random.choice(valid_emails_list())
        user_params = {
            'firstname': random.choice(valid_usernames_list()),
            'lastname': random.choice(valid_usernames_list()),
            'mail': new_mail.replace('"', r'\"').replace('`', r'\`'),
            'description': random.choice(list(valid_data_list().values())),
        }
        user_params.update({'id': user['id']})
        User.update(user_params)
        user = User.info({'login': user['login']})
        user['firstname'], user['lastname'] = user['name'].split()
        user_params.pop('mail')
        user_params['email'] = new_mail
        for key in user_params:
            assert user_params[key] == user[
                key], f'values for key "{key}" do not match'
        # delete
        User.delete({'login': user['login']})
        with pytest.raises(CLIReturnCodeError):
            User.info({'login': user['login']})
示例#52
0
class TestUserGroup:
    """Tests for the ``usergroups`` path."""
    @pytest.fixture
    def user_group(self):
        return entities.UserGroup().create()

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    def test_positive_create_with_name(self, name):
        """Create new user group using different valid names

        :id: 3a2255d9-f48d-4f22-a4b9-132361bd9224

        :parametrized: yes

        :expectedresults: User group is created successfully.

        :CaseImportance: Critical
        """
        user_group = entities.UserGroup(name=name).create()
        assert user_group.name == name

    @pytest.mark.tier1
    @pytest.mark.parametrize('login', **parametrized(valid_usernames_list()))
    def test_positive_create_with_user(self, login):
        """Create new user group using valid user attached to that group.

        :id: ab127e09-31d2-4c5b-ae6c-726e4b11a21e

        :parametrized: yes

        :expectedresults: User group is created successfully.

        :CaseImportance: Critical
        """
        user = entities.User(login=login).create()
        user_group = entities.UserGroup(user=[user]).create()
        assert len(user_group.user) == 1
        assert user_group.user[0].read().login == login

    @pytest.mark.tier1
    def test_positive_create_with_users(self):
        """Create new user group using multiple users attached to that group.

        :id: b8dbbacd-b5cb-49b1-985d-96df21440652

        :expectedresults: User group is created successfully and contains all
            expected users.

        :CaseImportance: Critical
        """
        users = [entities.User().create() for _ in range(randint(3, 5))]
        user_group = entities.UserGroup(user=users).create()
        assert sorted([user.login for user in users]) == sorted(
            [user.read().login for user in user_group.user])

    @pytest.mark.tier1
    @pytest.mark.parametrize('role_name', **parametrized(valid_data_list()))
    def test_positive_create_with_role(self, role_name):
        """Create new user group using valid role attached to that group.

        :id: c4fac71a-9dda-4e5f-a5df-be362d3cbd52

        :parametrized: yes

        :expectedresults: User group is created successfully.

        :CaseImportance: Critical
        """
        role = entities.Role(name=role_name).create()
        user_group = entities.UserGroup(role=[role]).create()
        assert len(user_group.role) == 1
        assert user_group.role[0].read().name == role_name

    @pytest.mark.tier1
    def test_positive_create_with_roles(self):
        """Create new user group using multiple roles attached to that group.

        :id: 5838fcfd-e256-49cf-aef8-b2bf215b3586

        :expectedresults: User group is created successfully and contains all
            expected roles

        :CaseImportance: Critical
        """
        roles = [entities.Role().create() for _ in range(randint(3, 5))]
        user_group = entities.UserGroup(role=roles).create()
        assert sorted([role.name for role in roles]) == sorted(
            [role.read().name for role in user_group.role])

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    def test_positive_create_with_usergroup(self, name):
        """Create new user group using another user group attached to the
        initial group.

        :id: 2a3f7b1a-7411-4c12-abaf-9a3ca1dfae31

        :parametrized: yes

        :expectedresults: User group is created successfully.

        :CaseImportance: Critical
        """
        sub_user_group = entities.UserGroup(name=name).create()
        user_group = entities.UserGroup(usergroup=[sub_user_group]).create()
        assert len(user_group.usergroup) == 1
        assert user_group.usergroup[0].read().name == name

    @pytest.mark.tier2
    def test_positive_create_with_usergroups(self):
        """Create new user group using multiple user groups attached to that
        initial group.

        :id: 9ba71288-af8b-4957-8413-442a47057634

        :expectedresults: User group is created successfully and contains all
            expected user groups

        :CaseLevel: Integration
        """
        sub_user_groups = [
            entities.UserGroup().create() for _ in range(randint(3, 5))
        ]
        user_group = entities.UserGroup(usergroup=sub_user_groups).create()
        assert sorted([usergroup.name
                       for usergroup in sub_user_groups]) == sorted([
                           usergroup.read().name
                           for usergroup in user_group.usergroup
                       ])

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
    def test_negative_create_with_name(self, name):
        """Attempt to create user group with invalid name.

        :id: 1a3384dc-5d52-442c-87c8-e38048a61dfa

        :parametrized: yes

        :expectedresults: User group is not created.

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.UserGroup(name=name).create()

    @pytest.mark.tier1
    def test_negative_create_with_same_name(self):
        """Attempt to create user group with a name of already existent entity.

        :id: aba0925a-d5ec-4e90-86c6-404b9b6f0179

        :expectedresults: User group is not created.

        :CaseImportance: Critical
        """
        user_group = entities.UserGroup().create()
        with pytest.raises(HTTPError):
            entities.UserGroup(name=user_group.name).create()

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_name', **parametrized(valid_data_list()))
    def test_positive_update(self, user_group, new_name):
        """Update existing user group with different valid names.

        :id: b4f0a19b-9059-4e8b-b245-5a30ec06f9f3

        :parametrized: yes

        :expectedresults: User group is updated successfully.

        :CaseImportance: Critical
        """
        user_group.name = new_name
        user_group = user_group.update(['name'])
        assert new_name == user_group.name

    @pytest.mark.tier1
    def test_positive_update_with_new_user(self):
        """Add new user to user group

        :id: e11b57c3-5f86-4963-9cc6-e10e2f02468b

        :expectedresults: User is added to user group successfully.

        :CaseImportance: Critical
        """
        user = entities.User().create()
        user_group = entities.UserGroup().create()
        user_group.user = [user]
        user_group = user_group.update(['user'])
        assert user.login == user_group.user[0].read().login

    @pytest.mark.tier2
    def test_positive_update_with_existing_user(self):
        """Update user that assigned to user group with another one

        :id: 71b78f64-867d-4bf5-9b1e-02698a17fb38

        :expectedresults: User group is updated successfully.

        :CaseLevel: Integration
        """
        users = [entities.User().create() for _ in range(2)]
        user_group = entities.UserGroup(user=[users[0]]).create()
        user_group.user[0] = users[1]
        user_group = user_group.update(['user'])
        assert users[1].login == user_group.user[0].read().login

    @pytest.mark.tier1
    def test_positive_update_with_new_role(self):
        """Add new role to user group

        :id: 8e0872c1-ae88-4971-a6fc-cd60127d6663

        :expectedresults: Role is added to user group successfully.

        :CaseImportance: Critical
        """
        new_role = entities.Role().create()
        user_group = entities.UserGroup().create()
        user_group.role = [new_role]
        user_group = user_group.update(['role'])
        assert new_role.name == user_group.role[0].read().name

    @pytest.mark.tier1
    @pytest.mark.upgrade
    def test_positive_update_with_new_usergroup(self):
        """Add new user group to existing one

        :id: 3cb29d07-5789-4f94-9fd9-a7e494b3c110

        :expectedresults: User group is added to existing group successfully.

        :CaseImportance: Critical
        """
        new_usergroup = entities.UserGroup().create()
        user_group = entities.UserGroup().create()
        user_group.usergroup = [new_usergroup]
        user_group = user_group.update(['usergroup'])
        assert new_usergroup.name == user_group.usergroup[0].read().name

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_name', **parametrized(invalid_values_list()))
    def test_negative_update(self, user_group, new_name):
        """Attempt to update existing user group using different invalid names.

        :id: 03772bd0-0d52-498d-8259-5c8a87e08344

        :parametrized: yes

        :expectedresults: User group is not updated.

        :CaseImportance: Critical
        """
        user_group.name = new_name
        with pytest.raises(HTTPError):
            user_group.update(['name'])
        assert user_group.read().name != new_name

    @pytest.mark.tier1
    def test_negative_update_with_same_name(self):
        """Attempt to update user group with a name of already existent entity.

        :id: 14888998-9282-4d81-9e99-234d19706783

        :expectedresults: User group is not updated.

        :CaseImportance: Critical
        """
        name = gen_string('alphanumeric')
        entities.UserGroup(name=name).create()
        new_user_group = entities.UserGroup().create()
        new_user_group.name = name
        with pytest.raises(HTTPError):
            new_user_group.update(['name'])
        assert new_user_group.read().name != name

    @pytest.mark.tier1
    def test_positive_delete(self):
        """Create user group with valid name and then delete it

        :id: c5cfcc4a-9177-47bb-8f19-7a8930eb7ca3

        :expectedresults: User group is deleted successfully

        :CaseImportance: Critical
        """
        user_group = entities.UserGroup().create()
        user_group.delete()
        with pytest.raises(HTTPError):
            user_group.read()
示例#53
0
    def test_positive_CRUD(self):
        """Check if product can be created, updated, synchronized and deleted

        :id: 9d7b5ec8-59d0-4371-b5d2-d43145e4e2db

        :expectedresults: Product is created, updated, synchronized and deleted

        :BZ: 1422552

        :CaseImportance: Critical
        """
        desc = valid_data_list()[0]
        gpg_key = make_gpg_key({u'organization-id': self.org['id']})
        name = valid_data_list()[0]
        label = valid_labels_list()[0]
        sync_plan = make_sync_plan({u'organization-id': self.org['id']})
        product = make_product({
            u'description': desc,
            u'gpg-key-id': gpg_key['id'],
            u'label': label,
            u'name': name,
            u'organization-id': self.org['id'],
            u'sync-plan-id': sync_plan['id'],
        })
        self.assertEqual(product['name'], name)
        self.assertGreater(len(product['label']), 0)
        self.assertEqual(product['label'], label)
        self.assertEqual(product['description'], desc)
        self.assertEqual(product['gpg']['gpg-key-id'], gpg_key['id'])
        self.assertEqual(product['sync-plan-id'], sync_plan['id'])

        # update
        desc = valid_data_list()[0]
        new_gpg_key = make_gpg_key({u'organization-id': self.org['id']})
        new_sync_plan = make_sync_plan({u'organization-id': self.org['id']})
        new_prod_name = gen_string('alpha', 8)
        Product.update({
            u'description': desc,
            u'id': product['id'],
            u'gpg-key-id': new_gpg_key['id'],
            u'sync-plan-id': new_sync_plan['id'],
            u'name': new_prod_name,
        })
        product = Product.info({
            u'id': product['id'],
            u'organization-id': self.org['id'],
        })
        self.assertEqual(product['name'], new_prod_name)
        self.assertEqual(product['description'], desc)
        self.assertEqual(product['gpg']['gpg-key-id'], new_gpg_key['id'])
        self.assertNotEqual(product['gpg']['gpg-key-id'], gpg_key['id'])
        self.assertEqual(product['sync-plan-id'], new_sync_plan['id'])
        self.assertNotEqual(product['sync-plan-id'], sync_plan['id'])

        # synchronize
        repo = make_repository({
            'product-id': product['id'],
            'url': FAKE_0_YUM_REPO,
        })
        Product.synchronize({
            'id': product['id'],
            'organization-id': self.org['id'],
        })
        packages = Package.list({'product-id': product['id']})
        repo = Repository.info({'id': repo['id']})
        self.assertEqual(int(repo['content-counts']['packages']),
                         len(packages))
        self.assertEqual(len(packages), FAKE_0_YUM_REPO_PACKAGES_COUNT)

        # delete
        Product.remove_sync_plan({'id': product['id']})
        product = Product.info({
            'id': product['id'],
            'organization-id': self.org['id'],
        })
        self.assertEqual(len(product['sync-plan-id']), 0)
        Product.delete({u'id': product['id']})
        wait_for_tasks(
            search_query='label = Actions::Katello::Product::Destroy'
            ' and resource_id = {}'.format(product['id']),
            max_tries=10,
        )
        with self.assertRaises(CLIReturnCodeError):
            Product.info({
                u'id': product['id'],
                u'organization-id': self.org['id'],
            })
示例#54
0
class TestModel:
    """Test class for Model CLI"""
    @pytest.fixture()
    def class_model(self):
        """Shared model for tests"""
        return make_model()

    @pytest.mark.tier1
    @pytest.mark.upgrade
    @pytest.mark.parametrize('name, new_name',
                             **parametrized(
                                 list(
                                     zip(valid_data_list().values(),
                                         valid_data_list().values()))))
    def test_positive_crud_with_name(self, name, new_name):
        """Successfully creates, updates and deletes a Model.

        :id: 9ca9d5ff-750a-4d60-91b2-4c4375f0e35f

        :parametrized: yes

        :expectedresults: Model is created, updated and deleted.

        :CaseImportance: High
        """
        model = make_model({'name': name})
        assert model['name'] == name
        Model.update({'id': model['id'], 'new-name': new_name})
        model = Model.info({'id': model['id']})
        assert model['name'] == new_name
        Model.delete({'id': model['id']})
        with pytest.raises(CLIReturnCodeError):
            Model.info({'id': model['id']})

    @pytest.mark.tier1
    def test_positive_create_with_vendor_class(self):
        """Check if Model can be created with specific vendor class

        :id: c36d3490-cd12-4f5f-a453-2ae5d0404496

        :expectedresults: Model is created with specific vendor class

        :CaseImportance: Medium
        """
        vendor_class = gen_string('utf8')
        model = make_model({'vendor-class': vendor_class})
        assert model['vendor-class'] == vendor_class

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
    def test_negative_create_with_name(self, name):
        """Don't create an Model with invalid data.

        :id: b2eade66-b612-47e7-bfcc-6e363023f498

        :parametrized: yes

        :expectedresults: Model is not created.

        :CaseImportance: High
        """
        with pytest.raises(CLIReturnCodeError):
            Model.create({'name': name})

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_name', **parametrized(invalid_values_list()))
    def test_negative_update_name(self, class_model, new_name):
        """Fail to update shared model name

        :id: 98020a4a-1789-4df3-929c-6c132b57f5a1

        :parametrized: yes

        :expectedresults: Model name is not updated

        :CaseImportance: Medium
        """
        with pytest.raises(CLIReturnCodeError):
            Model.update({'id': class_model['id'], 'new-name': new_name})
        result = Model.info({'id': class_model['id']})
        assert class_model['name'] == result['name']

    @pytest.mark.tier1
    @pytest.mark.parametrize('entity_id', **parametrized(invalid_id_list()))
    def test_negative_delete_by_id(self, entity_id):
        """Delete model by wrong ID

        :id: f8b0d428-1b3d-4fc9-9ca1-1eb30c8ac20a

        :parametrized: yes

        :expectedresults: Model is not deleted

        :CaseImportance: High
        """
        with pytest.raises(CLIReturnCodeError):
            Model.delete({'id': entity_id})
示例#55
0
def get_random_gpgkey_name():
    """Creates a random gpgkey name"""
    return random.choice(valid_data_list())
示例#56
0
class TestPartitionTable:
    """Tests for the ``ptables`` path."""
    @pytest.mark.tier1
    @pytest.mark.parametrize('name',
                             **parametrized(generate_strings_list(length=1)))
    def test_positive_create_with_one_character_name(self, name):
        """Create Partition table with 1 character in name

        :id: 71601d96-8ce8-4ecb-b053-af6f26a246ea

        :parametrized: yes

        :expectedresults: Partition table was created

        :BZ: 1229384

        :CaseImportance: Low
        """
        ptable = entities.PartitionTable(name=name).create()
        assert ptable.name == name

    @pytest.mark.tier1
    @pytest.mark.parametrize(
        'name, new_name',
        **parametrized(
            list(
                zip(
                    generate_strings_list(length=gen_integer(4, 30)),
                    generate_strings_list(length=gen_integer(4, 30)),
                ))),
    )
    def test_positive_crud_with_name(self, name, new_name):
        """Create new, search, update and delete partition tables using different inputs as a name

        :id: 32250f23-3704-496f-83e6-6379a415650a

        :parametrized: yes

        :expectedresults: Partition table is created, searched, updated and deleted successfully
            with correct name

        :CaseImportance: Critical
        """
        ptable = entities.PartitionTable(name=name).create()
        assert ptable.name == name
        result = entities.PartitionTable().search(
            query={'search': f'name="{ptable.name}"'})
        assert len(result) == 1
        assert result[0].id == ptable.id
        ptable.name = new_name
        assert ptable.update(['name']).name == new_name
        ptable.delete()
        with pytest.raises(HTTPError):
            ptable.read()

    @pytest.mark.tier1
    @pytest.mark.parametrize('layout, new_layout',
                             **parametrized(
                                 list(zip(valid_data_list(),
                                          valid_data_list()))))
    def test_positive_create_update_with_layout(self, layout, new_layout):
        """Create new and update partition tables using different inputs as a
            layout

        :id: 5cdf156f-72d9-4950-b11c-4bca5d2aa5bb

        :parametrized: yes

        :expectedresults: Partition table is created and updated successfully and has correct
            layout

        :CaseImportance: Critical
        """
        ptable = entities.PartitionTable(layout=layout).create()
        assert ptable.layout == layout
        ptable.layout = new_layout
        assert ptable.update(['layout']).layout == new_layout

    @pytest.mark.tier1
    def test_positive_create_with_layout_length(self):
        """Create a Partition Table with layout length more than 4096 chars

        :id: 7a07d70c-6130-4357-81c3-4f1254e519d2

        :expectedresults: Partition table created successfully and has correct
            layout

        :BZ: 1270181
        """
        layout = gen_string('alpha', 5000)
        ptable = entities.PartitionTable(layout=layout).create()
        assert ptable.layout == layout

    @pytest.mark.tier1
    def test_positive_create_update_with_os(self):
        """Create new partition table with random operating system and update it with
            random operating system

        :id: 52c6125b-ff50-4a7f-8be0-cb270baf5aa0

        :expectedresults: Partition table created and updated successfully and has correct
            operating system

        """
        os_family = random.choice(OPERATING_SYSTEMS)
        ptable = entities.PartitionTable(os_family=os_family).create()
        assert ptable.os_family == os_family
        new_os_family = random.choice(OPERATING_SYSTEMS)
        ptable.os_family = new_os_family
        assert ptable.update(['os_family']).os_family == new_os_family

    def test_positive_create_search_with_org(self):
        """Create new partition table with organization and try to find it using its name and
            organization it assigned to

        :id: e6e78c43-8251-4a44-a5c0-4e4d9f71323e

        :expectedresults: Partition table created successfully and has correct
            organization assigned

        :CaseImportance: Medium
        """
        org = entities.Organization().create()
        ptable = entities.PartitionTable(organization=[org]).create()
        assert ptable.organization[0].read().name == org.name
        result = entities.PartitionTable().search(query={
            'search': ptable.name,
            'organization_id': org.id
        })
        assert len(result) == 1
        assert result[0].read().organization[0].id == org.id

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
    def test_negative_create_with_invalid_name(self, name):
        """Try to create partition table using invalid names only

        :id: 02631917-2f7a-4cf7-bb2a-783349a04758

        :parametrized: yes

        :expectedresults: Partition table was not created

        :CaseImportance: Medium
        """
        with pytest.raises(HTTPError):
            entities.PartitionTable(name=name).create()

    @pytest.mark.tier1
    @pytest.mark.parametrize('layout', **parametrized(('', ' ', None)))
    def test_negative_create_with_empty_layout(self, layout):
        """Try to create partition table with empty layout

        :id: 03cb7a35-e4c3-4874-841b-0760c3b8d6af

        :parametrized: yes

        :expectedresults: Partition table was not created
        """
        with pytest.raises(HTTPError):
            entities.PartitionTable(layout=layout).create()

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_name', **parametrized(invalid_values_list()))
    def test_negative_update_name(self, new_name):
        """Try to update partition table using invalid names only

        :id: 7e9face8-2c20-450e-890c-6def6de570ca

        :parametrized: yes

        :expectedresults: Partition table was not updated

        :CaseImportance: Medium
        """
        ptable = entities.PartitionTable().create()
        ptable.name = new_name
        with pytest.raises(HTTPError):
            assert ptable.update(['name']).name != new_name

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_layout', **parametrized(('', ' ', None)))
    def test_negative_update_layout(self, new_layout):
        """Try to update partition table with empty layout

        :id: 35c84c8f-b802-4076-89f2-4ec04cf43a31

        :parametrized: yes

        :expectedresults: Partition table was not updated

        :CaseImportance: Medium
        """
        ptable = entities.PartitionTable().create()
        ptable.layout = new_layout
        with pytest.raises(HTTPError):
            assert ptable.update(['layout']).layout != new_layout
示例#57
0
def test_positive_end_to_end(module_org):
    """Check if host collection can be created with name and description,
    content host can be added and removed, host collection can be listed,
    updated and deleted

    :id: 2d3b718e-6f57-4c83-aedb-15604cc8a4bd

    :expectedresults: Host collection is created and has expected name and
        description, content-host is added and removed, host collection is
        updated and deleted.

    :CaseImportance: Critical
    """
    name = list(valid_data_list().values())[0]
    desc = list(valid_data_list().values())[0]
    new_host_col = make_host_collection(
        {'description': desc, 'name': name, 'organization-id': module_org.id}
    )
    assert new_host_col['name'] == name
    assert new_host_col['description'] == desc

    # add host
    new_system = _make_fake_host_helper(module_org)
    no_of_content_host = new_host_col['total-hosts']
    HostCollection.add_host({'host-ids': new_system['id'], 'id': new_host_col['id']})
    result = HostCollection.info({'id': new_host_col['id']})
    assert result['total-hosts'] > no_of_content_host

    # list hosts
    result = HostCollection.hosts({'name': name, 'organization-id': module_org.id})
    assert new_system['name'].lower() == result[0]['name']
    # List all host collections within organization
    result = HostCollection.list({'organization': module_org.name})
    assert len(result) >= 1
    # Filter list by name
    result = HostCollection.list({'name': name, 'organization-id': module_org.id})
    assert len(result) == 1
    assert result[0]['id'] == new_host_col['id']
    # Filter list by associated host name
    result = HostCollection.list({'organization': module_org.name, 'host': new_system['name']})
    assert len(result) == 1
    assert result[0]['name'] == new_host_col['name']

    # remove host
    no_of_content_host = HostCollection.info({'id': new_host_col['id']})['total-hosts']
    HostCollection.remove_host({'host-ids': new_system['id'], 'id': new_host_col['id']})
    result = HostCollection.info({'id': new_host_col['id']})
    assert no_of_content_host > result['total-hosts']

    # update
    new_name = list(valid_data_list().values())[0]
    new_desc = list(valid_data_list().values())[0]
    HostCollection.update(
        {'description': new_desc, 'id': new_host_col['id'], 'new-name': new_name}
    )
    result = HostCollection.info({'id': new_host_col['id']})
    assert result['name'] == new_name
    assert result['description'] == new_desc

    # delete
    HostCollection.delete({'id': new_host_col['id']})
    with pytest.raises(CLIReturnCodeError):
        HostCollection.info({'id': new_host_col['id']})
示例#58
0
    :id: df5837e7-3d0f-464a-bd67-86b423c16eb4

    :parametrized: yes

    :expectedresults: A sync plan is created, 'enabled' field has correct
        value.

    :CaseImportance: Critical
    """
    sync_plan = entities.SyncPlan(enabled=enabled,
                                  organization=module_org).create()
    sync_plan = sync_plan.read()
    assert sync_plan.enabled == enabled


@pytest.mark.parametrize('name', **parametrized(valid_data_list()))
@pytest.mark.tier1
def test_positive_create_with_name(module_org, name):
    """Create a sync plan with a random name.

    :id: c1263134-0d7c-425a-82fd-df5274e1f9ba

    :parametrized: yes

    :expectedresults: A sync plan is created with the specified name.

    :CaseImportance: Critical
    """
    sync_plan = entities.SyncPlan(name=name, organization=module_org).create()
    sync_plan = sync_plan.read()
    assert sync_plan.name == name
示例#59
0
class TestMedium:
    """Test class for Medium CLI"""
    @pytest.mark.tier1
    @pytest.mark.parametrize('name',
                             **parametrized(valid_data_list().values()))
    def test_positive_crud_with_name(self, name):
        """Check if Medium can be created, updated, deleted

        :id: 66b749b2-0248-47a8-b78f-3366f3804b29

        :parametrized: yes

        :expectedresults: Medium is created


        :CaseImportance: Critical
        """
        medium = make_medium({'name': name})
        assert medium['name'] == name
        new_name = gen_alphanumeric(6)
        Medium.update({'name': medium['name'], 'new-name': new_name})
        medium = Medium.info({'id': medium['id']})
        assert medium['name'] == new_name
        Medium.delete({'id': medium['id']})
        with pytest.raises(CLIReturnCodeError):
            Medium.info({'id': medium['id']})

    @pytest.mark.tier1
    def test_positive_create_with_location(self):
        """Check if medium with location can be created

        :id: cbc6c586-fae7-4bb9-aeb1-e30158f16a98

        :expectedresults: Medium is created and has new location assigned


        :CaseImportance: Medium
        """
        location = make_location()
        medium = make_medium({'location-ids': location['id']})
        assert location['name'] in medium['locations']

    @pytest.mark.tier1
    def test_positive_create_with_organization_by_id(self):
        """Check if medium with organization can be created

        :id: 631bb6ed-e42b-482a-83f0-f6ce0f20729a

        :expectedresults: Medium is created and has new organization assigned


        :CaseImportance: Medium
        """
        org = make_org()
        medium = make_medium({'organization-ids': org['id']})
        assert org['name'] in medium['organizations']

    @pytest.mark.tier2
    @pytest.mark.upgrade
    def test_positive_remove_os(self):
        """Check if Medium can be associated with operating system and then removed from media

        :id: 23b5b55b-3624-440c-8001-75c7c5a5a004

        :expectedresults: Operating system removed


        :CaseLevel: Integration
        """
        medium = make_medium()
        os = make_os()
        Medium.add_operating_system({
            'id': medium['id'],
            'operatingsystem-id': os['id']
        })
        medium = Medium.info({'id': medium['id']})
        assert os['title'] in medium['operating-systems']
        Medium.remove_operating_system({
            'id': medium['id'],
            'operatingsystem-id': os['id']
        })
        medium = Medium.info({'id': medium['id']})
        assert os['name'] not in medium['operating-systems']
示例#60
0
    repos_collection.setup_content(org.id, lce.id, upload_manifest=True)
    ak_name = repos_collection.setup_content_data['activation_key']['name']
    with VirtualMachine(distro=DISTRO_RHEL7) as vm:
        repos_collection.setup_virtual_machine(vm)
        with session:
            session.organization.select(org.name)
            chost = session.contenthost.read(vm.hostname, widget_names='details')
            assert chost['details']['registered_by'] == 'Activation Key {}'.format(ak_name)
            ak_values = session.activationkey.read(ak_name, widget_names='content_hosts')
            assert len(ak_values['content_hosts']['table']) == 1
            assert ak_values['content_hosts']['table'][0]['Name'] == vm.hostname


@tier2
@upgrade
@parametrize('cv_name', **parametrized(valid_data_list('ui')))
def test_positive_create_with_cv(session, module_org, cv_name):
    """Create Activation key for all variations of Content Views

    :id: 2ad000f1-6c80-46aa-a61b-9ea62cefe91b

    :parametrized: yes

    :expectedresults: Activation key is created

    :CaseLevel: Integration
    """
    name = gen_string('alpha')
    env_name = gen_string('alpha')
    repo_id = create_sync_custom_repo(module_org.id)
    cv_publish_promote(cv_name, env_name, repo_id, module_org.id)