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


Python Command.build_request_args方法代码示例

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


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

示例1: test_center_arg

# 需要导入模块: from ripe.atlas.tools.commands.probes import Command [as 别名]
# 或者: from ripe.atlas.tools.commands.probes.Command import build_request_args [as 别名]
 def test_center_arg(self):
     """User passed center arg"""
     cmd = Command()
     cmd.init_args(["--center", "1,2"])
     self.assertEquals(
         cmd.build_request_args(),
         {"latitude": "1", "longitude": "2"}
     )
开发者ID:johanterbeest,项目名称:ripe-atlas-tools,代码行数:10,代码来源:probes.py

示例2: test_location_arg

# 需要导入模块: from ripe.atlas.tools.commands.probes import Command [as 别名]
# 或者: from ripe.atlas.tools.commands.probes.Command import build_request_args [as 别名]
 def test_location_arg(self):
     """User passed location arg"""
     with mock.patch('requests.get') as mock_get:
         mock_get.return_value = requests.Response()
         with mock.patch('requests.Response.json') as mock_json:
             mock_json.return_value = {"results": [
                 {"geometry": {"location": {"lat": 1, "lng": 2}}}]}
             cmd = Command()
             cmd.init_args(["--location", "blaaaa"])
             self.assertEquals(cmd.build_request_args(), {
                 "latitude": '1', "longitude": '2'})
开发者ID:johanterbeest,项目名称:ripe-atlas-tools,代码行数:13,代码来源:probes.py

示例3: test_sane_args1

# 需要导入模块: from ripe.atlas.tools.commands.probes import Command [as 别名]
# 或者: from ripe.atlas.tools.commands.probes.Command import build_request_args [as 别名]
 def test_sane_args1(self):
     """User passed several arguments (1)"""
     cmd = Command()
     cmd.init_args([
         "--center", "1,2",
         "--radius", "4",
         "--asnv4", "3333",
         "--prefix", "193.0.0.0/21"
     ])
     self.assertEquals(
         cmd.build_request_args(),
         {'asn_v4': 3333, 'prefix': '193.0.0.0/21', 'radius': '1,2:4'}
     )
开发者ID:johanterbeest,项目名称:ripe-atlas-tools,代码行数:15,代码来源:probes.py

示例4: test_sane_args3

# 需要导入模块: from ripe.atlas.tools.commands.probes import Command [as 别名]
# 或者: from ripe.atlas.tools.commands.probes.Command import build_request_args [as 别名]
    def test_sane_args3(self):
        """User passed several arguments (3)"""

        cmd = Command()
        cmd.init_args([
            "--center", "1,2",
            "--asnv6", "3333",
            "--prefixv6", "2001:67c:2e8::/48"
        ])
        self.assertEquals(cmd.build_request_args(), {
            'asn_v6': 3333,
            'prefix_v6': '2001:67c:2e8::/48',
            'latitude': '1',
            'longitude': '2'
        })
开发者ID:johanterbeest,项目名称:ripe-atlas-tools,代码行数:17,代码来源:probes.py

示例5: test_sane_args2

# 需要导入模块: from ripe.atlas.tools.commands.probes import Command [as 别名]
# 或者: from ripe.atlas.tools.commands.probes.Command import build_request_args [as 别名]
    def test_sane_args2(self):
        """User passed several arguments (2)"""

        cmd = Command()
        cmd.init_args([
            "--location", "Amsterdam",
            "--asn", "3333",
            "--prefixv4", "193.0.0.0/21"
        ])

        path = 'ripe.atlas.tools.commands.probes.Command.location2degrees'
        with mock.patch(path) as mock_get:
            mock_get.return_value = (1, 2)
            self.assertEquals(cmd.build_request_args(), {
                'asn': 3333,
                'prefix_v4': '193.0.0.0/21',
                'latitude': 1,
                'longitude': 2
            })
开发者ID:johanterbeest,项目名称:ripe-atlas-tools,代码行数:21,代码来源:probes.py

示例6: test_country_arg_with_radius

# 需要导入模块: from ripe.atlas.tools.commands.probes import Command [as 别名]
# 或者: from ripe.atlas.tools.commands.probes.Command import build_request_args [as 别名]
 def test_country_arg_with_radius(self):
     """User passed country code arg together with radius"""
     cmd = Command()
     cmd.init_args(["--country", "GR", "--radius", "4"])
     self.assertEquals(cmd.build_request_args(), {"country_code": "GR"})
开发者ID:johanterbeest,项目名称:ripe-atlas-tools,代码行数:7,代码来源:probes.py

示例7: test_country_arg

# 需要导入模块: from ripe.atlas.tools.commands.probes import Command [as 别名]
# 或者: from ripe.atlas.tools.commands.probes.Command import build_request_args [as 别名]
 def test_country_arg(self):
     """User passed country code arg"""
     cmd = Command()
     cmd.init_args(["--country", "GR"])
     self.assertEquals(cmd.build_request_args(), {"country_code": "GR"})
开发者ID:johanterbeest,项目名称:ripe-atlas-tools,代码行数:7,代码来源:probes.py

示例8: test_center_arg_with_radius

# 需要导入模块: from ripe.atlas.tools.commands.probes import Command [as 别名]
# 或者: from ripe.atlas.tools.commands.probes.Command import build_request_args [as 别名]
 def test_center_arg_with_radius(self):
     """User passed center and radius arg"""
     cmd = Command()
     cmd.init_args(["--center", "1,2", "--radius", "4"])
     self.assertEquals(cmd.build_request_args(), {"radius": "1,2:4"})
开发者ID:johanterbeest,项目名称:ripe-atlas-tools,代码行数:7,代码来源:probes.py

示例9: test_all_args

# 需要导入模块: from ripe.atlas.tools.commands.probes import Command [as 别名]
# 或者: from ripe.atlas.tools.commands.probes.Command import build_request_args [as 别名]
 def test_all_args(self):
     """User passed all arguments"""
     cmd = Command()
     cmd.init_args(["--all"])
     self.assertEquals(cmd.build_request_args(), {})
开发者ID:johanterbeest,项目名称:ripe-atlas-tools,代码行数:7,代码来源:probes.py

示例10: TestProbesCommand

# 需要导入模块: from ripe.atlas.tools.commands.probes import Command [as 别名]
# 或者: from ripe.atlas.tools.commands.probes.Command import build_request_args [as 别名]
class TestProbesCommand(unittest.TestCase):

    def setUp(self):
        self.cmd = Command()
        self.maxDiff = None

    def test_with_empty_args(self):
        """User passes no args, should fail with RipeAtlasToolsException"""
        with self.assertRaises(RipeAtlasToolsException):
            self.cmd.init_args([])
            self.cmd.run()

    def test_with_random_args(self):
        """User passes random args, should fail with SystemExit"""
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["blaaaaaaa"])
            self.cmd.run()

    def test_arg_with_no_value(self):
        """User passed not boolean arg but no value"""
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["--asn"])
            self.cmd.run()

    def test_arg_with_wrong_type(self):
        """User passed arg with wrong type. e.g string for asn"""
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["--asn", "blaaaaa"])
            self.cmd.run()
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["--asnv4", "blaaaaa"])
            self.cmd.run()
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["--asnv6", "blaaaaa"])
            self.cmd.run()
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["--limit", "blaaaaa"])
            self.cmd.run()
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["--radius", "blaaaaa"])
            self.cmd.run()

    def test_location_google_breaks(self):
        """User passed location arg but google api gave error"""
        caught_exceptions = [
            requests.ConnectionError, requests.HTTPError, requests.Timeout]
        with mock.patch('requests.get') as mock_get:
            for exception in caught_exceptions:
                mock_get.side_effect = exception
                with self.assertRaises(RipeAtlasToolsException):
                    self.cmd.init_args(["--location", "blaaaa"])
                    self.cmd.run()
            mock_get.side_effect = Exception()
            with self.assertRaises(Exception):
                self.cmd.init_args(["--location", "blaaaa"])
                self.cmd.run()

    def test_location_google_wrong_output(self):
        """User passed location arg but google api gave not expected format"""
        with mock.patch('requests.get') as mock_get:
            mock_get.return_value = requests.Response()
            with mock.patch('requests.Response.json') as mock_json:
                mock_json.return_value = {"blaaa": "bla"}
                with self.assertRaises(RipeAtlasToolsException):
                    self.cmd.init_args(["--location", "blaaaa"])
                    self.cmd.run()

    def test_location_arg(self):
        """User passed location arg"""
        with mock.patch('requests.get') as mock_get:
            mock_get.return_value = requests.Response()
            with mock.patch('requests.Response.json') as mock_json:
                mock_json.return_value = {"results": [
                    {"geometry": {"location": {"lat": 1, "lng": 2}}}]}
                self.cmd.init_args(["--location", "blaaaa"])
                self.assertEquals(self.cmd.build_request_args(), {
                    "latitude": '1', "longitude": '2'})

    def test_location_arg_with_radius(self):
        """User passed location arg"""
        with mock.patch('requests.get') as mock_get:
            mock_get.return_value = requests.Response()
            with mock.patch('requests.Response.json') as mock_json:
                mock_json.return_value = {"results": [
                    {"geometry": {"location": {"lat": 1, "lng": 2}}}
                ]}
                self.cmd.init_args(["--location", "blaaaa", "--radius", "4"])
                self.assertEquals(
                    self.cmd.build_request_args(),
                    {"radius": "1,2:4"}
                )

    def test_asn_args(self):
        """User passed asn arg together with asnv4 or asnv6"""
        with self.assertRaises(RipeAtlasToolsException):
            self.cmd.init_args(["--asn", "3333", "--asnv4", "3333"])
            self.cmd.run()

        with self.assertRaises(RipeAtlasToolsException):
            self.cmd.init_args(["--asn", "3333", "--asnv6", "3333"])
#.........这里部分代码省略.........
开发者ID:becha42,项目名称:ripe-atlas-tools,代码行数:103,代码来源:probes.py


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