Python hamcrest.has_item() Examples

The following are 27 code examples of hamcrest.has_item(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module hamcrest , or try the search function .
Example #1
Source File: test_configure_interface.py    From fake-switches with Apache License 2.0 6 votes vote down vote up
def test_show_run_vs_show_run_interface_same_output(self, t):
        enable(t)
        configuring_interface(t, "tengigabitethernet 0/0/1", do="shutdown")
        assert_interface_configuration(t, "tengigabitethernet 0/0/1", [
            "shutdown"
        ])

        assert_running_config_contains_in_order(t, [
            "interface tengigabitethernet 0/0/1",
            "shutdown",
            "exit",
            "!",
        ])

        configuring_interface(t, "tengigabitethernet 0/0/1", do="no shutdown")

        assert_interface_configuration(t, "tengigabitethernet 0/0/1", [
            ""
        ])

        config = get_running_config(t)
        assert_that(config, is_not(has_item("interface tengigabitethernet 0/0/1"))) 
Example #2
Source File: test_configure_interface.py    From fake-switches with Apache License 2.0 6 votes vote down vote up
def test_show_run_vs_show_run_interface_same_output(self, t):
        enable(t)
        configuring_interface(t, "ethernet 1/g1", do="shutdown")
        assert_interface_configuration(t, "ethernet 1/g1", [
            "shutdown"
        ])

        assert_running_config_contains_in_order(t, [
            "interface ethernet 1/g1",
            "shutdown",
            "exit",
            "!",
        ])

        configuring_interface(t, "ethernet 1/g1", do="no shutdown")

        assert_interface_configuration(t, "ethernet 1/g1", [
            ""
        ])

        config = get_running_config(t)
        assert_that(config, is_not(has_item("interface ethernet 1/g1"))) 
Example #3
Source File: test__class_api.py    From django-river with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_shouldAssesFinalStateProperlyWhenThereIsOnlyOne(self):
        state1 = StateObjectFactory(label="state1")
        state2 = StateObjectFactory(label="state2")

        workflow = WorkflowFactory(initial_state=state1, content_type=self.content_type, field_name="my_field")

        transition_meta = TransitionMetaFactory.create(
            workflow=workflow,
            source_state=state1,
            destination_state=state2,
        )
        TransitionApprovalMetaFactory.create(
            workflow=workflow,
            transition_meta=transition_meta,
            priority=0
        )
        assert_that(BasicTestModel.river.my_field.final_states, has_length(1))
        assert_that(list(BasicTestModel.river.my_field.final_states), has_item(state2)) 
Example #4
Source File: api.py    From selene-backend with GNU Affero General Public License v3.0 6 votes vote down vote up
def validate_token_cookies(context, expired=False):
    for cookie in context.response.headers.getlist('Set-Cookie'):
        ingredients = _parse_cookie(cookie)
        ingredient_names = list(ingredients.keys())
        if ACCESS_TOKEN_COOKIE_KEY in ingredient_names:
            context.access_token = ingredients[ACCESS_TOKEN_COOKIE_KEY]
        elif REFRESH_TOKEN_COOKIE_KEY in ingredient_names:
            context.refresh_token = ingredients[REFRESH_TOKEN_COOKIE_KEY]
        for ingredient_name in ('Domain', 'Expires', 'Max-Age'):
            assert_that(ingredient_names, has_item(ingredient_name))
        if expired:
            assert_that(ingredients['Max-Age'], equal_to('0'))

    assert hasattr(context, 'access_token'), 'no access token in response'
    assert hasattr(context, 'refresh_token'), 'no refresh token in response'
    if expired:
        assert_that(context.access_token, equal_to(''))
        assert_that(context.refresh_token, equal_to('')) 
Example #5
Source File: profile.py    From selene-backend with GNU Affero General Public License v3.0 6 votes vote down vote up
def validate_response(context):
    response_data = context.response.json
    account = context.accounts['foo']
    assert_that(
        response_data['emailAddress'],
        equal_to(account.email_address)
    )
    assert_that(
        response_data['membership']['type'],
        equal_to('Monthly Membership')
    )
    assert_that(response_data['membership']['duration'], none())
    assert_that(
        response_data['membership'], has_item('id')
    )

    assert_that(len(response_data['agreements']), equal_to(3))
    agreement = response_data['agreements'][0]
    assert_that(agreement['type'], equal_to(PRIVACY_POLICY))
    assert_that(
        agreement['acceptDate'],
        equal_to(str(date.today().strftime('%B %d, %Y')))
    )
    assert_that(agreement, has_item('id')) 
Example #6
Source File: bond_management_test.py    From netman with Apache License 2.0 6 votes vote down vote up
def test_creating_deleting_a_bond(self):
        self.client.add_bond(3)

        list_of_bonds = self.client.get_bonds()
        assert_that(list_of_bonds, has_item(has_properties(number=3)))

        bond = self.client.get_bond(3)
        assert_that(bond, has_properties(number=3))

        self.client.remove_bond(3)

        new_list_of_bonds = self.client.get_bonds()
        assert_that(new_list_of_bonds, is_not(has_item(has_properties(number=3))))

        with self.assertRaises(UnknownBond):
            self.client.get_bond(3) 
Example #7
Source File: verifiers.py    From storops with Apache License 2.0 6 votes vote down vote up
def verify_raid0(rg):
    assert_that(rg.raid_group_id, equal_to(0))
    assert_that(rg.raid_group_type, equal_to(VNXRaidType.RAID5))
    assert_that(rg.state, equal_to('Valid_luns'))
    assert_that(rg.disks.index,
                has_items('0_0_A0', '0_0_A1', '0_0_A2', '0_0_A3', '0_0_A4'))
    assert_that(rg.list_of_luns, has_item(63868))
    assert_that(len(rg.list_of_luns), equal_to(16))
    assert_that(rg.max_number_of_disks, equal_to(16))
    assert_that(rg.max_number_of_luns, equal_to(256))
    assert_that(rg.raw_capacity_blocks, equal_to(4502487040))
    assert_that(rg.logical_capacity_blocks, equal_to(4502478848))
    assert_that(rg.free_capacity_blocks_non_contiguous,
                equal_to(3744083968))
    assert_that(rg.free_contiguous_group_of_unbound_segments,
                equal_to(1749913216))
    assert_that(rg.defrag_expand_priority, equal_to('N/A'))
    assert_that(rg.percent_defragmented, none())
    assert_that(rg.percent_expanded, none())
    assert_that(rg.disk_expanding_onto, equal_to('N/A'))
    assert_that(rg.lun_expansion_enabled, equal_to(False))
    assert_that(rg.legal_raid_types[0], equal_to(VNXRaidType.RAID5)) 
Example #8
Source File: remove_interface_from_bond_test.py    From netman with Apache License 2.0 5 votes vote down vote up
def test_removes_interface_from_bond(self):
        self.client.remove_interface_from_bond(self.test_port)
        bond = self.client.get_bond(42)

        assert_that(bond.members, not_(has_item(self.test_port))) 
Example #9
Source File: container.py    From allure-python with Apache License 2.0 5 votes vote down vote up
def has_fixture(section, name, *matchers):
    return has_entry(section,
                     has_item(
                         all_of(
                             has_entry('name', equal_to(name)),
                             *matchers
                         )
                     )) 
Example #10
Source File: container.py    From allure-python with Apache License 2.0 5 votes vote down vote up
def _matches(self, report):
        return has_property('test_containers',
                            has_item(
                                     all_of(
                                            has_entry('children',
                                                      all_of(
                                                             *[has_item(self._test_case_id_by_name(report, name))
                                                               for name in self.test_case_names]
                                                      )),
                                            *self.matchers
                                     )
                            )
               ).matches(report)

    # TODO better describe 
Example #11
Source File: container.py    From allure-python with Apache License 2.0 5 votes vote down vote up
def _matches(self, item):
        return has_property('test_containers',
                            has_item(
                                     all_of(
                                            has_entry('children', has_item(item['uuid'])),
                                            *self.matchers
                                     )
                            )).matches(self.report) 
Example #12
Source File: test_okid10_index.py    From cifrum with GNU General Public License v3.0 5 votes vote down vote up
def test__present_in_available_names():
    sym_ids = [x.fin_sym_id.format() for x in lib.available_names(namespace='index')]
    assert_that(sym_ids, has_item(__asset_name)) 
Example #13
Source File: test_share.py    From storops with Apache License 2.0 5 votes vote down vote up
def test_nfs_share_mixed_host_access(unity_gf):
    share = unity_gf.nfs_share
    share.allow_read_only_access('1.1.1.3', force_create_host=True)
    share.allow_root_access('1.1.1.4', force_create_host=True)
    share.update()
    assert_that(share.read_only_hosts.ip_list, has_item('1.1.1.3'))
    assert_that(share.root_access_hosts.ip_list, has_item('1.1.1.4'))

    share.deny_access(['1.1.1.3', '1.1.1.4'])
    share.update()
    assert_that(share.read_only_hosts, none())
    assert_that(share.root_access_hosts, none())
    assert_that(share.no_access_hosts.ip_list, has_items('1.1.1.3', '1.1.1.4')) 
Example #14
Source File: test_cg.py    From storops with Apache License 2.0 5 votes vote down vote up
def test_parse(self):
        output = """
                Name:  test cg name
                Name:  another cg
                """
        cgs = VNXConsistencyGroup.parse_all(output)
        assert_that(len(cgs), equal_to(2))
        names = [cg.name for cg in cgs]
        assert_that(names, has_item('test cg name'))
        assert_that(names, has_item('another cg')) 
Example #15
Source File: test_nfs_share.py    From storops with Apache License 2.0 5 votes vote down vote up
def test_create_with_host_config(self):
        mover = self.get_mover_1()
        host_config = NfsHostConfig(
            root_hosts=['1.1.1.1', '2.2.2.2'],
            ro_hosts=['3.3.3.3'],
            rw_hosts=['4.4.4.4', '5.5.5.5'],
            access_hosts=['6.6.6.6'])
        share = VNXNfsShare.create(cli=t_nas(), mover=mover, path='/FFF',
                                   host_config=host_config)
        assert_that(share.fs_id, equal_to(247))
        assert_that(share.path, equal_to('/FFF'))
        assert_that(share.existed, equal_to(True))
        assert_that(share.access_hosts, has_item('6.6.6.6')) 
Example #16
Source File: test_nfs_share.py    From storops with Apache License 2.0 5 votes vote down vote up
def verify_share_eee(share):
        assert_that(share.path, equal_to('/EEE'))
        assert_that(share.read_only, equal_to(False))
        assert_that(share.fs_id, equal_to(213))
        assert_that(share.mover_id, equal_to(1))
        assert_that(len(share.root_hosts), equal_to(41))
        assert_that(share.access_hosts, has_item('10.110.43.94'))
        assert_that(len(share.access_hosts), equal_to(41))
        assert_that(share.access_hosts, has_item('10.110.43.94'))
        assert_that(len(share.rw_hosts), equal_to(41))
        assert_that(share.rw_hosts, has_item('10.110.43.94'))
        assert_that(len(share.ro_hosts), equal_to(41))
        assert_that(share.ro_hosts, has_item('10.110.43.94')) 
Example #17
Source File: test_cifs_share.py    From storops with Apache License 2.0 5 votes vote down vote up
def verify_share_zhuanc(share):
        assert_that(share.path, equal_to(r'\zhuanc_fs_100g'))
        assert_that(share.fs_id, equal_to(211))
        assert_that(share.max_users, equal_to(10))
        assert_that(share.comment, equal_to('100g cifs share for zhuanc'))
        assert_that(share.name, equal_to('zhuanc_cifs_100g'))
        assert_that(share.mover_id, equal_to(1))
        assert_that(share.is_vdm, equal_to(False))
        assert_that(share.cifs_server_names, has_item('CIFS')) 
Example #18
Source File: test__transition_approval_meta.py    From django-river with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_shouldNotDeleteApprovedTransitionWhenDeleted(self):
        content_type = ContentType.objects.get_for_model(BasicTestModel)

        state1 = StateObjectFactory(label="state1")
        state2 = StateObjectFactory(label="state2")

        workflow = WorkflowFactory(initial_state=state1, content_type=content_type, field_name="my_field")

        transition_meta = TransitionMetaFactory.create(
            workflow=workflow,
            source_state=state1,
            destination_state=state2,
        )
        meta1 = TransitionApprovalMetaFactory.create(workflow=workflow, transition_meta=transition_meta, priority=0)

        BasicTestModelObjectFactory()
        TransitionApproval.objects.filter(workflow=workflow).update(status=APPROVED)
        approvals = TransitionApproval.objects.filter(workflow=workflow)
        assert_that(approvals, has_length(1))
        assert_that(approvals, has_item(has_property("meta", meta1)))

        meta1.delete()

        approvals = TransitionApproval.objects.filter(workflow=workflow)
        assert_that(approvals, has_length(1))
        assert_that(approvals, has_item(has_property("meta", none()))) 
Example #19
Source File: remove_bond_test.py    From netman with Apache License 2.0 5 votes vote down vote up
def test_removes_bond_from_get_bonds(self):
        self.client.remove_bond(42)

        assert_that(self.client.get_bonds(), not_(has_item(42))) 
Example #20
Source File: test_endpoints.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_nonZeroExitSignal(self):
        """
        When the command exits with a non-zero signal, the protocol's
        C{connectionLost} method is called with a L{Failure} wrapping an
        exception which encapsulates that status.

        Additional packet contents are logged at the C{info} level.
        """
        logObserver = EventLoggingObserver()
        globalLogPublisher.addObserver(logObserver)
        self.addCleanup(globalLogPublisher.removeObserver, logObserver)

        exitCode = None
        signal = 15
        # See https://tools.ietf.org/html/rfc4254#section-6.10
        packet = b"".join([
            common.NS(b'TERM'),     # Signal name (without "SIG" prefix);
                                    # string
            b'\x01',                # Core dumped; boolean
            common.NS(b'message'),  # Error message; string (UTF-8 encoded)
            common.NS(b'en-US'),    # Language tag; string
        ])
        exc = self._exitStatusTest(b'exit-signal', packet)
        exc.trap(ProcessTerminated)
        self.assertEqual(exitCode, exc.value.exitCode)
        self.assertEqual(signal, exc.value.signal)

        logNamespace = "twisted.conch.endpoints._CommandChannel"
        hamcrest.assert_that(
            logObserver,
            hamcrest.has_item(
                hamcrest.has_entries(
                    {
                        "log_level": hamcrest.equal_to(LogLevel.info),
                        "log_namespace": logNamespace,
                        "shortSignalName": b"TERM",
                        "coreDumped": True,
                        "errorMessage": u"message",
                        "languageTag": b"en-US",
                    },
                ))) 
Example #21
Source File: test__instance_api.py    From django-river with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test__shouldReturnNextApprovals(self):
        state1 = StateObjectFactory(label="state1")
        state2 = StateObjectFactory(label="state2")
        state3 = StateObjectFactory(label="state3")

        workflow = WorkflowFactory(initial_state=state1, content_type=self.content_type, field_name="my_field")

        transition_meta_1 = TransitionMetaFactory.create(
            workflow=workflow,
            source_state=state1,
            destination_state=state2,
        )

        transition_meta_2 = TransitionMetaFactory.create(
            workflow=workflow,
            source_state=state1,
            destination_state=state3,
        )

        meta1 = TransitionApprovalMetaFactory.create(
            workflow=workflow,
            transition_meta=transition_meta_1,
            priority=0,
        )

        meta2 = TransitionApprovalMetaFactory.create(
            workflow=workflow,
            transition_meta=transition_meta_2,
            priority=0,
        )

        workflow_object = BasicTestModelObjectFactory()

        assert_that(workflow_object.model.my_field, equal_to(state1))
        next_approvals = workflow_object.model.river.my_field.next_approvals
        assert_that(next_approvals, has_length(2))
        assert_that(next_approvals, has_item(meta1.transition_approvals.first()))
        assert_that(next_approvals, has_item(meta2.transition_approvals.first())) 
Example #22
Source File: test__instance_api.py    From django-river with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_shouldNotReturnOtherObjectsApprovalsForTheAuthorizedUser(self):
        authorized_permission = PermissionObjectFactory()
        authorized_user = UserObjectFactory(user_permissions=[authorized_permission])

        state1 = StateObjectFactory(label="state1")
        state2 = StateObjectFactory(label="state2")
        workflow = WorkflowFactory(initial_state=state1, content_type=self.content_type, field_name="my_field")
        transition_meta = TransitionMetaFactory.create(
            workflow=workflow,
            source_state=state1,
            destination_state=state2,
        )
        TransitionApprovalMetaFactory.create(
            workflow=workflow,
            transition_meta=transition_meta,
            priority=0,
            permissions=[authorized_permission]

        )

        workflow_object1 = BasicTestModelObjectFactory()
        workflow_object2 = BasicTestModelObjectFactory()

        available_approvals = workflow_object1.model.river.my_field.get_available_approvals(as_user=authorized_user)
        assert_that(available_approvals, has_length(1))
        assert_that(list(available_approvals), has_item(
            has_property("workflow_object", workflow_object1.model)
        ))
        assert_that(list(available_approvals), has_item(
            is_not(has_property("workflow_object", workflow_object2.model))
        )) 
Example #23
Source File: test__class_api.py    From django-river with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_shouldReturnAnApprovalWhenUserIsAuthorizedAsTransactioner(self):
        authorized_user = UserObjectFactory()

        state1 = StateObjectFactory(label="state1")
        state2 = StateObjectFactory(label="state2")

        workflow = WorkflowFactory(initial_state=state1, content_type=self.content_type, field_name="my_field")

        transition_meta = TransitionMetaFactory.create(
            workflow=workflow,
            source_state=state1,
            destination_state=state2,
        )
        TransitionApprovalMetaFactory.create(
            workflow=workflow,
            transition_meta=transition_meta,
            priority=0
        )

        workflow_object = BasicTestModelObjectFactory()

        TransitionApproval.objects.filter(workflow_object=workflow_object.model).update(transactioner=authorized_user)

        available_approvals = BasicTestModel.river.my_field.get_available_approvals(as_user=authorized_user)
        assert_that(available_approvals, has_length(1))
        assert_that(list(available_approvals), has_item(
            all_of(
                has_property("workflow_object", workflow_object.model),
                has_property("workflow", workflow),
                has_property("transition", transition_meta.transitions.first())
            )
        )) 
Example #24
Source File: test__class_api.py    From django-river with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_shouldReturnAnApprovalWhenUserIsAuthorizedWithAPermission(self):
        authorized_permission = PermissionObjectFactory()
        authorized_user = UserObjectFactory(user_permissions=[authorized_permission])

        state1 = StateObjectFactory(label="state1")
        state2 = StateObjectFactory(label="state2")

        workflow = WorkflowFactory(initial_state=state1, content_type=self.content_type, field_name="my_field")

        transition_meta = TransitionMetaFactory.create(
            workflow=workflow,
            source_state=state1,
            destination_state=state2,
        )
        TransitionApprovalMetaFactory.create(
            workflow=workflow,
            transition_meta=transition_meta,
            priority=0,
            permissions=[authorized_permission]
        )

        workflow_object = BasicTestModelObjectFactory()

        available_approvals = BasicTestModel.river.my_field.get_available_approvals(as_user=authorized_user)
        assert_that(available_approvals, has_length(1))
        assert_that(list(available_approvals), has_item(
            all_of(
                has_property("workflow_object", workflow_object.model),
                has_property("workflow", workflow),
                has_property("transition", transition_meta.transitions.first())
            )
        )) 
Example #25
Source File: test__app.py    From django-river with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test__shouldNotInjectToAdminOfTheModelThatDoesNotHaveStateFieldInIt(self):
        assert_that(admin.site._registry[Function].inlines, is_not(has_item(OnApprovedHookInline)))
        assert_that(admin.site._registry[Function].inlines, is_not(has_item(OnTransitHookInline)))
        assert_that(admin.site._registry[Function].inlines, is_not(has_item(OnCompleteHookInline))) 
Example #26
Source File: test__app.py    From django-river with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test__shouldInjectADefaultAdminWithTheHooks(self):
        assert_that(admin.site._registry[BasicTestModelWithoutAdmin], instance_of(DefaultWorkflowModelAdmin))
        assert_that(admin.site._registry[BasicTestModel].inlines, has_item(OnApprovedHookInline))
        assert_that(admin.site._registry[BasicTestModel].inlines, has_item(OnTransitHookInline))
        assert_that(admin.site._registry[BasicTestModel].inlines, has_item(OnCompleteHookInline)) 
Example #27
Source File: test__app.py    From django-river with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test__shouldInjectExistingAdminOfTheModelThatHasStateFieldInIt(self):
        assert_that(admin.site._registry[BasicTestModel], instance_of(BasicTestModelAdmin))
        assert_that(admin.site._registry[BasicTestModel].inlines, has_item(OnApprovedHookInline))
        assert_that(admin.site._registry[BasicTestModel].inlines, has_item(OnTransitHookInline))
        assert_that(admin.site._registry[BasicTestModel].inlines, has_item(OnCompleteHookInline))