Exemplo n.º 1
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()

    @tier1
    @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()

    @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

    @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

    @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

    @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

    @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()

    @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()

    @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()

    @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'])

    @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_'])

    @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'])
Exemplo n.º 2
0
    :id: e48a6260-97e0-4234-a69c-77bbbcde85d6

    :expectedresults: Proxy is not created

    :CaseLevel: Component

    """
    # Create a random proxy
    with pytest.raises(HTTPError) as context:
        entities.SmartProxy(url=gen_url(scheme='https')).create()
    assert 'Unable to communicate' in context.value.response.text


@pytest.mark.skip_if_not_set('fake_capsules')
@pytest.mark.tier1
@pytest.mark.parametrize('name', **parametrized(valid_data_list()))
def test_positive_create_with_name(request, name):
    """Proxy creation with valid name

    :id: 0ffe0dc5-675e-45f4-b7e1-a14d3dd81f6e

    :expectedresults: Proxy is created

    :CaseLevel: Component

    :Parametrized: Yes

    """
    new_port = get_available_capsule_port()
    with default_url_on_new_port(9090, new_port) as url:
        proxy = _create_smart_proxy(request, name=name, url=url)
Exemplo n.º 3
0
class TestActiveDirectoryUser:
    """Implements the LDAP auth User Tests with Active Directory"""

    @pytest.fixture(scope='module')
    def create_ldap(self, ad_data):
        """Fetch necessary properties from settings and Create ldap auth source"""
        org = entities.Organization().create()
        loc = entities.Location(organization=[org]).create()
        ad_data = ad_data()
        yield dict(
            org=org,
            loc=loc,
            sat_url=f'https://{settings.server.hostname}',
            ldap_user_name=ad_data['ldap_user_name'],
            ldap_user_passwd=ad_data['ldap_user_passwd'],
            authsource=entities.AuthSourceLDAP(
                onthefly_register=True,
                account=ad_data['ldap_user_name'],
                account_password=ad_data['ldap_user_passwd'],
                base_dn=ad_data['base_dn'],
                groups_base=ad_data['group_base_dn'],
                attr_firstname=LDAP_ATTR['firstname'],
                attr_lastname=LDAP_ATTR['surname'],
                attr_login=LDAP_ATTR['login_ad'],
                server_type=LDAP_SERVER_TYPE['API']['ad'],
                attr_mail=LDAP_ATTR['mail'],
                name=gen_string('alpha'),
                host=ad_data['ldap_hostname'],
                tls=False,
                port='389',
                location=[loc],
                organization=[org],
            ).create(),
        )
        for user in entities.User().search(query={'search': f'login={ad_data["ldap_user_name"]}'}):
            user.delete()
        org.delete()
        loc.delete()

    @pytest.mark.tier2
    @pytest.mark.upgrade
    @pytest.mark.parametrize('username', **parametrized(valid_usernames_list()))
    def test_positive_create_in_ldap_mode(self, username, create_ldap):
        """Create User in ldap mode

        :id: 6f8616b1-5380-40d2-8678-7c4434050cfb

        :parametrized: yes

        :expectedresults: User is created without specifying the password

        :CaseLevel: Integration
        """
        user = entities.User(
            login=username, auth_source=create_ldap['authsource'], password=''
        ).create()
        assert user.login == username

    @pytest.mark.tier3
    def test_positive_ad_basic_no_roles(self, create_ldap):
        """Login with LDAP Auth- AD for user with no roles/rights

        :id: 3910c6eb-6eff-4ab7-a50d-ba40f5c24c08

        :setup: assure properly functioning AD server for authentication

        :steps: Login to server with an AD user.

        :expectedresults: Log in to foreman successfully but cannot access entities.

        :CaseLevel: System
        """
        sc = ServerConfig(
            auth=(create_ldap['ldap_user_name'], create_ldap['ldap_user_passwd']),
            url=create_ldap['sat_url'],
            verify=False,
        )
        with pytest.raises(HTTPError):
            entities.Architecture(sc).search()

    @pytest.mark.tier3
    @pytest.mark.upgrade
    def test_positive_access_entities_from_ldap_org_admin(self, create_ldap):
        """LDAP User can access resources within its taxonomies if assigned
        role has permission for same taxonomies

        :id: 522063ad-8d39-4f05-bfd3-dfa0fa73f4e1

        :steps:

            1. Create Org Admin and assign taxonomies to it
            2. Create LDAP user with same taxonomies as role above
            3. Assign Org Admin role to user above
            4. Login with LDAP user and attempt to access resources

        :expectedresults: LDAP User should be able to access all the resources
            and permissions in taxonomies selected in Org Admin role

        :CaseLevel: System
        """
        role_name = gen_string('alpha')
        default_org_admin = entities.Role().search(query={'search': 'name="Organization admin"'})
        org_admin = entities.Role(id=default_org_admin[0].id).clone(
            data={
                'role': {
                    'name': role_name,
                    'organization': create_ldap['org'].name,
                    'location': create_ldap['loc'].name,
                }
            }
        )
        sc = ServerConfig(
            auth=(create_ldap['ldap_user_name'], create_ldap['ldap_user_passwd']),
            url=create_ldap['sat_url'],
            verify=False,
        )
        with pytest.raises(HTTPError):
            entities.Architecture(sc).search()
        user = entities.User().search(
            query={'search': 'login={}'.format(create_ldap['ldap_user_name'])}
        )[0]
        user.role = [entities.Role(id=org_admin['id']).read()]
        user.update(['role'])
        for entity in [
            entities.Architecture,
            entities.Audit,
            entities.Bookmark,
            entities.CommonParameter,
            entities.LibvirtComputeResource,
            entities.OVirtComputeResource,
            entities.VMWareComputeResource,
            entities.ConfigGroup,
            entities.Errata,
            entities.OperatingSystem,
        ]:
            entity(sc).search()
Exemplo n.º 4
0
:Upstream: No
"""
import pytest
from fauxfactory import gen_string
from requests.exceptions import HTTPError

from robottelo.api.utils import one_to_many_names
from robottelo.datafactory import invalid_environments_list
from robottelo.datafactory import invalid_names_list
from robottelo.datafactory import parametrized
from robottelo.datafactory import valid_environments_list


@pytest.mark.tier1
@pytest.mark.parametrize('name', **parametrized(valid_environments_list()))
def test_positive_create_with_name(name, session_puppet_enabled_sat):
    """Create an environment and provide a valid name.

    :id: 8869ccf8-a511-4fa7-ac36-11494e85f532

    :parametrized: yes

    :expectedresults: The environment created successfully and has expected
        name.

    :CaseImportance: Critical
    """
    env = session_puppet_enabled_sat.api.Environment(name=name).create()
    assert env.name == name
Exemplo n.º 5
0
    :BZ: 1447958

    :CaseLevel: Integration
    """
    host = entities.Host().create()
    # adding org id as GET parameter for correspondence with BZ
    query = entities.Host()
    query._meta['api_path'] += f'?organization_id={host.organization.id}'
    results = query.search()
    assert len(results) == 1
    assert results[0].id == host.id


@tier1
@pytest.mark.parametrize('owner_type', **parametrized(['User', 'Usergroup']))
def test_negative_create_with_owner_type(owner_type):
    """Create a host and specify only ``owner_type``.

    :id: cdf9d16f-1c47-498a-be48-901355385dde

    :parametrized: yes

    :expectedresults: The host can't be created as ``owner`` is required.

    :CaseImportance: Critical
    """
    with pytest.raises(HTTPError) as error:
        entities.Host(owner_type=owner_type).create()
    assert str(422) in str(error)
Exemplo n.º 6
0
class TestADAuthSource:
    """Implements Active Directory feature tests in CLI"""
    @pytest.mark.tier1
    @pytest.mark.upgrade
    @pytest.mark.parametrize('server_name',
                             **parametrized(generate_strings_list()))
    def test_positive_create_with_ad(self, ad_data, server_name,
                                     ldap_tear_down):
        """Create/update/delete LDAP authentication with AD using names of different types

        :id: 093f6abc-91e7-4449-b484-71e4a14ac808

        :parametrized: yes

        :expectedresults: Whether creating/upating/deleting LDAP Auth with AD is successful.

        :CaseImportance: Critical
        """
        ad_data = ad_data()
        auth = make_ldap_auth_source({
            'name':
            server_name,
            'onthefly-register':
            'true',
            'host':
            ad_data['ldap_hostname'],
            'server-type':
            LDAP_SERVER_TYPE['CLI']['ad'],
            'attr-login':
            LDAP_ATTR['login_ad'],
            'attr-firstname':
            LDAP_ATTR['firstname'],
            'attr-lastname':
            LDAP_ATTR['surname'],
            'attr-mail':
            LDAP_ATTR['mail'],
            'account':
            ad_data['ldap_user_name'],
            'account-password':
            ad_data['ldap_user_passwd'],
            'base-dn':
            ad_data['base_dn'],
            'groups-base':
            ad_data['group_base_dn'],
        })
        assert auth['server']['name'] == server_name
        assert auth['server']['server'] == ad_data['ldap_hostname']
        assert auth['server']['server-type'] == LDAP_SERVER_TYPE['CLI']['ad']
        new_name = gen_string('alpha')
        LDAPAuthSource.update({'name': server_name, 'new-name': new_name})
        updated_auth = LDAPAuthSource.info({'id': auth['server']['id']})
        assert updated_auth['server']['name'] == new_name
        LDAPAuthSource.delete({'name': new_name})
        with pytest.raises(CLIReturnCodeError):
            LDAPAuthSource.info({'name': new_name})

    @pytest.mark.tier1
    @pytest.mark.parametrize('member_group', ['foobargroup', 'foobar.group'])
    def test_positive_refresh_usergroup_with_ad(self, member_group, ad_data,
                                                ldap_tear_down):
        """Verify the usergroup-sync functionality in AD Auth Source

        :id: 2e913e76-49c3-11eb-b4c6-d46d6dd3b5b2

        :customerscenario: true

        :CaseImportance: Medium

        :bz: 1901392

        :parametrized: yes

        :expectedresults: external user-group sync works as expected automatically
            based on user-sync
        """
        ad_data = ad_data()
        group_base_dn = ','.join(ad_data['group_base_dn'].split(',')[1:])
        LOGEDIN_MSG = "Using configured credentials for user '{0}'."
        auth_source = make_ldap_auth_source({
            'name':
            gen_string('alpha'),
            'onthefly-register':
            'true',
            'host':
            ad_data['ldap_hostname'],
            'server-type':
            LDAP_SERVER_TYPE['CLI']['ad'],
            'attr-login':
            LDAP_ATTR['login_ad'],
            'attr-firstname':
            LDAP_ATTR['firstname'],
            'attr-lastname':
            LDAP_ATTR['surname'],
            'attr-mail':
            LDAP_ATTR['mail'],
            'account':
            ad_data['ldap_user_name'],
            'account-password':
            ad_data['ldap_user_passwd'],
            'base-dn':
            ad_data['base_dn'],
            'groups-base':
            group_base_dn,
        })
        # assert auth_source['account']['groups-base'] == group_base_dn
        viewer_role = Role.info({'name': 'Viewer'})
        user_group = make_usergroup()
        make_usergroup_external({
            'auth-source-id': auth_source['server']['id'],
            'user-group-id': user_group['id'],
            'name': member_group,
        })
        UserGroup.add_role({
            'id': user_group['id'],
            'role-id': viewer_role['id']
        })
        user_group = UserGroup.info({'id': user_group['id']})
        result = Auth.with_user(username=ad_data['ldap_user_name'],
                                password=ad_data['ldap_user_passwd']).status()
        assert LOGEDIN_MSG.format(
            ad_data['ldap_user_name']) in result[0]['message']
        UserGroupExternal.refresh({
            'user-group-id': user_group['id'],
            'name': member_group
        })
        user_group = UserGroup.info({'id': user_group['id']})
        list = Role.with_user(username=ad_data['ldap_user_name'],
                              password=ad_data['ldap_user_passwd']).list()
        assert len(list) > 1
Exemplo n.º 7
0
    :param repo: Repository instance to be validated
    :param content_types: List of repository content entities that should
        be validated (e.g. package, erratum, puppet_module)
    :param bool after_sync: Specify whether you perform validation before
        synchronization procedure is happened or after
    """
    repo = Repository.info({'id': repo['id']})
    for content in content_types:
        if after_sync:
            assert int(repo['content-counts'][content]) > 0
        else:
            assert not int(repo['content-counts'][content])


@pytest.mark.parametrize('name', **parametrized(valid_data_list()))
@pytest.mark.tier1
def test_positive_create_with_name(module_org, name):
    """Check if syncplan can be created with random names

    :id: dc0a86f7-4219-427e-92fd-29352dbdbfce

    :parametrized: yes

    :expectedresults: Sync plan is created and has random name

    :CaseImportance: Critical
    """
    sync_plan = make_sync_plan({
        'name': name,
        'organization-id': module_org.id
Exemplo n.º 8
0
class TestTailoringFiles:
    """Implements Tailoring Files tests in CLI."""
    @pytest.mark.parametrize('name', **parametrized(valid_data_list()))
    @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

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

    @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: Critical
        """
        name = gen_string('alphanumeric') + ' ' + gen_string('alphanumeric')
        tailoring_file = make_tailoringfile({
            'name':
            name,
            'scap-file':
            tailoring_file_path['satellite']
        })
        assert tailoring_file['name'] == name

    @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: Critical
        """
        name = gen_string('alphanumeric')
        make_tailoringfile({
            'name': name,
            'scap-file': tailoring_file_path['satellite']
        })
        result = TailoringFiles.info({'name': name})
        assert result['name'] == name

    @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: Critical
        """
        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]

    @tier1
    def test_negative_create_with_invalid_file(self):
        """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: Critical
        """
        ssh.upload_file(
            local_file=get_data_file(SNIPPET_DATA_FILE),
            remote_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()))
    @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: Critical
        """
        with pytest.raises(CLIFactoryError):
            make_tailoringfile({
                'name': name,
                'scap-file': tailoring_file_path['satellite']
            })

    @pytest.mark.stubbed
    @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: Critical
        """

    @pytest.mark.skip_if_open("BZ:1857572")
    @tier2
    def test_positive_download_tailoring_file(self, tailoring_file_path):
        """ 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: Critical
        """
        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[0]
        result = ssh.command(f'find {file_path} 2> /dev/null')
        assert result.return_code == 0
        assert file_path == result.stdout[0]

    @tier1
    @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: Critical
        """
        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
    @tier4
    @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

        :CaseImportance: Critical
        """

    @pytest.mark.stubbed
    @tier4
    @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

        :CaseImportance: Critical
        """

    @pytest.mark.stubbed
    @tier4
    @upgrade
    def test_positive_fetch_tailoring_file_information_from_arfreports(self):
        """ Fetch Tailoring file Information from Arf-reports
Exemplo n.º 9
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
Exemplo n.º 10
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)
Exemplo n.º 11
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


@parametrize('product_name', **parametrized(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

    :parametrized: yes

    :expectedresults: Product is created successfully in both
        organizations.

    :CaseLevel: Integration
    """
    orgs = [entities.Organization().create() for _ in range(2)]
    with session:
Exemplo n.º 12
0
@pytest.fixture(scope='module')
def content_source():
    """Return the proxy."""
    return Proxy.list({'search': f'url = https://{settings.server.hostname}:9090'})[0]


@pytest.fixture(scope='module')
def hostgroup(content_source, module_org):
    """Create a host group."""
    return make_hostgroup(
        {'content-source-id': content_source['id'], 'organization-ids': module_org.id}
    )


@pytest.mark.tier2
@pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
def test_negative_create_with_name(name):
    """Don't create an HostGroup with invalid data.

    :id: 853a6d43-129a-497b-94f0-08dc622862f8

    :parametrized: yes

    :expectedresults: HostGroup is not created.
    """
    with pytest.raises(CLIReturnCodeError):
        HostGroup.create({'name': name})


@pytest.mark.tier1
@pytest.mark.upgrade
Exemplo n.º 13
0
    :steps: Create Subnet with parameter that has single key and single
        value

    :expectedresults: The Subnet is created with parameter
    """
    parameter = [{'name': gen_string('alpha'), 'value': gen_string('alpha')}]
    subnet = entities.Subnet(subnet_parameters_attributes=parameter).create()
    assert subnet.subnet_parameters_attributes[0]['name'] == parameter[0][
        'name']
    assert subnet.subnet_parameters_attributes[0]['value'] == parameter[0][
        'value']


@pytest.mark.tier1
@pytest.mark.parametrize('name', **parametrized(generate_strings_list()))
def test_positive_add_parameter(name):
    """Parameters can be created in subnet

    :id: c1dae6f4-45b1-45db-8529-d7918e41a99b

    :parametrized: yes

    :steps:

        1. Create Subnet with all the details
        2. Create subnet parameter with single key and single value

    :expectedresults: The parameter should be created in subnet

    :CaseImportance: Medium
Exemplo n.º 14
0
class TestLocation:
    """Tests for the ``locations`` path."""

    # TODO Add coverage for media, realms as soon as they're implemented

    @pytest.fixture
    def make_proxies(self, options=None):
        """Create a Proxy"""
        proxy1 = make_proxy(options=options)
        proxy2 = make_proxy(options=options)
        yield dict(proxy1=proxy1, proxy2=proxy2)
        capsule_cleanup(proxy1['id'])
        capsule_cleanup(proxy2['id'])

    @pytest.fixture
    def make_orgs(self):
        """Create two organizations"""
        return dict(org=entities.Organization().create(),
                    org2=entities.Organization().create())

    @pytest.fixture
    def make_entities(self):
        """Set up reusable entities for tests."""
        return dict(
            domain=entities.Domain().create(),
            subnet=entities.Subnet().create(),
            env=entities.Environment().create(),
            host_group=entities.HostGroup().create(),
            template=entities.ProvisioningTemplate().create(),
            test_cr=entities.LibvirtComputeResource().create(),
            new_user=entities.User().create(),
        )

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(valid_loc_data_list()))
    def test_positive_create_with_name(self, name):
        """Create new locations using different inputs as a name

        :id: 90bb90a3-120f-4ea6-89a9-62757be42486

        :expectedresults: Location created successfully and has expected and
            correct name

        :CaseImportance: Critical

        :parametrized: yes
        """
        location = entities.Location(name=name).create()
        assert location.name == name

    @pytest.mark.tier1
    def test_positive_create_and_delete_with_comma_separated_name(self):
        """Create new location using name that has comma inside, delete location

        :id: 3131e99d-b278-462e-a650-a5a4f4e0a2f1

        :expectedresults: Location created successfully and has expected name
        """
        name = '{}, {}'.format(gen_string('alpha'), gen_string('alpha'))
        location = entities.Location(name=name).create()
        assert location.name == name
        location.delete()
        with pytest.raises(HTTPError):
            location.read()

    @pytest.mark.tier2
    def test_positive_create_and_update_with_org(self, make_orgs):
        """Create new location with assigned organization to it

        :id: 5032a93f-4b37-4c19-b6d3-26e3a868d0f1

        :expectedresults: Location created successfully and has correct
            organization assigned to it with expected title

        :CaseLevel: Integration
        """
        location = entities.Location(organization=[make_orgs['org']]).create()
        assert location.organization[0].id == make_orgs['org'].id
        assert location.organization[0].read().title == make_orgs['org'].title

        orgs = [make_orgs['org'], make_orgs['org2']]
        location.organization = orgs
        location = location.update(['organization'])
        assert {org.id
                for org in orgs} == {org.id
                                     for org in location.organization}

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
    def test_negative_create_with_name(self, name):
        """Attempt to create new location using invalid names only

        :id: 320e6bca-5645-423b-b86a-2b6f35c8dae3

        :expectedresults: Location is not created and expected error is raised

        :CaseImportance: Critical

        :parametrized: yes
        """
        with pytest.raises(HTTPError):
            entities.Location(name=name).create()

    @pytest.mark.tier1
    def test_negative_create_with_same_name(self):
        """Attempt to create new location using name of existing entity

        :id: bc09acb3-9ecf-4d23-b3ef-94f24e16e6db

        :expectedresults: Location is not created and expected error is raised

        :CaseImportance: Critical
        """
        name = gen_string('alphanumeric')
        location = entities.Location(name=name).create()
        assert location.name == name
        with pytest.raises(HTTPError):
            entities.Location(name=name).create()

    @pytest.mark.tier1
    def test_negative_create_with_domain(self):
        """Attempt to create new location using non-existent domain identifier

        :id: 5449532d-7959-4547-ba05-9e194eea495d

        :expectedresults: Location is not created and expected error is raised

        """
        with pytest.raises(HTTPError):
            entities.Location(domain=[gen_integer(10000, 99999)]).create()

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_name', **parametrized(valid_loc_data_list()))
    def test_positive_update_name(self, new_name):
        """Update location with new name

        :id: 73ff6dab-e12a-4f7d-9c1f-6984fc076329

        :expectedresults: Location updated successfully and name was changed

        :CaseImportance: Critical

        :parametrized: yes
        """
        location = entities.Location().create()
        location.name = new_name
        assert location.update(['name']).name == new_name

    @pytest.mark.tier2
    def test_positive_update_entities(self, make_entities):
        """Update location with new domain

        :id: 1016dfb9-8103-45f1-8738-0579fa9754c1

        :expectedresults: Location updated successfully and has correct domain
            assigned

        :CaseLevel: Integration
        """
        location = entities.Location().create()

        location.domain = [make_entities["domain"]]
        location.subnet = [make_entities["subnet"]]
        location.environment = [make_entities["env"]]
        location.hostgroup = [make_entities["host_group"]]
        location.provisioning_template = [make_entities["template"]]
        location.compute_resource = [make_entities["test_cr"]]
        location.user = [make_entities["new_user"]]

        assert location.update(['domain'
                                ]).domain[0].id == make_entities["domain"].id
        assert location.update(['subnet'
                                ]).subnet[0].id == make_entities["subnet"].id
        assert location.update(['environment'
                                ]).environment[0].id == make_entities["env"].id
        assert location.update(
            ['hostgroup']).hostgroup[0].id == make_entities["host_group"].id
        ct_list = [
            ct for ct in location.update(['provisioning_template'
                                          ]).provisioning_template
            if ct.id == make_entities["template"].id
        ]
        assert len(ct_list) == 1
        assert (location.update([
            'compute_resource'
        ]).compute_resource[0].id == make_entities["test_cr"].id)
        assert location.compute_resource[0].read().provider == 'Libvirt'
        assert location.update(['user'
                                ]).user[0].id == make_entities["new_user"].id

    @pytest.mark.run_in_one_thread
    @pytest.mark.tier2
    def test_positive_create_update_and_remove_capsule(self, make_proxies):
        """Update location with new capsule

        :id: 2786146f-f466-4ed8-918a-5f46806558e2

        :expectedresults: Location updated successfully and has correct capsule
            assigned

        :BZ: 1398695

        :CaseLevel: Integration

        :CaseImportance: Critical
        """
        proxy_id_1 = make_proxies['proxy1']['id']
        proxy_id_2 = make_proxies['proxy2']['id']

        proxy = entities.SmartProxy(id=proxy_id_1).read()
        location = entities.Location(smart_proxy=[proxy]).create()

        new_proxy = entities.SmartProxy(id=proxy_id_2).read()
        location.smart_proxy = [new_proxy]
        location = location.update(['smart_proxy'])
        assert location.smart_proxy[0].id == new_proxy.id
        assert location.smart_proxy[0].read().name == new_proxy.name

        location.smart_proxy = []
        location = location.update(['smart_proxy'])
        assert len(location.smart_proxy) == 0

    @pytest.mark.tier2
    def test_negative_update_domain(self):
        """Try to update existing location with incorrect domain. Use
        domain id

        :id: e26c92f2-42cb-4706-9e03-3e00a134cb9f

        :expectedresults: Location is not updated

        :CaseLevel: Integration
        """
        location = entities.Location(
            domain=[entities.Domain().create()]).create()
        domain = entities.Domain().create()
        location.domain[0].id = gen_integer(10000, 99999)
        with pytest.raises(HTTPError):
            assert location.update(['domain']).domain[0].id != domain.id

    @pytest.mark.tier1
    def test_default_loc_id_check(self):
        """test to check the default_location id

        :id: 3c89d63b-d5fb-4f05-9efb-f560f0194c85

        :BZ: 1713269

        :expectedresults: The default_location ID remain 2.

        """
        default_loc_id = entities.Location().search(
            query={'search': f'name="{DEFAULT_LOC}"'})[0].id
        assert default_loc_id == 2
Exemplo n.º 15
0
        '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})


@pytest.mark.tier2
@pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
def test_negative_create_with_name(name, module_org):
    """Check that only valid names can be used

    :id: 2da26ab2-8d79-47ea-b4d2-defcd98a0649

    :parametrized: yes

    :expectedresults: Product is not created

    :CaseImportance: High
    """
    with pytest.raises(CLIFactoryError):
        make_product({'name': name, 'organization-id': module_org.id})

Exemplo n.º 16
0
    repos_collection.setup_virtual_machine(rhel7_contenthost, target_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)
Exemplo n.º 17
0
class TestIPAAuthSource:
    """Implements FreeIPA ldap auth feature tests in CLI"""
    def _add_user_in_IPA_usergroup(self, member_username, member_group):
        self.ipa_host.execute(
            f'echo {self.ldap_ipa_user_passwd} | kinit admin', )
        self.ipa_host.execute(
            f'ipa group-add-member {member_group} --users={member_username}', )

    def _remove_user_in_IPA_usergroup(self, member_username, member_group):
        self.ipa_host.execute(
            f'echo {self.ldap_ipa_user_passwd} | kinit admin', )
        result = self.ipa_host.execute(
            f'ipa group-remove-member {member_group} --users={member_username}',
        )
        if result.status != 0:
            raise AssertionError('failed to remove the user from user-group')

    def _clean_up_previous_ldap(self):
        """clean up the all ldap settings user, usergroup and ldap delete"""
        ldap = entities.AuthSourceLDAP().search()
        for ldap_auth in range(len(ldap)):
            users = entities.User(auth_source=ldap[ldap_auth]).search()
            for user in range(len(users)):
                users[user].delete()
            ldap[ldap_auth].delete()
        user_groups = entities.UserGroup().search()
        for user_group in user_groups:
            user_group.delete()

    @pytest.mark.tier2
    @pytest.mark.parametrize('server_name',
                             **parametrized(generate_strings_list()))
    @pytest.mark.upgrade
    def test_positive_end_to_end_with_ipa(self, ipa_data, server_name,
                                          ldap_tear_down):
        """CRUD LDAP authentication with FreeIPA

        :id: 6cb54405-b579-4020-bf99-cb811a6aa28b

        :expectedresults: Whether creating/updating/deleting LDAP Auth with FreeIPA is successful.

        :parametrized: yes

        :CaseImportance: High

        """
        auth = make_ldap_auth_source({
            'name':
            server_name,
            'onthefly-register':
            'true',
            'host':
            ipa_data['ldap_hostname'],
            'server-type':
            LDAP_SERVER_TYPE['CLI']['ipa'],
            'attr-login':
            LDAP_ATTR['login'],
            'attr-firstname':
            LDAP_ATTR['firstname'],
            'attr-lastname':
            LDAP_ATTR['surname'],
            'attr-mail':
            LDAP_ATTR['mail'],
            'account':
            ipa_data['ldap_user_cn'],
            'account-password':
            ipa_data['ldap_user_passwd'],
            'base-dn':
            ipa_data['base_dn'],
            'groups-base':
            ipa_data['group_base_dn'],
        })
        assert auth['server']['name'] == server_name
        assert auth['server']['server'] == ipa_data['ldap_hostname']
        assert auth['server']['server-type'] == LDAP_SERVER_TYPE['CLI']['ipa']
        new_name = gen_string('alpha')
        LDAPAuthSource.update({'name': server_name, 'new-name': new_name})
        updated_auth = LDAPAuthSource.info({'id': auth['server']['id']})
        assert updated_auth['server']['name'] == new_name
        LDAPAuthSource.delete({'name': new_name})
        with pytest.raises(CLIReturnCodeError):
            LDAPAuthSource.info({'name': new_name})

    @pytest.mark.tier3
    def test_usergroup_sync_with_refresh(self, ipa_data, ldap_tear_down):
        """Verify the refresh functionality in Ldap Auth Source

        :id: c905eb80-2bd0-11ea-abc3-ddb7dbb3c930

        :expectedresults: external user-group sync works as expected as on-demand
            sync based on refresh works

        :CaseImportance: Medium
        """
        self._clean_up_previous_ldap()
        self.ipa_host = ssh.get_client(hostname=ipa_data['ldap_hostname'])
        self.ldap_ipa_user_passwd = ipa_data['ldap_user_passwd']
        ipa_group_base_dn = ipa_data['group_base_dn'].replace(
            'foobargroup', 'foreman_group')
        member_username = '******'
        member_group = 'foreman_group'
        LOGEDIN_MSG = "Using configured credentials for user '{0}'."
        auth_source_name = gen_string('alpha')
        auth_source = make_ldap_auth_source({
            'name':
            auth_source_name,
            'onthefly-register':
            'true',
            'usergroup-sync':
            'false',
            'host':
            ipa_data['ldap_hostname'],
            'server-type':
            LDAP_SERVER_TYPE['CLI']['ipa'],
            'attr-login':
            LDAP_ATTR['login'],
            'attr-firstname':
            LDAP_ATTR['firstname'],
            'attr-lastname':
            LDAP_ATTR['surname'],
            'attr-mail':
            LDAP_ATTR['mail'],
            'account':
            ipa_data['ldap_user_cn'],
            'account-password':
            ipa_data['ldap_user_passwd'],
            'base-dn':
            ipa_data['base_dn'],
            'groups-base':
            ipa_group_base_dn,
        })
        auth_source = LDAPAuthSource.info({'id': auth_source['server']['id']})

        # Adding User in IPA UserGroup
        self._add_user_in_IPA_usergroup(member_username, member_group)
        viewer_role = Role.info({'name': 'Viewer'})
        user_group = make_usergroup()
        ext_user_group = make_usergroup_external({
            'auth-source-id':
            auth_source['server']['id'],
            'user-group-id':
            user_group['id'],
            'name':
            member_group,
        })
        UserGroup.add_role({
            'id': user_group['id'],
            'role-id': viewer_role['id']
        })
        assert ext_user_group['auth-source'] == auth_source['server']['name']
        user_group = UserGroup.info({'id': user_group['id']})
        assert len(user_group['users']) == 0
        result = Auth.with_user(username=member_username,
                                password=self.ldap_ipa_user_passwd).status()
        assert LOGEDIN_MSG.format(member_username) in result[0]['message']
        with pytest.raises(CLIReturnCodeError) as error:
            Role.with_user(username=member_username,
                           password=self.ldap_ipa_user_passwd).list()
        assert 'Missing one of the required permissions' in error.value.message
        UserGroupExternal.refresh({
            'user-group-id': user_group['id'],
            'name': member_group
        })
        list = Role.with_user(username=member_username,
                              password=self.ldap_ipa_user_passwd).list()
        assert len(list) > 1
        user_group = UserGroup.info({'id': user_group['id']})
        assert len(user_group['users']) == 1
        assert user_group['users'][0] == member_username

        # Removing User in IPA UserGroup
        self._remove_user_in_IPA_usergroup(member_username, member_group)
        UserGroupExternal.refresh({
            'user-group-id': user_group['id'],
            'name': member_group
        })
        user_group = UserGroup.info({'id': user_group['id']})
        assert len(user_group['users']) == 0
        with pytest.raises(CLIReturnCodeError) as error:
            Role.with_user(username=member_username,
                           password=self.ldap_ipa_user_passwd).list()
        assert 'Missing one of the required permissions' in error.value.message

    @pytest.mark.tier3
    def test_usergroup_with_usergroup_sync(self, ipa_data, ldap_tear_down):
        """Verify the usergroup-sync functionality in Ldap Auth Source

        :id: 2b63e886-2c53-11ea-9da5-db3ae0527554

        :expectedresults: external user-group sync works as expected automatically
            based on user-sync

        :CaseImportance: Medium
        """
        self._clean_up_previous_ldap()
        self.ipa_host = ssh.get_client(hostname=ipa_data['ldap_hostname'])
        self.ldap_ipa_user_passwd = ipa_data['ldap_user_passwd']
        ipa_group_base_dn = ipa_data['group_base_dn'].replace(
            'foobargroup', 'foreman_group')
        member_username = '******'
        member_group = 'foreman_group'
        LOGEDIN_MSG = "Using configured credentials for user '{0}'."
        auth_source_name = gen_string('alpha')
        auth_source = make_ldap_auth_source({
            'name':
            auth_source_name,
            'onthefly-register':
            'true',
            'usergroup-sync':
            'true',
            'host':
            ipa_data['ldap_hostname'],
            'server-type':
            LDAP_SERVER_TYPE['CLI']['ipa'],
            'attr-login':
            LDAP_ATTR['login'],
            'attr-firstname':
            LDAP_ATTR['firstname'],
            'attr-lastname':
            LDAP_ATTR['surname'],
            'attr-mail':
            LDAP_ATTR['mail'],
            'account':
            ipa_data['ldap_user_cn'],
            'account-password':
            ipa_data['ldap_user_passwd'],
            'base-dn':
            ipa_data['base_dn'],
            'groups-base':
            ipa_group_base_dn,
        })
        auth_source = LDAPAuthSource.info({'id': auth_source['server']['id']})

        # Adding User in IPA UserGroup
        self._add_user_in_IPA_usergroup(member_username, member_group)
        viewer_role = Role.info({'name': 'Viewer'})
        user_group = make_usergroup()
        ext_user_group = make_usergroup_external({
            'auth-source-id':
            auth_source['server']['id'],
            'user-group-id':
            user_group['id'],
            'name':
            member_group,
        })
        UserGroup.add_role({
            'id': user_group['id'],
            'role-id': viewer_role['id']
        })
        assert ext_user_group['auth-source'] == auth_source['server']['name']
        user_group = UserGroup.info({'id': user_group['id']})
        assert len(user_group['users']) == 0
        result = Auth.with_user(username=member_username,
                                password=self.ldap_ipa_user_passwd).status()
        assert LOGEDIN_MSG.format(member_username) in result[0]['message']
        list = Role.with_user(username=member_username,
                              password=self.ldap_ipa_user_passwd).list()
        assert len(list) > 1
        user_group = UserGroup.info({'id': user_group['id']})
        assert len(user_group['users']) == 1
        assert user_group['users'][0] == member_username

        # Removing User in IPA UserGroup
        self._remove_user_in_IPA_usergroup(member_username, member_group)
        with pytest.raises(CLIReturnCodeError) as error:
            Role.with_user(username=member_username,
                           password=self.ldap_ipa_user_passwd).list()
        assert 'Missing one of the required permissions' in error.value.message
        user_group = UserGroup.info({'id': user_group['id']})
        assert len(user_group['users']) == 0
Exemplo n.º 18
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()
    :CaseLevel: Component
    """
    comp_res = make_compute_resource({
        'provider': FOREMAN_PROVIDERS['libvirt'],
        'url': libvirt_url
    })
    assert comp_res['name']
    ComputeResource.delete({'name': comp_res['name']})
    result = ComputeResource.exists(search=('name', comp_res['name']))
    assert len(result) == 0


# Positive create
@pytest.mark.tier1
@pytest.mark.upgrade
@pytest.mark.parametrize('options', **parametrized(valid_name_desc_data()))
def test_positive_create_with_libvirt(libvirt_url, options):
    """Test Compute Resource create

    :id: adc6f4f8-6420-4044-89d1-c69e0bfeeab9

    :expectedresults: Compute Resource created

    :CaseImportance: Critical

    :CaseLevel: Component

    :parametrized: yes
    """
    ComputeResource.create({
        'description': options['description'],
Exemplo n.º 20
0
class TestArchitecture:
    """Architecture CLI related tests."""

    @pytest.fixture(scope='class')
    def class_architecture(self):
        """Shared architecture for tests"""
        return make_architecture()

    @pytest.mark.tier1
    def test_positive_CRUD(self):
        """Create a new Architecture, update the name and delete the Architecture itself.

        :id: cd8654b8-e603-11ea-adc1-0242ac120002

        :expectedresults: Architecture is created, modified and deleted successfully

        :CaseImportance: Critical
        """

        name = gen_choice(list(valid_data_list().values()))
        new_name = gen_choice(list(valid_data_list().values()))

        architecture = make_architecture({'name': name})
        assert architecture['name'] == name
        Architecture.update({'id': architecture['id'], 'new-name': new_name})
        architecture = Architecture.info({'id': architecture['id']})
        assert architecture['name'] == new_name
        Architecture.delete({'id': architecture['id']})
        with pytest.raises(CLIReturnCodeError):
            Architecture.info({'id': architecture['id']})

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
    def test_negative_create_with_name(self, name):
        """Don't create an Architecture with invalid data.

        :id: cfed972e-9b09-4852-bdd2-b5a8a8aed170

        :parametrized: yes

        :expectedresults: Architecture is not created.

        :CaseImportance: Medium
        """

        with pytest.raises(CLIReturnCodeError) as error:
            Architecture.create({'name': name})

        assert 'Could not create the architecture:' in error.value.message

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_name', **parametrized(invalid_values_list()))
    def test_negative_update_name(self, class_architecture, new_name):
        """Create Architecture then fail to update its name

        :id: 037c4892-5e62-46dd-a2ed-92243e870e40

        :parametrized: yes

        :expectedresults: Architecture name is not updated

        :CaseImportance: Medium
        """

        with pytest.raises(CLIReturnCodeError) as error:
            Architecture.update({'id': class_architecture['id'], 'new-name': new_name})

        assert 'Could not update the architecture:' in error.value.message

        result = Architecture.info({'id': class_architecture['id']})
        assert class_architecture['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 architecture by invalid ID

        :id: 78bae664-6493-4c74-a587-94170f20746e

        :parametrized: yes

        :expectedresults: Architecture is not deleted

        :CaseImportance: Medium
        """
        with pytest.raises(CLIReturnCodeError) as error:
            Architecture.delete({'id': entity_id})

        assert 'Could not delete the architecture' in error.value.message
Exemplo n.º 21
0
from robottelo.constants import DISTRO_RHEL7
from robottelo.datafactory import invalid_values_list
from robottelo.datafactory import parametrized
from robottelo.datafactory import valid_data_list
from robottelo.vm import VirtualMachine


@pytest.fixture(scope='module')
def fake_hosts(module_org):
    """Create content hosts that can be shared by tests."""
    hosts = [entities.Host(organization=module_org).create() for _ in range(2)]
    return hosts


@pytest.mark.parametrize('name', **parametrized(valid_data_list()))
@pytest.mark.tier1
def test_positive_create_with_name(module_org, name):
    """Create host collections with different names.

    :id: 8f2b9223-f5be-4cb1-8316-01ea747cae14

    :parametrized: yes

    :expectedresults: The host collection was successfully created and has
        appropriate name.

    :CaseImportance: Critical
    """
    host_collection = entities.HostCollection(
        name=name, organization=module_org).create()
Exemplo n.º 22
0
class TestOrganizationUpdate:
    """Tests for the ``organizations`` path."""
    @pytest.fixture
    def module_org(self):
        """Create an organization."""
        return entities.Organization().create()

    @tier1
    @pytest.mark.parametrize('name', **parametrized(valid_org_data_list()))
    def test_positive_update_name(self, module_org, name):
        """Update an organization's name with valid values.

        :id: 68f2ba13-2538-407c-9f33-2447fca28cd5

        :expectedresults: The organization's name is updated.

        :CaseImportance: Critical

        :parametrized: yes
        """
        setattr(module_org, 'name', name)
        module_org = module_org.update(['name'])
        assert module_org.name == name

    @tier1
    @pytest.mark.parametrize('desc', **parametrized(valid_org_data_list()))
    def test_positive_update_description(self, module_org, desc):
        """Update an organization's description with valid values.

        :id: bd223197-1021-467e-8714-c1a767ae89af

        :expectedresults: The organization's description is updated.

        :CaseImportance: Critical

        :parametrized: yes
        """
        setattr(module_org, 'description', desc)
        module_org = module_org.update(['description'])
        assert module_org.description == desc

    @tier2
    def test_positive_update_user(self, module_org):
        """Update an organization, associate user with it.

        :id: 2c0c0061-5b4e-4007-9f54-b61d6e65ef58

        :expectedresults: User is associated with organization.

        :CaseLevel: Integration
        """
        user = entities.User().create()
        module_org.user = [user]
        module_org = module_org.update(['user'])
        assert len(module_org.user) == 1
        assert module_org.user[0].id == user.id

    @tier2
    def test_positive_update_subnet(self, module_org):
        """Update an organization, associate subnet with it.

        :id: 3aa0b9cb-37f7-4e7e-a6ec-c1b407225e54

        :expectedresults: Subnet is associated with organization.

        :CaseLevel: Integration
        """
        subnet = entities.Subnet().create()
        module_org.subnet = [subnet]
        module_org = module_org.update(['subnet'])
        assert len(module_org.subnet) == 1
        assert module_org.subnet[0].id == subnet.id

    @tier2
    def test_positive_add_and_remove_hostgroup(self):
        """Add a hostgroup to an organization and then remove it

        :id: 7eb1aca7-fd7b-404f-ab18-21be5052a11f

        :BZ: 1395229

        :expectedresults: Hostgroup is added to organization and then removed

        :CaseLevel: Integration
        """
        org = entities.Organization().create()
        hostgroup = entities.HostGroup().create()
        org.hostgroup = [hostgroup]
        org = org.update(['hostgroup'])
        assert len(org.hostgroup) == 1
        org.hostgroup = []
        org = org.update(['hostgroup'])
        assert len(org.hostgroup) == 0

    @upgrade
    @tier2
    def test_positive_add_and_remove_smart_proxy(self):
        """Add a smart proxy to an organization

        :id: e21de720-3fa2-429b-bd8e-b6a48a13146d

        :expectedresults: Smart proxy is successfully added to organization

        :BZ: 1395229

        :CaseLevel: Integration
        """
        # Every Satellite has a built-in smart proxy, so let's find it
        smart_proxy = entities.SmartProxy().search(query={
            'search':
            'url = https://{0}:9090'.format(settings.server.hostname)
        })
        # Check that proxy is found and unpack it from the list
        assert len(smart_proxy) > 0
        smart_proxy = smart_proxy[0]
        # By default, newly created organization uses built-in smart proxy,
        # so we need to remove it first
        org = entities.Organization().create()
        org.smart_proxy = []
        org = org.update(['smart_proxy'])
        # Verify smart proxy was actually removed
        assert len(org.smart_proxy) == 0

        # Add smart proxy to organization
        org.smart_proxy = [smart_proxy]
        org = org.update(['smart_proxy'])
        # Verify smart proxy was actually added
        assert len(org.smart_proxy) == 1
        assert org.smart_proxy[0].id == smart_proxy.id

        org.smart_proxy = []
        org = org.update(['smart_proxy'])
        # Verify smart proxy was actually removed
        assert len(org.smart_proxy) == 0

    @tier1
    @pytest.mark.parametrize(
        'attrs',
        # Immutable. See BZ 1089996.
        [
            {
                'name': gen_string(str_type='utf8', length=256)
            },
            {
                'label': gen_string(str_type='utf8')
            },
        ],
        ids=['name', 'label'],
    )
    def test_negative_update(self, module_org, attrs):
        """Update an organization's attributes with invalid values.

        :id: b7152d0b-5ab0-4d68-bfdf-f3eabcb5fbc6

        :expectedresults: The organization's attributes are not updated.

        :CaseImportance: Critical

        :parametrized: yes
        """
        with pytest.raises(HTTPError):
            entities.Organization(id=module_org.id,
                                  **attrs).update(attrs.keys())
Exemplo n.º 23
0
    :CaseLevel: Acceptance
    """
    org = entities.Organization().create()
    prod = entities.Product(organization=org).create()
    setting_update.value = download_policy
    setting_update.update({'value'})
    repo = entities.Repository(product=prod,
                               content_type='yum',
                               organization=org).create()
    assert repo.download_policy == download_policy
    repo.delete()
    prod.delete()


@pytest.mark.tier2
@pytest.mark.parametrize('valid_value', **parametrized(valid_timeout_values()))
@pytest.mark.parametrize('setting_update', ['sync_connect_timeout_v2'],
                         indirect=True)
def test_positive_update_sync_timeout(setting_update, valid_value):
    """Check that values from provided range can be set to
    sync connection timeout

    :id: e25cd07b-a4a7-4ad3-9053-ad0bbaffbab7

    :CaseImportance: Medium

    :parametrized: yes

    :expectedresults: Default timeout should be updated with new value
    """
    setting_update.value = valid_value
Exemplo n.º 24
0
class TestOrganization:
    """Tests for the ``organizations`` path."""
    @tier1
    def test_positive_create(self):
        """Create an organization using a 'text/plain' content-type.

        :id: 6f67a3f0-0c1d-498c-9a35-28207b0faec2

        :expectedresults: HTTP 415 is returned.

        :CaseImportance: Critical
        """
        organization = entities.Organization()
        organization.create_missing()
        response = client.post(
            organization.path(),
            organization.create_payload(),
            auth=settings.server.get_credentials(),
            headers={'content-type': 'text/plain'},
            verify=False,
        )
        assert http.client.UNSUPPORTED_MEDIA_TYPE == response.status_code

    @tier1
    @pytest.mark.parametrize('name', **parametrized(valid_org_data_list()))
    def test_positive_create_with_name_and_description(self, name):
        """Create an organization and provide a name and description.

        :id: afeea84b-61ca-40bf-bb16-476432919115

        :expectedresults: The organization has the provided attributes and an
            auto-generated label.

        :CaseImportance: Critical

        :parametrized: yes
        """
        org = entities.Organization(name=name, description=name).create()
        assert org.name == name
        assert org.description == name

        # Was a label auto-generated?
        assert hasattr(org, 'label')
        assert isinstance(org.label, type(''))
        assert len(org.label) > 0

    @tier1
    @pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
    def test_negative_create_with_invalid_name(self, name):
        """Create an org with an incorrect name.

        :id: 9c6a4b45-a98a-4d76-9865-92d992fa1a22

        :expectedresults: The organization cannot be created.

        :parametrized: yes
        """
        with pytest.raises(HTTPError):
            entities.Organization(name=name).create()

    @tier1
    def test_negative_create_with_same_name(self):
        """Create two organizations with identical names.

        :id: a0f5333c-cc83-403c-9bf7-08fb372909dc

        :expectedresults: The second organization cannot be created.

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

    @tier1
    def test_positive_search(self):
        """Create an organization, then search for it by name.

        :id: f6f1d839-21f2-4676-8683-9f899cbdec4c

        :expectedresults: Searching returns at least one result.

        :CaseImportance: Critical
        """
        org = entities.Organization().create()
        orgs = entities.Organization().search(
            query={'search': 'name="{0}"'.format(org.name)})
        assert len(orgs) == 1
        assert orgs[0].id == org.id
        assert orgs[0].name == org.name

    @tier1
    def test_negative_create_with_wrong_path(self):
        """Attempt to create an organization using foreman API path
        (``api/v2/organizations``)

        :id: 499ae5ef-b1e4-4fb8-967a-57d525e06326

        :BZ: 1241068

        :expectedresults: API returns 404 error with 'Route overriden by
            Katello' message

        :CaseImportance: Critical
        """
        org = entities.Organization()
        org._meta['api_path'] = 'api/v2/organizations'
        with pytest.raises(HTTPError) as err:
            org.create()
        assert err.value.response.status_code == 404
        assert 'Route overriden by Katello' in err.value.response.text

    @tier2
    def test_default_org_id_check(self):
        """test to check the default_organization id

        :id: df066396-a069-4e9e-b3c1-c6d34a755ec0

        :BZ: 1713269

        :expectedresults: The default_organization ID remain 1.

        :CaseImportance: Low
        """
        default_org_id = (entities.Organization().search(
            query={'search': 'name="{}"'.format(DEFAULT_ORG)})[0].id)
        assert default_org_id == 1
Exemplo n.º 25
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=settings.server.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=settings.server.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.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.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'])
Exemplo n.º 26
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})
Exemplo n.º 27
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()
    pytest.mark.skip_if_not_set('libvirt'),
]


@pytest.fixture(scope="module")
def setup():
    """Set up organization and location for tests."""
    setupEntities = type("", (), {})()
    setupEntities.org = entities.Organization().create()
    setupEntities.loc = entities.Location(organization=[setupEntities.org]).create()
    setupEntities.current_libvirt_url = LIBVIRT_RESOURCE_URL % settings.libvirt.libvirt_hostname
    return setupEntities


@pytest.mark.tier1
@pytest.mark.parametrize('name', **parametrized(valid_data_list()))
def test_positive_create_with_name(setup, name):
    """Create compute resources with different names

    :id: 1e545c56-2f53-44c1-a17e-38c83f8fe0c1

    :expectedresults: Compute resources are created with expected names

    :CaseImportance: Critical

    :CaseLevel: Component

    :parametrized: yes
    """
    compresource = entities.LibvirtComputeResource(
        location=[setup.loc],
Exemplo n.º 29
0
from robottelo import manifests
from robottelo import ssh
from robottelo.api.utils import upload_manifest
from robottelo.config import settings
from robottelo.constants import VALID_GPG_KEY_BETA_FILE
from robottelo.constants import VALID_GPG_KEY_FILE
from robottelo.constants.repos import FAKE_1_PUPPET_REPO
from robottelo.constants.repos import FAKE_1_YUM_REPO
from robottelo.datafactory import invalid_values_list
from robottelo.datafactory import parametrized
from robottelo.datafactory import valid_data_list
from robottelo.helpers import read_data_file


@pytest.mark.tier1
@pytest.mark.parametrize('name', **parametrized(valid_data_list()))
def test_positive_create_with_name(request, name, module_org):
    """Create a product providing different valid names

    :id: 3d873b73-6919-4fda-84df-0e26bdf0c1dc

    :parametrized: yes

    :expectedresults: A product is created with expected name.

    :CaseImportance: Critical
    """
    product = entities.Product(name=name, organization=module_org).create()
    assert product.name == name

Exemplo n.º 30
0
class TestRole:
    """Test class for Roles CLI"""
    @pytest.mark.tier1
    @pytest.mark.parametrize(
        'name, new_name',
        **parametrized(
            list(
                zip(generate_strings_list(length=10),
                    generate_strings_list(length=10)))),
    )
    def test_positive_crud_with_name(self, name, new_name):
        """Create new role with provided name, update name and delete role by ID

        :id: f77b8e84-e964-4007-b12b-142949134d8b

        :parametrized: yes

        :expectedresults: Role is created and has correct name, its name is updated
            and then deleted by ID

        :BZ: 1138553

        :CaseImportance: Critical
        """
        role = make_role({'name': name})
        assert role['name'] == name
        Role.update({'id': role['id'], 'new-name': new_name})
        role = Role.info({'id': role['id']})
        assert role['name'] == new_name
        Role.delete({'id': role['id']})
        with pytest.raises(CLIReturnCodeError):
            Role.info({'id': role['id']})

    @pytest.mark.tier1
    @pytest.mark.upgrade
    @pytest.mark.build_sanity
    def test_positive_create_with_permission(self):
        """Create new role with a set of permission

        :id: 7cb2b2e2-ad4d-41e9-b6b2-c0366eb09b9a

        :expectedresults: Role is created and has correct set of permissions

        :CaseImportance: Critical
        """
        role = make_role()
        # Pick permissions by its resource type
        permissions = [
            permission['name'] for permission in Filter.available_permissions(
                {"search": "resource_type=Organization"})
        ]
        # Assign filter to created role
        make_filter({'role-id': role['id'], 'permissions': permissions})
        assert set(Role.filters({'id': role['id']
                                 })[0]['permissions']) == set(permissions)

    @pytest.mark.tier1
    def test_positive_list_filters_by_id(self):
        """Create new role with a filter and list it by role id

        :id: 6979ad8d-629b-481e-9d3a-8f3b3bca53f9

        :expectedresults: Filter is listed for specified role

        :CaseImportance: Critical
        """
        role = make_role()
        # Pick permissions by its resource type
        permissions = [
            permission['name'] for permission in Filter.available_permissions(
                {"search": "resource_type=Organization"})
        ]
        # Assign filter to created role
        filter_ = make_filter({
            'role-id': role['id'],
            'permissions': permissions
        })
        assert role['name'] == filter_['role']
        assert Role.filters({'id': role['id']})[0]['id'] == filter_['id']

    @pytest.mark.tier1
    def test_positive_list_filters_by_name(self):
        """Create new role with a filter and list it by role name

        :id: bbcb3982-f484-4dde-a3ea-7145fd28ab1f

        :expectedresults: Filter is listed for specified role

        :CaseImportance: Critical
        """
        role = make_role()
        # Pick permissions by its resource type
        permissions = [
            permission['name'] for permission in Filter.available_permissions(
                {"search": "resource_type=Organization"})
        ]
        # Assign filter to created role
        filter_ = make_filter({
            'role': role['name'],
            'permissions': permissions
        })
        assert role['name'] == filter_['role']
        assert Role.filters({'name': role['name']})[0]['id'] == filter_['id']

    @pytest.mark.tier1
    def test_negative_list_filters_without_parameters(self):
        """Try to list filter without specifying role id or name

        :id: 56cafbe0-d1cb-413e-8eac-0e01a3590fd2

        :expectedresults: Proper error message is shown instead of SQL error

        :CaseImportance: Critical

        :BZ: 1296782
        """
        with pytest.raises(CLIReturnCodeError) as err:
            try:
                Role.filters()
            except CLIDataBaseError as err:
                pytest.fail(err)
        assert re.search('At least one of options .* is required',
                         err.value.msg)

    @pytest.fixture()
    def make_role_with_permissions(self):
        """Create new role with a filter"""
        role = make_role()
        res_types = iter(PERMISSIONS.keys())
        permissions = []
        # Collect more than 20 different permissions
        while len(permissions) <= 20:
            permissions += [
                permission['name']
                for permission in Filter.available_permissions(
                    {"search": f"resource_type={next(res_types)}"})
            ]
        # Create a filter for each permission
        for perm in permissions:
            make_filter({'role': role['name'], 'permissions': perm})
        return {
            'role': role,
            'permissions': permissions,
        }

    @pytest.mark.tier1
    @pytest.mark.upgrade
    @pytest.mark.parametrize('per_page', [1, 5, 20])
    def test_positive_list_filters_with_pagination(self,
                                                   make_role_with_permissions,
                                                   per_page):
        """Make sure filters list can be displayed with different items per
        page value

        :id: b9c7c6c1-70c2-4d7f-8d36-fa8613acc865

        :BZ: 1428516

        :expectedresults: `per-page` correctly sets amount of items displayed
            per page, different `per-page` values divide a list into correct
            number of pages

        :CaseImportance: Critical

        :parametrized: yes
        """
        # Verify the first page contains exactly the same items count
        # as `per-page` value
        filters = Role.filters({
            'name':
            make_role_with_permissions['role']['name'],
            'per-page':
            per_page
        })
        assert len(filters) == per_page
        # Verify pagination and total amount of pages by checking the
        # items count on the last page
        last_page = ceil(
            len(make_role_with_permissions['permissions']) / per_page)
        filters = Role.filters({
            'name':
            make_role_with_permissions['role']['name'],
            'page':
            last_page,
            'per-page':
            per_page,
        })
        assert len(filters) == (
            len(make_role_with_permissions['permissions']) % per_page
            or per_page)

    @pytest.mark.tier1
    @pytest.mark.upgrade
    def test_positive_delete_cloned_builtin(self):
        """Clone a builtin role and attempt to delete it

        :id: 1fd9c636-596a-4cb2-b100-de19238042cc

        :BZ: 1426672

        :expectedresults: role was successfully deleted

        :CaseImportance: Critical

        """
        role_list = Role.list(
            {'search': 'name=\\"{}\\"'.format(choice(ROLES))})
        assert len(role_list) == 1
        cloned_role = Role.clone({
            'id': role_list[0]['id'],
            'new-name': gen_string('alphanumeric')
        })
        Role.delete({'id': cloned_role['id']})
        with pytest.raises(CLIReturnCodeError):
            Role.info({'id': cloned_role['id']})