Esempio n. 1
0
 def test_strips_spaces(self):
     accept = http.Accept.from_header(header=" text/* ; q=0.2 ,  text/foo")
     media_types = (
         http.MediaRange(type="text", quality=0.2),
         http.MediaRange(type="text", subtype="foo", quality=1.0),
     )
     self.assertEqual(accept, http.Accept(media_types=media_types))
Esempio n. 2
0
 def test_multiple(self):
     accept = http.Accept.from_header(header="audio/*; q=0.2, audio/basic")
     media_types = (
         http.MediaRange(type="audio", quality=0.2),
         http.MediaRange(type="audio", subtype="basic", quality=1.0),
     )
     self.assertEqual(accept, http.Accept(media_types=media_types))
Esempio n. 3
0
 def test_not_lt_parameters_different_subtype(self):
     self.assertFalse(
         http.MediaRange(type="bar", subtype="foo") < http.MediaRange(
             type="bar",
             subtype="baz",
             parameters=pmap({"a": "b"}),
         ), )
Esempio n. 4
0
 def test_hash_parameters(self):
     self.assertEqual(
         {
             http.MediaRange(type="a", parameters={"a": "b"}),
             http.MediaRange(type="a", parameters={"a": "b"}),
         },
         {http.MediaRange(type="a", parameters={"a": "b"})},
     )
Esempio n. 5
0
 def test_hash(self):
     self.assertEqual(
         {
             http.MediaRange(type="text", subtype="plain", quality=0.8),
             http.MediaRange(type="text", subtype="plain", quality=0.8),
         },
         {http.MediaRange(type="text", subtype="plain", quality=0.8)},
     )
Esempio n. 6
0
 def test_lt_parameters_same_type_and_subtype(self):
     self.assertLess(
         http.MediaRange(type="bar", subtype="foo"),
         http.MediaRange(
             type="bar",
             subtype="foo",
             parameters=pmap({"a": "b"}),
         ),
     )
Esempio n. 7
0
 def test_more_elaborate(self):
     accept = http.Accept.from_header(
         header="text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c",
     )
     media_types = (
         http.MediaRange(type="text", subtype="plain", quality=0.5),
         http.MediaRange(type="text", subtype="x-dvi", quality=0.8),
         http.MediaRange(type="text", subtype="html"),
         http.MediaRange(type="text", subtype="x-c"),
     )
     self.assertEqual(accept, http.Accept(media_types=media_types))
Esempio n. 8
0
 def test_override_with_more_specific_type(self):
     accept = http.Accept.from_header(
         header="text/*, text/plain, text/plain;format=flowed, */*", )
     media_types = (
         http.MediaRange(),
         http.MediaRange(type="text"),
         http.MediaRange(type="text", subtype="plain"),
         http.MediaRange(
             type="text",
             subtype="plain",
             parameters=dict(format="flowed"),
         ),
     )
     self.assertEqual(accept, http.Accept(media_types=media_types))
Esempio n. 9
0
 def test_basic(self):
     accept = http.Accept.from_header(header="application/json")
     media_range = http.MediaRange(
         type="application",
         subtype="json",
         quality=1.0,
     )
     self.assertEqual(accept, http.Accept(media_types=(media_range, )))
Esempio n. 10
0
 def test_quality_factors(self):
     accept = http.Accept.from_header(
         header="text/*;q=0.3, text/html;q=0.7, text/html;level=1, "
         "text/html;level=2;q=0.4, */*;q=0.5", )
     media_types = (
         http.MediaRange(type="text", quality=0.3),
         http.MediaRange(
             type="text",
             subtype="html",
             quality=0.4,
             parameters=dict(level="2"),
         ),
         http.MediaRange(quality=0.5),
         http.MediaRange(type="text", subtype="html", quality=0.7),
         http.MediaRange(
             type="text",
             subtype="html",
             parameters=dict(level="1"),
         ),
     )
     self.assertEqual(accept, http.Accept(media_types=media_types))
Esempio n. 11
0
 def test_quality_factors(self):
     accept = http.Accept.from_header(
         header=(b"text/*;q=0.3, text/html;q=0.7, text/html;level=1, "
                 b"text/html;level=2;q=0.4, */*;q=0.5"), )
     media_types = (
         http.MediaRange(type=b"text", quality=0.3),
         http.MediaRange(
             type=b"text",
             subtype=b"html",
             quality=0.4,
             parameters=pmap({b"level": b"2"}),
         ),
         http.MediaRange(quality=0.5),
         http.MediaRange(type=b"text", subtype=b"html", quality=0.7),
         http.MediaRange(
             type=b"text",
             subtype=b"html",
             parameters=pmap({b"level": b"1"}),
         ),
     )
     self.assertEqual(accept, http.Accept(media_types=media_types))
Esempio n. 12
0
 def test_lt_equal_range(self):
     self.assertFalse(http.MediaRange() < http.MediaRange())
Esempio n. 13
0
 def test_ne_quality(self):
     self.assertTrue(
         http.MediaRange(type="text", subtype="plain", quality=0.5) !=
         http.MediaRange(type="text", subtype="plain", quality=0.8), )
Esempio n. 14
0
 def test_not_lt_ranged_subtype(self):
     self.assertFalse(
         http.MediaRange(type="text", subtype="plain") <
         http.MediaRange(type="text"), )
Esempio n. 15
0
 def test_not_lt_ranged_lower_quality(self):
     self.assertFalse(
         http.MediaRange(quality=0.5) < http.MediaRange(type="text",
                                                        quality=0.3), )
Esempio n. 16
0
 def test_not_lt_different_type_and_subtype(self):
     self.assertFalse(
         http.MediaRange(type="application", subtype="json") <
         http.MediaRange(type="text", subtype="plain"), )
Esempio n. 17
0
 def test_not_lt_parameters(self):
     self.assertFalse(
         http.MediaRange(type="bar", subtype="foo", parameters={"a": "b"}) <
         http.MediaRange(type="bar", subtype="foo"), )
Esempio n. 18
0
 def test_lt_different_type_and_subtype(self):
     self.assertLess(
         http.MediaRange(type="application", subtype="json", quality=0.5),
         http.MediaRange(type="text", subtype="plain", quality=0.8),
     )
Esempio n. 19
0
 def test_not_lt_same_type_and_subtype(self):
     self.assertFalse(
         http.MediaRange(type="text", subtype="plain", quality=0.8) <
         http.MediaRange(type="text", subtype="plain", quality=0.5), )
Esempio n. 20
0
 def test_lt_ranged_type_and_subtype(self):
     self.assertLess(http.MediaRange(), http.MediaRange(type="text"))
Esempio n. 21
0
 def test_lt_ranged_lower_quality(self):
     self.assertLess(
         http.MediaRange(type="text", quality=0.3),
         http.MediaRange(quality=0.5),
     )
Esempio n. 22
0
 def test_lt_ranged_subtype(self):
     self.assertLess(
         http.MediaRange(type="text"),
         http.MediaRange(type="text", subtype="plain"),
     )
Esempio n. 23
0
 def test_eq(self):
     self.assertTrue(
         http.MediaRange(type="text", subtype="plain",
                         quality=0.5) == http.MediaRange(type="text",
                                                         subtype="plain",
                                                         quality=0.5), )
Esempio n. 24
0
 def test_eq_quality(self):
     self.assertFalse(
         http.MediaRange(type="text", subtype="plain",
                         quality=0.5) == http.MediaRange(type="text",
                                                         subtype="plain",
                                                         quality=0.8), )
Esempio n. 25
0
 def test_ne(self):
     self.assertFalse(
         http.MediaRange(type="text", subtype="plain", quality=0.5) !=
         http.MediaRange(type="text", subtype="plain", quality=0.5), )
Esempio n. 26
0
 def test_eq_parameters(self):
     self.assertFalse(
         http.MediaRange(type="text",
                         parameters={"a": "b"}) == http.MediaRange(
                             type="text", parameters={"a": "c"}), )
Esempio n. 27
0
 def test_hash_different_parameters(self):
     self.assertNotEqual(
         hash(http.MediaRange(type="a", parameters={"a": "b"})),
         hash(http.MediaRange(type="a", parameters={"a": "c"})),
     ),
Esempio n. 28
0
 def test_ne_parameters(self):
     self.assertTrue(
         http.MediaRange(type="text", parameters={"a": "b"}) !=
         http.MediaRange(type="text", parameters={"a": "c"}), )