当前位置: 首页>>代码示例>>Python>>正文


Python matchers.Contains方法代码示例

本文整理汇总了Python中testtools.matchers.Contains方法的典型用法代码示例。如果您正苦于以下问题:Python matchers.Contains方法的具体用法?Python matchers.Contains怎么用?Python matchers.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testtools.matchers的用法示例。


在下文中一共展示了matchers.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_run

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_run(self):
        """
        The script creates a new release version branch in a new working
        directory and prints some shell commands to ``stdout``.
        """
        expected_version = "9.9.9"
        script_path = self.make_temporary_directory()
        repo_path = script_path.sibling(
            'flocker-release-{}'.format(expected_version)
        )
        result = run_process(
            [INITIALIZE_RELEASE_PATH.path,
             '--flocker-version={}'.format(expected_version)],
            cwd=script_path.path
        )
        self.expectThat(result.status, Equals(0))
        self.expectThat(
            result.output,
            Contains('export VERSION={}'.format(expected_version))
        )
        self.expectThat(
            Repo(path=repo_path.path).active_branch.name,
            Equals('release/flocker-{}'.format(expected_version))
        ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:26,代码来源:test_release.py

示例2: _build_role_assignment_response

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def _build_role_assignment_response(self, role_id, scope_type, scope_id,
                                        entity_type, entity_id):
        self.assertThat(['group', 'user'], matchers.Contains(entity_type))
        self.assertThat(['project', 'domain'], matchers.Contains(scope_type))
        # NOTE(notmorgan): Links are thrown out by shade, but we construct them
        # for corectness.
        link_str = ('https://identity.example.com/identity/v3/{scope_t}s'
                    '/{scopeid}/{entity_t}s/{entityid}/roles/{roleid}')
        return [{
            'links': {'assignment': link_str.format(
                scope_t=scope_type, scopeid=scope_id, entity_t=entity_type,
                entityid=entity_id, roleid=role_id)},
            'role': {'id': role_id},
            'scope': {scope_type: {'id': scope_id}},
            entity_type: {'id': entity_id}
        }] 
开发者ID:openstack,项目名称:openstacksdk,代码行数:18,代码来源:test_role_assignment.py

示例3: test_finds_power_address_from_mac_address

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_finds_power_address_from_mac_address(self):
        context = make_context()
        driver = IPMIPowerDriver()
        ip_address = factory.make_ipv4_address()
        find_ip_via_arp = self.patch(ipmi_module, "find_ip_via_arp")
        find_ip_via_arp.return_value = ip_address
        power_change = random.choice(("on", "off"))

        context["mac_address"] = factory.make_mac_address()
        context["power_address"] = random.choice((None, "", "   "))

        self.patch_autospec(driver, "_issue_ipmipower_command")
        driver._issue_ipmi_command(power_change, **context)

        # The IP address is passed to _issue_ipmipower_command.
        self.assertThat(
            driver._issue_ipmipower_command,
            MockCalledOnceWith(ANY, power_change, ip_address),
        )
        # The IP address is also within the command passed to
        # _issue_ipmipower_command.
        self.assertThat(
            driver._issue_ipmipower_command.call_args[0], Contains(ip_address)
        ) 
开发者ID:maas,项目名称:maas,代码行数:26,代码来源:test_ipmi.py

示例4: test_no_write_local

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_no_write_local(self):
        config.write_config(False)
        matcher_one = Not(
            Contains(':fromhost-ip, !isequal, "127.0.0.1" ?MAASenlist')
        )
        matcher_two = Not(
            Contains(':fromhost-ip, !isequal, "127.0.0.1" ?MAASboot')
        )
        # maas.log is still local when no write local.
        matcher_three = Contains(':syslogtag, contains, "maas"')
        self.assertThat(
            "%s/%s" % (self.tmpdir, config.MAAS_SYSLOG_CONF_NAME),
            FileContains(
                matcher=MatchesAll(matcher_one, matcher_two, matcher_three)
            ),
        ) 
开发者ID:maas,项目名称:maas,代码行数:18,代码来源:test_config.py

示例5: test_normal_operation

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_normal_operation(self):
        options_file = self.make_file(contents=OPTIONS_FILE)
        self.run_command("--config-path", options_file)
        expected_path = os.path.join(
            os.path.dirname(options_file),
            "maas",
            MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME,
        )

        # Check that the file was re-written with the include statement.
        options = read_isc_file(options_file)
        self.assertThat(
            make_isc_string(options), Contains('include "%s";' % expected_path)
        )

        # Check that the backup was made.
        options_file_base = os.path.dirname(options_file)
        files = os.listdir(options_file_base)
        self.assertEqual(2, len(files))
        files.remove(os.path.basename(options_file))
        [backup_file] = files
        backup_file = os.path.join(options_file_base, backup_file)
        self.assertThat(backup_file, FileContains(OPTIONS_FILE)) 
开发者ID:maas,项目名称:maas,代码行数:25,代码来源:test_edit_named_options.py

示例6: test_bind_write_configuration_writes_file_with_acl

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_bind_write_configuration_writes_file_with_acl(self):
        trusted_networks = [
            factory.make_ipv4_network(),
            factory.make_ipv6_network(),
        ]
        actions.bind_write_configuration(
            zones=[], trusted_networks=trusted_networks
        )
        expected_file = os.path.join(self.dns_conf_dir, MAAS_NAMED_CONF_NAME)
        self.assertThat(expected_file, FileExists())
        expected_content = dedent(
            """\
        acl "trusted" {
            %s;
            %s;
            localnets;
            localhost;
        };
        """
        )
        expected_content %= tuple(trusted_networks)
        self.assertThat(
            expected_file, FileContains(matcher=Contains(expected_content))
        ) 
开发者ID:maas,项目名称:maas,代码行数:26,代码来源:test_actions.py

示例7: test_setUp_creates_config_files

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_setUp_creates_config_files(self):
        with BINDServerResources() as resources:
            self.assertThat(
                resources.conf_file,
                FileContains(
                    matcher=Contains(b"listen-on port %d" % resources.port)
                ),
            )
            self.assertThat(
                resources.rndcconf_file,
                FileContains(
                    matcher=Contains(
                        b"default-port %d" % (resources.rndc_port)
                    )
                ),
            )
            # This should ideally be in its own test but it's here to cut
            # test run time. See test_setUp_honours_include_in_options()
            # as its counterpart.
            self.assertThat(
                resources.conf_file,
                Not(FileContains(matcher=Contains("forwarders"))),
            ) 
开发者ID:maas,项目名称:maas,代码行数:25,代码来源:test_bindfixture.py

示例8: test_creates_dns_record_for_hostname

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_creates_dns_record_for_hostname(self):
        subnet = factory.make_ipv4_Subnet_with_IPRanges(
            with_static_range=False, dhcp_on=True
        )
        dynamic_range = subnet.get_dynamic_ranges()[0]
        ip = factory.pick_ip_in_IPRange(dynamic_range)
        hostname = factory.make_name().lower()
        kwargs = self.make_kwargs(action="commit", ip=ip, hostname=hostname)
        update_lease(**kwargs)
        unknown_interface = UnknownInterface.objects.filter(
            mac_address=kwargs["mac"]
        ).first()
        self.assertIsNotNone(unknown_interface)
        self.assertEquals(subnet.vlan, unknown_interface.vlan)
        sip = unknown_interface.ip_addresses.first()
        self.assertIsNotNone(sip)
        dnsrr = get_one(DNSResource.objects.filter(name=hostname))
        self.assertThat(sip.dnsresource_set.all(), Contains(dnsrr)) 
开发者ID:maas,项目名称:maas,代码行数:20,代码来源:test_leases.py

示例9: test_skips_dns_record_for_hostname_from_existing_node

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_skips_dns_record_for_hostname_from_existing_node(self):
        subnet = factory.make_ipv4_Subnet_with_IPRanges(
            with_static_range=False, dhcp_on=True
        )
        dynamic_range = subnet.get_dynamic_ranges()[0]
        ip = factory.pick_ip_in_IPRange(dynamic_range)
        hostname = factory.make_name().lower()
        factory.make_Node(hostname=hostname)
        kwargs = self.make_kwargs(action="commit", ip=ip, hostname=hostname)
        update_lease(**kwargs)
        unknown_interface = UnknownInterface.objects.filter(
            mac_address=kwargs["mac"]
        ).first()
        self.assertIsNotNone(unknown_interface)
        self.assertEquals(subnet.vlan, unknown_interface.vlan)
        sip = unknown_interface.ip_addresses.first()
        self.assertIsNotNone(sip)
        self.assertThat(sip.dnsresource_set.all(), Not(Contains(sip))) 
开发者ID:maas,项目名称:maas,代码行数:20,代码来源:test_leases.py

示例10: test_skips_dns_record_for_coerced_hostname_from_existing_node

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_skips_dns_record_for_coerced_hostname_from_existing_node(self):
        subnet = factory.make_ipv4_Subnet_with_IPRanges(
            with_static_range=False, dhcp_on=True
        )
        dynamic_range = subnet.get_dynamic_ranges()[0]
        ip = factory.pick_ip_in_IPRange(dynamic_range)
        hostname = "gaming device"
        factory.make_Node(hostname="gaming-device")
        kwargs = self.make_kwargs(action="commit", ip=ip, hostname=hostname)
        update_lease(**kwargs)
        unknown_interface = UnknownInterface.objects.filter(
            mac_address=kwargs["mac"]
        ).first()
        self.assertIsNotNone(unknown_interface)
        self.assertEquals(subnet.vlan, unknown_interface.vlan)
        sip = unknown_interface.ip_addresses.first()
        self.assertIsNotNone(sip)
        self.assertThat(sip.dnsresource_set.all(), Not(Contains(sip))) 
开发者ID:maas,项目名称:maas,代码行数:20,代码来源:test_leases.py

示例11: test_POST_allocate_allocates_machine_by_storage

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_POST_allocate_allocates_machine_by_storage(self):
        """Storage label is returned alongside machine data"""
        machine = factory.make_Node(
            status=NODE_STATUS.READY, with_boot_disk=False
        )
        factory.make_PhysicalBlockDevice(
            node=machine,
            size=11 * (1000 ** 3),
            tags=["ssd"],
            formatted_root=True,
        )
        response = self.client.post(
            reverse("machines_handler"),
            {"op": "allocate", "storage": "needed:10(ssd)"},
        )
        self.assertThat(response, HasStatusCode(http.client.OK))
        response_json = json.loads(
            response.content.decode(settings.DEFAULT_CHARSET)
        )
        device_id = response_json["physicalblockdevice_set"][0]["id"]
        constraints = response_json["constraints_by_type"]
        self.expectThat(constraints, Contains("storage"))
        self.expectThat(constraints["storage"], Contains("needed"))
        self.expectThat(constraints["storage"]["needed"], Contains(device_id))
        self.expectThat(constraints, Not(Contains("verbose_storage"))) 
开发者ID:maas,项目名称:maas,代码行数:27,代码来源:test_machines.py

示例12: test_POST_allocate_allocates_machine_by_interfaces

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_POST_allocate_allocates_machine_by_interfaces(self):
        """Interface label is returned alongside machine data"""
        fabric = factory.make_Fabric("ubuntu")
        # The ID may always be '1', which won't be interesting for testing.
        for _ in range(1, random.choice([1, 3, 5])):
            factory.make_Interface()
        machine = factory.make_Node_with_Interface_on_Subnet(
            status=NODE_STATUS.READY, fabric=fabric
        )
        iface = machine.get_boot_interface()
        response = self.client.post(
            reverse("machines_handler"),
            {"op": "allocate", "interfaces": "needed:fabric=ubuntu"},
        )
        self.assertThat(response, HasStatusCode(http.client.OK))
        response_json = json.loads(
            response.content.decode(settings.DEFAULT_CHARSET)
        )
        self.expectThat(response_json["status"], Equals(NODE_STATUS.ALLOCATED))
        constraints = response_json["constraints_by_type"]
        self.expectThat(constraints, Contains("interfaces"))
        interfaces = constraints.get("interfaces")
        self.expectThat(interfaces, Contains("needed"))
        self.expectThat(interfaces["needed"], Contains(iface.id))
        self.expectThat(constraints, Not(Contains("verbose_interfaces"))) 
开发者ID:maas,项目名称:maas,代码行数:27,代码来源:test_machines.py

示例13: test_handle_uncaught_exception_notes_serialization_failure

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_handle_uncaught_exception_notes_serialization_failure(self):
        handler = views.WebApplicationHandler()
        request = make_request()
        request.path = factory.make_name("path")
        failure = self.capture_serialization_failure()
        response = handler.handle_uncaught_exception(
            request=request,
            resolver=get_resolver(None),
            exc_info=failure,
            reraise=False,
        )
        # HTTP 409 is returned...
        self.expectThat(response.status_code, Equals(http.client.CONFLICT))
        # ... and the response is recorded as needing a retry.
        self.expectThat(
            handler._WebApplicationHandler__retry, Contains(response)
        ) 
开发者ID:maas,项目名称:maas,代码行数:19,代码来源:test_views.py

示例14: test_handle_uncaught_exception_does_not_note_other_failure

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_handle_uncaught_exception_does_not_note_other_failure(self):
        handler = views.WebApplicationHandler()
        request = make_request()
        request.path = factory.make_name("path")
        failure_type = factory.make_exception_type()
        failure = failure_type, failure_type(), None
        response = handler.handle_uncaught_exception(
            request=request,
            resolver=get_resolver(None),
            exc_info=failure,
            reraise=False,
        )
        # HTTP 500 is returned...
        self.expectThat(
            response.status_code, Equals(http.client.INTERNAL_SERVER_ERROR)
        )
        # ... but the response is NOT recorded as needing a retry.
        self.expectThat(
            handler._WebApplicationHandler__retry, Not(Contains(response))
        ) 
开发者ID:maas,项目名称:maas,代码行数:22,代码来源:test_views.py

示例15: test_normal_operation

# 需要导入模块: from testtools import matchers [as 别名]
# 或者: from testtools.matchers import Contains [as 别名]
def test_normal_operation(self):
        options_file = self.make_file(contents=OPTIONS_FILE)
        call_command(
            "edit_named_options", config_path=options_file, stdout=self.stdout
        )
        expected_path = os.path.join(
            os.path.dirname(options_file),
            "maas",
            MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME,
        )

        # Check that the file was re-written with the include statement.
        options = read_isc_file(options_file)
        self.assertThat(
            make_isc_string(options), Contains('include "%s";' % expected_path)
        )

        # Check that the backup was made.
        options_file_base = os.path.dirname(options_file)
        files = os.listdir(options_file_base)
        self.assertEqual(2, len(files))
        files.remove(os.path.basename(options_file))
        [backup_file] = files
        backup_file = os.path.join(options_file_base, backup_file)
        self.assertThat(backup_file, FileContains(OPTIONS_FILE)) 
开发者ID:maas,项目名称:maas,代码行数:27,代码来源:test_commands_edit_named_options.py


注:本文中的testtools.matchers.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。