コード例 #1
0
ファイル: test_hpack.py プロジェクト: irvind/pyhttp2
    def setUp(self):
        self.table = IndexTable()

        self.modif_table = IndexTable()
        self.modif_table.add('myfield', 'myvalue')
        self.modif_table.add('myfield2', 'myvalue2')
        self.modif_table.add('somefield', 'somevalue')
コード例 #2
0
    def setUp(self):
        self.table = IndexTable()

        self.modif_table = IndexTable()
        self.modif_table.add('myfield', 'myvalue')
        self.modif_table.add('myfield2', 'myvalue2')
        self.modif_table.add('somefield', 'somevalue')
コード例 #3
0
    def test_find_name(self):
        self.assertEqual(self.table.find(':scheme'), 6)
        self.assertEqual(self.table.find('www-authenticate'),
                         IndexTable.STATIC_LENGTH)

        self.assertEqual(self.modif_table.find('myfield'),
                         IndexTable.STATIC_LENGTH + 3)
        self.assertIsNone(self.modif_table.find('notfound'))

        tbl = IndexTable()
        tbl.add('f1', '1')
        tbl.add('f1', '2')
        tbl.add('f2', '3')
        self.assertEqual(tbl.find('f1'), IndexTable.STATIC_LENGTH + 2)
コード例 #4
0
ファイル: test_hpack.py プロジェクト: irvind/pyhttp2
    def test_find_name(self):
        self.assertEqual(self.table.find(':scheme'), 6)
        self.assertEqual(self.table.find('www-authenticate'), IndexTable.STATIC_LENGTH)

        self.assertEqual(self.modif_table.find('myfield'), IndexTable.STATIC_LENGTH + 3)
        self.assertIsNone(self.modif_table.find('notfound'))

        tbl = IndexTable()
        tbl.add('f1', '1')
        tbl.add('f1', '2')
        tbl.add('f2', '3')
        self.assertEqual(tbl.find('f1'), IndexTable.STATIC_LENGTH + 2)
コード例 #5
0
ファイル: test_hpack.py プロジェクト: irvind/pyhttp2
class TestIndexTable(unittest.TestCase):
    def setUp(self):
        self.table = IndexTable()

        self.modif_table = IndexTable()
        self.modif_table.add('myfield', 'myvalue')
        self.modif_table.add('myfield2', 'myvalue2')
        self.modif_table.add('somefield', 'somevalue')

    def test_getitem(self):
        self.assertEqual(self.table[1], (':authority', ''))
        self.assertEqual(self.table[5], (':path', '/index.html'))
        self.assertEqual(self.table[IndexTable.STATIC_LENGTH], ('www-authenticate', ''))

        self.assertEqual(self.modif_table[IndexTable.STATIC_LENGTH + 1], ('somefield', 'somevalue'))

        with self.assertRaises(IndexError):
            print(self.table[100])

    def test_insertion(self):
        self.table.add('myfield', 'myval')
        self.assertEqual(self.table.get(IndexTable.STATIC_LENGTH + 1), ('myfield', 'myval'))

        self.table.add('myfield2', 'myval2')
        self.assertEqual(self.table.get(IndexTable.STATIC_LENGTH + 1), ('myfield2', 'myval2'))
        self.assertEqual(self.table.get(IndexTable.STATIC_LENGTH + 2), ('myfield', 'myval'))

    def test_len(self):
        self.assertEqual(len(self.table), IndexTable.STATIC_LENGTH)
        self.assertEqual(len(self.modif_table), IndexTable.STATIC_LENGTH + 3)

    def test_find_name(self):
        self.assertEqual(self.table.find(':scheme'), 6)
        self.assertEqual(self.table.find('www-authenticate'), IndexTable.STATIC_LENGTH)

        self.assertEqual(self.modif_table.find('myfield'), IndexTable.STATIC_LENGTH + 3)
        self.assertIsNone(self.modif_table.find('notfound'))

        tbl = IndexTable()
        tbl.add('f1', '1')
        tbl.add('f1', '2')
        tbl.add('f2', '3')
        self.assertEqual(tbl.find('f1'), IndexTable.STATIC_LENGTH + 2)

    def test_find_field(self):
        self.assertEqual(self.table.find(':method', 'POST'), 3)
        self.assertEqual(self.table.find('accept-charset', ''), 15)

        self.assertIsNone(self.table.find('none', 'none'))

        self.assertEqual(self.modif_table.find('somefield', 'somevalue'), IndexTable.STATIC_LENGTH + 1)
        self.assertEqual(self.modif_table.find('myfield', 'myvalue'), IndexTable.STATIC_LENGTH + 3)
コード例 #6
0
class TestIndexTable(unittest.TestCase):
    def setUp(self):
        self.table = IndexTable()

        self.modif_table = IndexTable()
        self.modif_table.add('myfield', 'myvalue')
        self.modif_table.add('myfield2', 'myvalue2')
        self.modif_table.add('somefield', 'somevalue')

    def test_getitem(self):
        self.assertEqual(self.table[1], (':authority', ''))
        self.assertEqual(self.table[5], (':path', '/index.html'))
        self.assertEqual(self.table[IndexTable.STATIC_LENGTH],
                         ('www-authenticate', ''))

        self.assertEqual(self.modif_table[IndexTable.STATIC_LENGTH + 1],
                         ('somefield', 'somevalue'))

        with self.assertRaises(IndexError):
            print(self.table[100])

    def test_insertion(self):
        self.table.add('myfield', 'myval')
        self.assertEqual(self.table.get(IndexTable.STATIC_LENGTH + 1),
                         ('myfield', 'myval'))

        self.table.add('myfield2', 'myval2')
        self.assertEqual(self.table.get(IndexTable.STATIC_LENGTH + 1),
                         ('myfield2', 'myval2'))
        self.assertEqual(self.table.get(IndexTable.STATIC_LENGTH + 2),
                         ('myfield', 'myval'))

    def test_len(self):
        self.assertEqual(len(self.table), IndexTable.STATIC_LENGTH)
        self.assertEqual(len(self.modif_table), IndexTable.STATIC_LENGTH + 3)

    def test_find_name(self):
        self.assertEqual(self.table.find(':scheme'), 6)
        self.assertEqual(self.table.find('www-authenticate'),
                         IndexTable.STATIC_LENGTH)

        self.assertEqual(self.modif_table.find('myfield'),
                         IndexTable.STATIC_LENGTH + 3)
        self.assertIsNone(self.modif_table.find('notfound'))

        tbl = IndexTable()
        tbl.add('f1', '1')
        tbl.add('f1', '2')
        tbl.add('f2', '3')
        self.assertEqual(tbl.find('f1'), IndexTable.STATIC_LENGTH + 2)

    def test_find_field(self):
        self.assertEqual(self.table.find(':method', 'POST'), 3)
        self.assertEqual(self.table.find('accept-charset', ''), 15)

        self.assertIsNone(self.table.find('none', 'none'))

        self.assertEqual(self.modif_table.find('somefield', 'somevalue'),
                         IndexTable.STATIC_LENGTH + 1)
        self.assertEqual(self.modif_table.find('myfield', 'myvalue'),
                         IndexTable.STATIC_LENGTH + 3)