本文整理汇总了Python中hamcrest.has_length方法的典型用法代码示例。如果您正苦于以下问题:Python hamcrest.has_length方法的具体用法?Python hamcrest.has_length怎么用?Python hamcrest.has_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hamcrest
的用法示例。
在下文中一共展示了hamcrest.has_length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_shouldNotDeletePendingTransitionWhenDeleted
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
def test_shouldNotDeletePendingTransitionWhenDeleted(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=PENDING)
assert_that(TransitionApproval.objects.filter(workflow=workflow), has_length(1))
meta1.delete()
assert_that(TransitionApproval.objects.filter(workflow=workflow), has_length(0))
示例2: test_shouldNotAllowWorkflowToBeDeletedWhenThereIsATransitionApproval
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
def test_shouldNotAllowWorkflowToBeDeletedWhenThereIsATransitionApproval(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,
)
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(
calling(workflow.delete),
raises(ProtectedError, "Cannot delete some instances of model 'Workflow' because they are referenced through a protected foreign key")
)
示例3: test_shouldCreateAllMigrations
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
def test_shouldCreateAllMigrations(self):
for f in os.listdir("river/migrations"):
if f != "__init__.py" and f != "__pycache__" and not f.endswith(".pyc"):
open(os.path.join("river/tests/volatile/river/", f), 'wb').write(open(os.path.join("river/migrations", f), 'rb').read())
self.migrations_before = list(filter(lambda f: f.endswith('.py') and f != '__init__.py', os.listdir('river/tests/volatile/river/')))
out = StringIO()
sys.stout = out
call_command('makemigrations', 'river', stdout=out)
self.migrations_after = list(filter(lambda f: f.endswith('.py') and f != '__init__.py', os.listdir('river/tests/volatile/river/')))
assert_that(out.getvalue(), equal_to("No changes detected in app 'river'\n"))
assert_that(self.migrations_after, has_length(len(self.migrations_before)))
示例4: test_shouldReturnNoApprovalWhenUserIsUnAuthorized
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
def test_shouldReturnNoApprovalWhenUserIsUnAuthorized(self):
unauthorized_user = UserObjectFactory()
state1 = StateObjectFactory(label="state1")
state2 = StateObjectFactory(label="state2")
workflow = WorkflowFactory(initial_state=state1, content_type=self.content_type, field_name="my_field")
authorized_permission = PermissionObjectFactory()
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]
)
BasicTestModelObjectFactory()
available_approvals = BasicTestModel.river.my_field.get_available_approvals(as_user=unauthorized_user)
assert_that(available_approvals, has_length(0))
示例5: test_shouldAssesFinalStateProperlyWhenThereIsOnlyOne
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
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))
示例6: test_get_vlan_without_interface
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
def test_get_vlan_without_interface(self):
self.switch.node.should_receive("enable") \
.with_args(["show vlan 456", "show interfaces Vlan456"], strict=True) \
.and_raise(CommandError(1002, "CLI command 3 of 3 'show interfaces Vlan456' failed: invalid command",
command_error="Interface does not exist",
output=[
{},
{'vlans': {'456': vlan_data(name='Patate')}},
{'errors': ['Interface does not exist']}
]))
self.switch.node.should_receive("get_config").with_args(params="interfaces Vlan456").once() \
.and_return(['interface Vlan456'])
vlan = self.switch.get_vlan(456)
assert_that(vlan.number, equal_to(456))
assert_that(vlan.name, equal_to('Patate'))
assert_that(vlan.ips, has_length(0))
示例7: test_get_single
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
def test_get_single(self):
mg = VNXMirrorGroup.get(t_cli(), name='petermg')
assert_that(mg, instance_of(VNXMirrorGroup))
assert_that(mg.name, equal_to('petermg'))
assert_that(mg.gid, equal_to('50:06:01:60:B6:60:25:22:00:00:00:00'))
assert_that(mg.description, equal_to(''))
assert_that(mg.state, equal_to('Synchronized'))
assert_that(mg.role, equal_to('Primary'))
assert_that(mg.condition, equal_to('Active'))
assert_that(mg.policy, equal_to(VNXMirrorGroupRecoveryPolicy.MANUAL))
assert_that(mg.mirrors, has_length(2))
assert_that(mg.group_mirrors, has_length(2))
for m in mg.mirrors:
assert_that(m, instance_of(VNXMirrorView))
for mg in mg.group_mirrors:
assert_that(
mg.mirror_name,
not_none())
assert_that(mg.src_lun_id, instance_of(int))
示例8: test_set_interface_disabling
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
def test_set_interface_disabling(self):
result = self.nc.get_config(source="running", filter=dict_2_etree({"filter": {
"configuration": {"interfaces": {"interface": {"name": "xe-0/0/2"}}}}}))
assert_that(result.xpath("data/configuration/interfaces/interface"), has_length(0))
self.edit({"interfaces": {"interface": [{"name": "xe-0/0/2"}, {"disable": ""}]}})
self.nc.commit()
result = self.nc.get_config(source="running", filter=dict_2_etree({"filter": {
"configuration": {"interfaces": {"interface": {"name": "xe-0/0/2"}}}}}))
int002 = result.xpath("data/configuration/interfaces/interface")[0]
assert_that(int002.xpath("disable"), has_length(1))
self.edit({"interfaces": {
"interface": [{"name": "xe-0/0/2"}, {"disable": {XML_ATTRIBUTES: {"operation": "delete"}}}]}})
self.nc.commit()
result = self.nc.get_config(source="running", filter=dict_2_etree({"filter": {
"configuration": {"interfaces": {"interface": {"name": "xe-0/0/2"}}}}}))
assert_that(result.xpath("data/configuration/interfaces/interface"), has_length(0))
示例9: test_add_a_routing_interface_to_vlan
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
def test_add_a_routing_interface_to_vlan(self):
self.edit({
"bridge-domains": {
"domain": {
"name": "VLAN123",
"vlan-id": "123",
"routing-interface": "irb.123"}}})
self.nc.commit()
vlan123 = self._get_vlan("VLAN123")
assert_that(vlan123.xpath("routing-interface")[0].text, is_("irb.123"))
self.edit({
"bridge-domains": {
"domain": [
{"name": "VLAN123"},
{"routing-interface": {XML_ATTRIBUTES: {"operation": "delete"}}}]}})
self.nc.commit()
vlan123 = self._get_vlan("VLAN123")
assert_that(vlan123.xpath("routing-interface"), has_length(0))
self.cleanup(vlan("VLAN123"))
示例10: test_multiple_ip_support
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
def test_multiple_ip_support(self):
self.edit({
"interfaces": {
"interface": {
"name": "irb",
"unit": {
"name": "300",
"family": {
"inet": [
{"address": {"name": "3.3.3.2/27"}},
{"address": {"name": "4.4.4.2/27"}},
]}}}}})
self.nc.commit()
int_vlan = self._interface_vlan("300")
assert_that(int_vlan.xpath("family/inet/address"), has_length(2))
assert_that(int_vlan.xpath("family/inet/address/name")[0].text, is_("3.3.3.2/27"))
assert_that(int_vlan.xpath("family/inet/address/name")[1].text, is_("4.4.4.2/27"))
self.cleanup(reset_interface("irb"))
示例11: check_output_count
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
def check_output_count(context, number):
assert_that(context.result, has_length(number))
示例12: test_shouldNotDeleteApprovedTransitionWhenDeleted
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
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())))
示例13: test_shouldNotAllowTheStateToBeDeletedWhenThereIsATransitionApprovalThatIsUsedAsSource
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
def test_shouldNotAllowTheStateToBeDeletedWhenThereIsATransitionApprovalThatIsUsedAsSource(self):
content_type = ContentType.objects.get_for_model(BasicTestModel)
state1 = StateObjectFactory(label="state1")
state2 = StateObjectFactory(label="state2")
state3 = StateObjectFactory(label="state3")
workflow = WorkflowFactory(initial_state=state1, content_type=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=state2,
destination_state=state3,
)
TransitionApprovalMetaFactory.create(workflow=workflow, transition_meta=transition_meta_1, priority=0)
TransitionApprovalMetaFactory.create(workflow=workflow, transition_meta=transition_meta_2, priority=0)
BasicTestModelObjectFactory()
TransitionApproval.objects.filter(workflow=workflow).update(status=APPROVED)
approvals = TransitionApproval.objects.filter(workflow=workflow)
assert_that(approvals, has_length(2))
assert_that(
calling(state2.delete),
raises(ProtectedError, "Cannot delete some instances of model 'State' because they are referenced through a protected foreign key")
)
示例14: test__shouldNotKeepRecreatingMigrationsWhenNoChange
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
def test__shouldNotKeepRecreatingMigrationsWhenNoChange(self):
call_command('makemigrations', 'tests')
self.migrations_before = list(filter(lambda f: f.endswith('.py') and f != '__init__.py', os.listdir('river/tests/volatile/river_tests/')))
out = StringIO()
sys.stout = out
call_command('makemigrations', 'tests', stdout=out)
self.migrations_after = list(filter(lambda f: f.endswith('.py') and f != '__init__.py', os.listdir('river/tests/volatile/river_tests/')))
assert_that(out.getvalue(), equal_to("No changes detected in app 'tests'\n"))
assert_that(self.migrations_after, has_length(len(self.migrations_before)))
示例15: test_shouldReturnAnApprovalWhenUserIsAuthorizedWithAUserGroup
# 需要导入模块: import hamcrest [as 别名]
# 或者: from hamcrest import has_length [as 别名]
def test_shouldReturnAnApprovalWhenUserIsAuthorizedWithAUserGroup(self):
authorized_user_group = GroupObjectFactory()
authorized_user = UserObjectFactory(groups=[authorized_user_group])
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,
)
approval_meta = TransitionApprovalMetaFactory.create(
workflow=workflow,
transition_meta=transition_meta,
priority=0
)
approval_meta.groups.add(authorized_user_group)
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())
)
))