Пример #1
0
    def test_duration_timeout(self):
        client = Client()
        file = io.BytesIO()

        with self.assertRaises(DurationTimeout), client.session() as session:
            yield from \
                session.start(Request(self.get_url('/hidden/sleep.txt')))
            yield from session.download(file, duration_timeout=0.1)
Пример #2
0
    def test_duration_timeout(self):
        client = Client()
        file = io.BytesIO()

        with self.assertRaises(DurationTimeout), client.session() as session:
            yield from \
                session.start(Request(self.get_url('/hidden/sleep.txt')))
            yield from session.download(file, duration_timeout=0.1)
Пример #3
0
    def test_login_no_password_required(self):
        client = Client()
        file = io.BytesIO()

        with client.session() as session:
            request = Request(self.get_url('/example (copy).txt'))
            request.username = '******'
            yield from session.start(request)
            yield from session.download(file)
Пример #4
0
    def test_login_no_password_required(self):
        client = Client()
        file = io.BytesIO()

        with client.session() as session:
            request = Request(self.get_url('/example (copy).txt'))
            request.username = '******'
            yield from session.start(request)
            yield from session.download(file)
Пример #5
0
    def test_fetch_file(self):
        client = Client()
        file = io.BytesIO()

        with client.session() as session:
            response = yield from \
                session.start(Request(self.get_url('/example (copy).txt')))
            yield from session.download(file)

        self.assertEqual(
            'The real treasure is in Smaug’s heart 💗.\n'.encode('utf-8'),
            response.body.content())
Пример #6
0
    def test_fetch_no_file(self):
        client = Client()
        file = io.BytesIO()

        with client.session() as session:
            try:
                yield from \
                    session.start(Request(self.get_url('/asdf.txt')))
                yield from session.download(file)
            except FTPServerError as error:
                self.assertEqual(550, error.reply_code)
            else:
                self.fail()  # pragma: no cover
Пример #7
0
    def test_fetch_file(self):
        client = Client()
        file = io.BytesIO()

        with client.session() as session:
            response = yield from \
                session.start(Request(self.get_url('/example (copy).txt')))
            yield from session.download(file)

        self.assertEqual(
            'The real treasure is in Smaug’s heart 💗.\n'.encode('utf-8'),
            response.body.content()
        )
Пример #8
0
    def test_fetch_no_file(self):
        client = Client()
        file = io.BytesIO()

        with client.session() as session:
            try:
                yield from \
                    session.start(Request(self.get_url('/asdf.txt')))
                yield from session.download(file)
            except FTPServerError as error:
                self.assertEqual(550, error.reply_code)
            else:
                self.fail()  # pragma: no cover
Пример #9
0
    def test_fetch_file_restart_not_supported(self):
        client = Client()
        file = io.BytesIO()

        with client.session() as session:
            request = Request(self.get_url('/example (copy).txt'))
            request.set_continue(99999)  # Magic value in the test server
            response = yield from session.start(request)
            self.assertFalse(response.restart_value)
            yield from session.download(file)

        self.assertEqual(
            'The real treasure is in Smaug’s heart 💗.\n'.encode('utf-8'),
            response.body.content())
Пример #10
0
    def test_fetch_file_restart(self):
        client = Client()
        file = io.BytesIO()

        with client.session() as session:
            request = Request(self.get_url('/example (copy).txt'))
            request.set_continue(10)
            response = yield from session.start(request)
            self.assertEqual(10, response.restart_value)
            yield from session.download(file)

        self.assertEqual(
            'reasure is in Smaug’s heart 💗.\n'.encode('utf-8'),
            response.body.content())
Пример #11
0
    def test_fetch_listing(self):
        client = Client()
        file = io.BytesIO()
        with client.session() as session:
            response = yield from \
                session.start_listing(Request(self.get_url('/')))
            yield from session.download_listing(file)

        print(response.body.content())
        self.assertEqual(5, len(response.files))
        self.assertEqual('junk', response.files[0].name)
        self.assertEqual('example1', response.files[1].name)
        self.assertEqual('example2💎', response.files[2].name)
        self.assertEqual('example (copy).txt', response.files[3].name)
        self.assertEqual('readme.txt', response.files[4].name)
Пример #12
0
    def test_fetch_file_restart_not_supported(self):
        client = Client()
        file = io.BytesIO()

        with client.session() as session:
            request = Request(self.get_url('/example (copy).txt'))
            request.set_continue(99999)  # Magic value in the test server
            response = yield from session.start(request)
            self.assertFalse(response.restart_value)
            yield from session.download(file)

        self.assertEqual(
            'The real treasure is in Smaug’s heart 💗.\n'.encode('utf-8'),
            response.body.content()
        )
Пример #13
0
    def test_fetch_file_restart(self):
        client = Client()
        file = io.BytesIO()

        with client.session() as session:
            request = Request(self.get_url('/example (copy).txt'))
            request.set_continue(10)
            response = yield from session.start(request)
            self.assertEqual(10, response.restart_value)
            yield from session.download(file)

        self.assertEqual(
            'reasure is in Smaug’s heart 💗.\n'.encode('utf-8'),
            response.body.content()
        )
Пример #14
0
    def test_fetch_listing(self):
        client = Client()
        file = io.BytesIO()
        with client.session() as session:
            response = yield from \
                session.start_listing(Request(self.get_url('/')))
            yield from session.download_listing(file)

        print(response.body.content())
        self.assertEqual(5, len(response.files))
        self.assertEqual('junk', response.files[0].name)
        self.assertEqual('example1', response.files[1].name)
        self.assertEqual('example2💎', response.files[2].name)
        self.assertEqual('example (copy).txt', response.files[3].name)
        self.assertEqual('readme.txt', response.files[4].name)
Пример #15
0
    def test_fetch_bad_pasv_addr(self):
        client = Client()
        file = io.BytesIO()

        with client.session() as session:
            original_func = session._log_in

            @asyncio.coroutine
            def override_func():
                yield from original_func()
                yield from session._control_stream.write_command(Command('EVIL_BAD_PASV_ADDR'))
                print('Evil awaits')

            # TODO: should probably have a way of sending custom commands
            session._log_in = override_func

            with self.assertRaises(ProtocolError):
                yield from \
                    session.start(Request(self.get_url('/example (copy).txt')))
Пример #16
0
    def test_fetch_bad_pasv_addr(self):
        client = Client()
        file = io.BytesIO()

        with client.session() as session:
            original_func = session._log_in

            @asyncio.coroutine
            def override_func():
                yield from original_func()
                yield from session._control_stream.write_command(
                    Command('EVIL_BAD_PASV_ADDR'))
                print('Evil awaits')

            # TODO: should probably have a way of sending custom commands
            session._log_in = override_func

            with self.assertRaises(ProtocolError):
                yield from \
                    session.start(Request(self.get_url('/example (copy).txt')))