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"})] )
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 )
def test_string_representation(self): header = 'application/json; q=0.2' m = parse(header)[0] self.assertEquals( str(m), header )
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) )
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"})] )
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 )
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('*/*') ] )
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) ] )
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) ] )
def test_non_valid_q_value(self): self.assertEquals( parse('application/*; q=_0-2'), [MediaType('application/*', 1.0)] )
def test_accept_header_still_included(self): m = [MediaType('application/json')] self.assertEquals(m, parse('Accept: application/json'))
def test_parse_simple_header(self): m = [MediaType('application/json')] self.assertEquals(m, parse('application/json'))
def test_none_value(self): self.assertEquals(parse(None), [])
def test_empty_value(self): self.assertEquals(parse(''), [])