Beispiel #1
0
        class Tester(BotFinder):

            correct_channel_joined = False

            def on_welcome(self, conn, event):
                self.current_pack = XDCCPack(self.server, "HelloKitty", 1)
                self.connection.whois(self.current_pack.get_bot())

            # noinspection PyUnusedLocal
            def on_nosuchnick(self, conn, event):
                self.on_endofwhois(conn, event)

            # noinspection PyUnusedLocal
            def on_join(self, conn, event):
                if event.target.lower() == BotChannelMapper.map(
                        self.current_pack.get_bot()).lower():
                    self.correct_channel_joined = True
                    raise TestException()
Beispiel #2
0
        class Tester(DownloadHandler):
            def on_welcome(self, conn, event):
                self.current_pack = XDCCPack(self.server, "xdcc_servbot", 2)
                self.pack_queue = []
                self.progress = Progress(1)

                with open("2_test.txt", 'w') as f:
                    f.write("Test")

                self.dcc_resume_requested = True
                self.connection.whois(self.current_pack.get_bot())
Beispiel #3
0
        class Tester(BotFinder):

            dummy_channel_joined = False

            def on_welcome(self, conn, event):
                self.current_pack = XDCCPack(self.server, "channelless_bot", 1)
                self.connection.whois(self.current_pack.get_bot())

            # noinspection PyUnusedLocal
            def on_nosuchnick(self, conn, event):
                self.on_endofwhois(conn, event)

            # noinspection PyUnusedLocal
            def on_join(self, conn, event):
                if event.source == self.user.get_name():
                    self.dummy_channel_joined = True
                    raise TestException()
Beispiel #4
0
class UnitTests(unittest.TestCase):
    def setUp(self):
        self.pack = XDCCPack(IrcServer("irc.namibsun.net"), "xdcc_servbot", 1)

    def tearDown(self):
        pass

    def test_getters(self):

        self.assertEqual(self.pack.get_packnumber(), 1)
        self.assertEqual(self.pack.get_bot(), "xdcc_servbot")
        self.assertEqual(self.pack.get_filename(), "")
        self.assertEqual(self.pack.get_size(), 0)
        self.assertEqual(self.pack.get_server().get_address(),
                         "irc.namibsun.net")
        self.assertEqual(self.pack.get_filepath(), os.getcwd() + os.sep)
        self.assertEqual(self.pack.get_request_message(), "xdcc send #1")

    def test_setting_filename(self):

        self.pack.set_filename("test")
        self.assertEqual(self.pack.get_filename(), "test")
        self.assertEqual(self.pack.get_filepath(),
                         os.path.join(os.getcwd(), "test"))

        self.pack.set_filename("something")
        self.assertEqual(self.pack.get_filename(), "test")
        self.assertEqual(self.pack.get_filepath(),
                         os.path.join(os.getcwd(), "test"))

        self.pack.set_filename("something", override=True)
        self.assertEqual(self.pack.get_filename(), "something")
        self.assertEqual(self.pack.get_filepath(),
                         os.path.join(os.getcwd(), "something"))

        self.pack.set_filename("something_else.txt")
        self.assertEqual(self.pack.get_filename(), "something.txt")
        self.assertEqual(self.pack.get_filepath(),
                         os.path.join(os.getcwd(), "something.txt"))

        self.pack.set_filename("something_else.txt")
        self.assertEqual(self.pack.get_filename(), "something.txt")
        self.assertEqual(self.pack.get_filepath(),
                         os.path.join(os.getcwd(), "something.txt"))

        self.pack.set_filename("something_else.mkv")
        self.assertEqual(self.pack.get_filename(), "something.txt.mkv")
        self.assertEqual(self.pack.get_filepath(),
                         os.path.join(os.getcwd(), "something.txt.mkv"))

        self.pack.set_directory(os.path.join(os.getcwd(), "test"))
        self.assertEqual(self.pack.get_filename(), "something.txt.mkv")
        self.assertEqual(
            self.pack.get_filepath(),
            os.path.join(os.getcwd(), "test", "something.txt.mkv"))

    def test_original_filename_check(self):

        self.assertTrue(self.pack.is_filename_valid("the_original"))
        self.assertTrue(self.pack.is_filename_valid("not_the_original"))
        self.pack.set_original_filename("the_original")
        self.assertTrue(self.pack.is_filename_valid("the_original"))
        self.assertFalse(self.pack.is_filename_valid("not_the_original"))

    def test_request_message(self):
        self.assertEqual(self.pack.get_request_message(), "xdcc send #1")
        self.assertEqual(self.pack.get_request_message(full=True),
                         "/msg xdcc_servbot xdcc send #1")

    def test_generating_from_xdcc_message_single(self):

        packs = xdcc_packs_from_xdcc_message("/msg xdcc_servbot xdcc send #1",
                                             "testdir", "irc.namibsun.net")
        self.assertEqual(len(packs), 1)
        pack = packs[0]

        self.assertEqual(pack.get_packnumber(), 1)
        self.assertEqual(pack.get_bot(), "xdcc_servbot")
        self.assertEqual(pack.get_server().get_address(), "irc.namibsun.net")
        self.assertEqual(pack.get_filepath(), "testdir" + os.sep)
        self.assertTrue(
            pack.get_request_message() in "/msg xdcc_servbot xdcc send #1")

    def test_generating_from_xdcc_message_range(self):

        packs = xdcc_packs_from_xdcc_message(
            "/msg xdcc_servbot xdcc send #1-100")
        self.assertEqual(len(packs), 100)

        for i, pack in enumerate(packs):
            self.assertEqual(pack.get_packnumber(), i + 1)
            self.assertEqual(pack.get_server().get_address(), "irc.rizon.net")
            self.assertEqual(pack.get_filepath(), os.getcwd() + os.sep)

    def test_generating_from_xdcc_message_range_with_jumps(self):

        packs = xdcc_packs_from_xdcc_message(
            "/msg xdcc_servbot xdcc send #1-100,2")
        self.assertEqual(len(packs), 50)

        i = 1
        for pack in packs:
            self.assertEqual(pack.get_packnumber(), i)
            i += 2

    def test_generating_invalid_xdcc_message(self):

        packs = xdcc_packs_from_xdcc_message("randomnonesense")
        self.assertEqual(len(packs), 0)