Esempio n. 1
0
 def test_repr(self):
     self.assertEqual(repr(MediaType('*/*; q=0.8')),
                      '<MediaType: */*; q=0.8>')
     self.assertEqual(
         repr(MediaType('application/xml')),
         '<MediaType: application/xml>',
     )
Esempio n. 2
0
 def test_repr(self):
     self.assertEqual(repr(MediaType("*/*; q=0.8")),
                      "<MediaType: */*; q=0.8>")
     self.assertEqual(
         repr(MediaType("application/xml")),
         "<MediaType: application/xml>",
     )
 def test_empty(self):
     for empty_media_type in (None, ''):
         with self.subTest(media_type=empty_media_type):
             media_type = MediaType(empty_media_type)
             self.assertIs(media_type.is_all_types, False)
             self.assertEqual(str(media_type), '')
             self.assertEqual(repr(media_type), '<MediaType: >')
 def test_no_match(self):
     tests = [
         (None, '*/*'),
         ('', '*/*'),
         ('; q=0.8', '*/*'),
         ('application/xml', 'application/html'),
         ('application/xml', '*/*'),
     ]
     for accepted_type, mime_type in tests:
         with self.subTest(accepted_type, mime_type=mime_type):
             self.assertIs(MediaType(accepted_type).match(mime_type), False)
Esempio n. 5
0
 def test_no_match(self):
     tests = [
         (None, "*/*"),
         ("", "*/*"),
         ("; q=0.8", "*/*"),
         ("application/xml", "application/html"),
         ("application/xml", "*/*"),
     ]
     for accepted_type, mime_type in tests:
         with self.subTest(accepted_type, mime_type=mime_type):
             self.assertIs(MediaType(accepted_type).match(mime_type), False)
 def test_match(self):
     tests = [
         ('*/*; q=0.8', '*/*'),
         ('*/*', 'application/json'),
         (' */* ', 'application/json'),
         ('application/*', 'application/json'),
         ('application/xml', 'application/xml'),
         (' application/xml ', 'application/xml'),
         ('application/xml', ' application/xml '),
     ]
     for accepted_type, mime_type in tests:
         with self.subTest(accepted_type, mime_type=mime_type):
             self.assertIs(MediaType(accepted_type).match(mime_type), True)
Esempio n. 7
0
 def test_match(self):
     tests = [
         ("*/*; q=0.8", "*/*"),
         ("*/*", "application/json"),
         (" */* ", "application/json"),
         ("application/*", "application/json"),
         ("application/xml", "application/xml"),
         (" application/xml ", "application/xml"),
         ("application/xml", " application/xml "),
     ]
     for accepted_type, mime_type in tests:
         with self.subTest(accepted_type, mime_type=mime_type):
             self.assertIs(MediaType(accepted_type).match(mime_type), True)
 def test_is_all_types(self):
     self.assertIs(MediaType('*/*').is_all_types, True)
     self.assertIs(MediaType('*/*; q=0.8').is_all_types, True)
     self.assertIs(MediaType('text/*').is_all_types, False)
     self.assertIs(MediaType('application/xml').is_all_types, False)
 def test_str(self):
     self.assertEqual(str(MediaType('*/*; q=0.8')), '*/*; q=0.8')
     self.assertEqual(str(MediaType('application/xml')), 'application/xml')
Esempio n. 10
0
 def test_is_all_types(self):
     self.assertIs(MediaType("*/*").is_all_types, True)
     self.assertIs(MediaType("*/*; q=0.8").is_all_types, True)
     self.assertIs(MediaType("text/*").is_all_types, False)
     self.assertIs(MediaType("application/xml").is_all_types, False)
Esempio n. 11
0
 def test_str(self):
     self.assertEqual(str(MediaType("*/*; q=0.8")), "*/*; q=0.8")
     self.assertEqual(str(MediaType("application/xml")), "application/xml")