Exemplo n.º 1
0
    def test_m_search(self):
        actual_output = StringIO()
        timeout_msg = "aioupnp encountered an error: M-SEARCH for 10.0.0.1:1900 timed out\n"
        with contextlib.redirect_stdout(actual_output):
            with mock_tcp_and_udp(self.loop,
                                  '10.0.0.1',
                                  tcp_replies={},
                                  udp_replies={}):
                main([
                    None, '--timeout=1', '--gateway_address=10.0.0.1',
                    '--lan_address=10.0.0.2', 'm-search'
                ], self.loop)
        self.assertEqual(timeout_msg, actual_output.getvalue())

        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            with mock_tcp_and_udp(self.loop,
                                  '10.0.0.1',
                                  tcp_replies=self.scpd_replies,
                                  udp_replies=self.udp_replies):
                main([
                    None, '--timeout=1', '--gateway_address=10.0.0.1',
                    '--lan_address=10.0.0.2', 'm-search'
                ], self.loop)
        self.assertEqual(m_search_cli_result, actual_output.getvalue())
Exemplo n.º 2
0
 def test_get_external_ip(self):
     actual_output = StringIO()
     with contextlib.redirect_stdout(actual_output):
         with mock_tcp_and_udp(self.loop, '10.0.0.1', tcp_replies=self.scpd_replies, udp_replies=self.udp_replies):
             main(
                 [None, '--timeout=1', '--gateway_address=10.0.0.1', '--lan_address=10.0.0.2', 'get-external-ip'],
                 self.loop
             )
     self.assertEqual("11.22.33.44\n", actual_output.getvalue())
Exemplo n.º 3
0
    def test_commands_help(self):
        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None, 'help', 'm-search'], self.loop)
        self.assertEqual(m_search_help_msg, actual_output.getvalue())

        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None, 'help', 'get-external-ip'], self.loop)

        self.assertEqual(expected_get_external_ip_usage,
                         actual_output.getvalue())

        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None, 'help', 'add-port-mapping'], self.loop)
        self.assertEqual(expected_add_port_mapping_usage,
                         actual_output.getvalue())
        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None, 'help', 'get-next-mapping'], self.loop)
        self.assertEqual(expected_get_next_mapping_usage,
                         actual_output.getvalue())

        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None, 'help', 'delete_port_mapping'], self.loop)
        self.assertEqual(expected_delete_port_mapping_usage,
                         actual_output.getvalue())

        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None, 'help', 'get_specific_port_mapping'], self.loop)
        self.assertEqual(expected_get_specific_port_mapping_usage,
                         actual_output.getvalue())

        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None, 'help', 'get_redirects'], self.loop)
        self.assertEqual(expected_get_redirects_usage,
                         actual_output.getvalue())

        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None, 'help', 'get_port_mapping_by_index'], self.loop)
        self.assertEqual(expected_get_port_mapping_by_index_usage,
                         actual_output.getvalue())
Exemplo n.º 4
0
    def test_usage(self):
        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None, 'help'], self.loop)
        self.assertEqual(expected_usage, actual_output.getvalue())

        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None, 'help', 'test'], self.loop)
        self.assertEqual(expected_usage, actual_output.getvalue())

        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None, 'test', 'help'], self.loop)
        self.assertEqual(
            "aioupnp encountered an error: \"test\" is not a recognized command\n",
            actual_output.getvalue())

        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None, 'test'], self.loop)
        self.assertEqual(
            "aioupnp encountered an error: \"test\" is not a recognized command\n",
            actual_output.getvalue())

        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None], self.loop)
        self.assertEqual(expected_usage, actual_output.getvalue())

        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            main([None, "--something=test"], self.loop)
        self.assertEqual("no command given\n" + expected_usage,
                         actual_output.getvalue())