Esempio n. 1
0
    def test_join_header_words(self):
        from mechanize._headersutil import join_header_words

        assert join_header_words([[("foo", None), ("bar", "baz"),
                                   (None, "value")]]) == "foo; bar=baz; value"

        assert join_header_words([[]]) == ""
Esempio n. 2
0
    def test_join_header_words(self):
        from mechanize._headersutil import join_header_words

        assert join_header_words([[
            ("foo", None), ("bar", "baz"), (None, "value")
            ]]) == "foo; bar=baz; value"

        assert join_header_words([[]]) == ""
Esempio n. 3
0
    def test_roundtrip(self):
        from mechanize._headersutil import split_header_words, join_header_words

        tests = [
            ("foo", "foo"),
            ("foo=bar", "foo=bar"),
            ("   foo   ", "foo"),
            ("foo=", 'foo=""'),
            ("foo=bar bar=baz", "foo=bar; bar=baz"),
            ("foo=bar;bar=baz", "foo=bar; bar=baz"),
            ('foo bar baz', "foo; bar; baz"),
            (r'foo="\"" bar="\\"', r'foo="\""; bar="\\"'),
            ('foo,,,bar', 'foo, bar'),
            ('foo=bar,bar=baz', 'foo=bar, bar=baz'),

            ('text/html; charset=iso-8859-1',
             'text/html; charset="iso-8859-1"'),

            ('foo="bar"; port="80,81"; discard, bar=baz',
             'foo=bar; port="80,81"; discard, bar=baz'),

            (r'Basic realm="\"foo\\\\bar\""',
             r'Basic; realm="\"foo\\\\bar\""')
            ]

        for arg, expect in tests:
            input = split_header_words([arg])
            res = join_header_words(input)
            assert res == expect, """
When parsing: '%s'
Expected:     '%s'
Got:          '%s'
Input was:    '%s'""" % (arg, expect, res, input)
Esempio n. 4
0
    def test_roundtrip(self):
        from mechanize._headersutil import split_header_words, join_header_words

        tests = [("foo", "foo"), ("foo=bar", "foo=bar"), ("   foo   ", "foo"),
                 ("foo=", 'foo=""'), ("foo=bar bar=baz", "foo=bar; bar=baz"),
                 ("foo=bar;bar=baz", "foo=bar; bar=baz"),
                 ('foo bar baz', "foo; bar; baz"),
                 (r'foo="\"" bar="\\"', r'foo="\""; bar="\\"'),
                 ('foo,,,bar', 'foo, bar'),
                 ('foo=bar,bar=baz', 'foo=bar, bar=baz'),
                 ('text/html; charset=iso-8859-1',
                  'text/html; charset="iso-8859-1"'),
                 ('foo="bar"; port="80,81"; discard, bar=baz',
                  'foo=bar; port="80,81"; discard, bar=baz'),
                 (r'Basic realm="\"foo\\\\bar\""',
                  r'Basic; realm="\"foo\\\\bar\""')]

        for arg, expect in tests:
            input = split_header_words([arg])
            res = join_header_words(input)
            assert res == expect, """
When parsing: '%s'
Expected:     '%s'
Got:          '%s'
Input was:    '%s'""" % (arg, expect, res, input)