def test_set_alias(self): path_aliases = "ripe.atlas.tools.commands.measure.base.aliases" new_aliases = copy.deepcopy(AliasesDB.DEFAULT) with mock.patch(path_aliases, new_aliases): path_AliasesDB = "ripe.atlas.tools.commands.measure.base.AliasesDB" with mock.patch(path_AliasesDB, autospec=True) as new_AliasesDB: new_AliasesDB.write.return_value = True path_create = "ripe.atlas.tools.commands.measure.base.Command.create" with mock.patch(path_create) as mock_create: mock_create.return_value = ( True, {"measurements": [1234]} ) cmd = PingMeasureCommand() cmd.init_args([ "ping", "--target", "www.ripe.net", "--no-report", "--set-alias", "PING_RIPE" ]) cmd.run() self.assertEqual( new_aliases["measurement"]["PING_RIPE"], 1234 )
def test_dry_run(self): with capture_sys_output() as (stdout, stderr): cmd = PingMeasureCommand() cmd.init_args(["ping", "--target", "ripe.net", "--dry-run"]) cmd.run() expected = ( "\n" "Definitions:\n" "================================================================================\n" "target ripe.net\n" "packet_interval 1000\n" "description Ping measurement to ripe.net\n" "af 4\n" "packets 3\n" "size 48\n" "\n" "Sources:\n" "================================================================================\n" "requested 50\n" "type area\n" "value WW\n" "tags\n" " include system-ipv4-works\n" " exclude \n" "\n") self.assertEqual(set(stdout.getvalue().split("\n")), set(expected.split("\n"))) with capture_sys_output() as (stdout, stderr): cmd = PingMeasureCommand() cmd.init_args([ "ping", "--target", "ripe.net", "--af", "6", "--include-tag", "alpha", "--include-tag", "bravo", "--include-tag", "charlie", "--exclude-tag", "delta", "--exclude-tag", "echo", "--exclude-tag", "foxtrot", "--dry-run" ]) cmd.run() expected = ( "\n" "Definitions:\n" "================================================================================\n" "target ripe.net\n" "packet_interval 1000\n" "description Ping measurement to ripe.net\n" "af 6\n" "packets 3\n" "size 48\n" "\n" "Sources:\n" "================================================================================\n" "requested 50\n" "type area\n" "value WW\n" "tags\n" " include alpha, bravo, charlie\n" " exclude delta, echo, foxtrot\n" "\n") self.assertEqual(set(stdout.getvalue().split("\n")), set(expected.split("\n")))
def test_dry_run(self): with capture_sys_output() as (stdout, stderr): cmd = PingMeasureCommand() cmd.init_args(["ping", "--target", "ripe.net", "--dry-run"]) cmd.run() expected = ( "\n" "Definitions:\n" "================================================================================\n" "target ripe.net\n" "packet_interval 1000\n" "description Ping measurement to ripe.net\n" "af 4\n" "packets 3\n" "size 48\n" "\n" "Sources:\n" "================================================================================\n" "requested 50\n" "type area\n" "value WW\n" "tags\n" " include system-ipv4-works\n" " exclude \n" "\n" ) self.assertEqual( set(stdout.getvalue().split("\n")), set(expected.split("\n")) ) with capture_sys_output() as (stdout, stderr): cmd = PingMeasureCommand() cmd.init_args([ "ping", "--target", "ripe.net", "--af", "6", "--include-tag", "alpha", "--include-tag", "bravo", "--include-tag", "charlie", "--exclude-tag", "delta", "--exclude-tag", "echo", "--exclude-tag", "foxtrot", "--dry-run" ]) cmd.run() expected = ( "\n" "Definitions:\n" "================================================================================\n" "target ripe.net\n" "packet_interval 1000\n" "description Ping measurement to ripe.net\n" "af 6\n" "packets 3\n" "size 48\n" "\n" "Sources:\n" "================================================================================\n" "requested 50\n" "type area\n" "value WW\n" "tags\n" " include alpha, bravo, charlie\n" " exclude delta, echo, foxtrot\n" "\n" ) self.assertEqual( set(stdout.getvalue().split("\n")), set(expected.split("\n")) )