Example #1
0
 def test_special_characters(self):
     self.assertEquals(
         parse('application/*; test=_0-2'),
         [MediaType('application/*', params={"test": "_0-2"})]
     )
     self.assertEquals(
         parse("application/*; test=_0-2'"),
         [MediaType('application/*', params={"test": "_0-2"})]
     )
Example #2
0
 def test_string_representation_parameter(self):
     header = 'application/json; q=0.2; level=1; test=2; something=3'
     m = parse(header)[0]
     self.assertEquals(
         str(m),
         header
     )
Example #3
0
 def test_string_representation(self):
     header = 'application/json; q=0.2'
     m = parse(header)[0]
     self.assertEquals(
         str(m),
         header
     )
Example #4
0
 def test_representation(self):
     header = 'application/json; q=0.2; level=1; test=2; something=3'
     m = parse(header)[0]
     self.assertEquals(
         repr(m),
         '<Media Type: {}>'.format(header)
     )
Example #5
0
 def test_media_type_parameter_with_quotes(self):
     self.assertEquals(
         parse('application/*; q="0.2"'),
         [MediaType('application/*', 0.2)]
     )
     self.assertEquals(
         parse("application/*; q='0.2'"),
         [MediaType('application/*', 0.2)]
     )
     self.assertEquals(
         parse('application/*; q=0.2; test="moop"'),
         [MediaType('application/*', 0.2, {"test": "moop"})]
     )
     self.assertEquals(
         parse("application/*; q=0.2; test='moop'"),
         [MediaType('application/*', 0.2, {"test": "moop"})]
     )
Example #6
0
 def test_prefer_most_specific_type(self):
     m = [
         MediaType('application/json'),
         MediaType('application/*', 0.2),
     ]
     self.assertEquals(
         parse('application/*; q=0.2, application/json'),
         m
     )
Example #7
0
 def test_elaborate_accept_header(self):
     self.assertEquals(
         parse('text/*, text/html, text/html;level=1, */*'),
         [
             MediaType('text/html', params={'level': '1'}),
             MediaType('text/html'),
             MediaType('text/*'),
             MediaType('*/*')
         ]
     )
Example #8
0
 def test_real_world_header(self):
     m = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
     self.assertEquals(
         parse(m),
         [
             MediaType('text/html'),
             MediaType('application/xhtml+xml'),
             MediaType('application/xml', q=0.9),
             MediaType('*/*', q=0.8)
         ]
     )
Example #9
0
 def test_parse_broken_accept_header(self):
     header = ('text/xml,application/xml,application/xhtml+xml,') +\
              ('text/html;q=0.9,text/plain;q=0.8,image/*,,*/*;q=0.5')
     self.assertEquals(
         parse(header),
         [
             MediaType('text/xml'),
             MediaType('application/xml'),
             MediaType('application/xhtml+xml'),
             MediaType('image/*'),
             MediaType('text/html', q=0.9),
             MediaType('text/plain', q=0.8),
             MediaType('*/*', q=0.5)
         ]
     )
Example #10
0
 def test_non_valid_q_value(self):
     self.assertEquals(
         parse('application/*; q=_0-2'),
         [MediaType('application/*', 1.0)]
     )
Example #11
0
 def test_accept_header_still_included(self):
     m = [MediaType('application/json')]
     self.assertEquals(m, parse('Accept: application/json'))
Example #12
0
 def test_parse_simple_header(self):
     m = [MediaType('application/json')]
     self.assertEquals(m, parse('application/json'))
Example #13
0
 def test_none_value(self):
     self.assertEquals(parse(None), [])
Example #14
0
 def test_empty_value(self):
     self.assertEquals(parse(''), [])