def test_basic(self): dc = PlainContainer('abc', 'text/plain') self.assertEqual('abc', str(dc)) self.assertNotIn('abc', dc) self.assertEqual(dc.content_type_header_value, 'text/plain') self.assertEqual(dc.get_headers(), [('content-type', 'text/plain')])
def dc_from_hdrs_post(headers, post_data): """ :param headers: HTTP request headers, most importantly containing the content-type info. :param post_data: The HTTP request post-data as a string :return: The best-match from POST_DATA_CONTAINERS to hold the information in self._post_data @ FuzzableRequest """ if headers is None: headers = Headers() for pdc_klass in POST_DATA_CONTAINERS: try: return pdc_klass.from_postdata(headers, post_data) except (ValueError, TypeError) as e: pass else: content_type, _ = headers.iget('content-type', 'None') msg = 'Unknown post-data. Content-type: "%s" and/or post-data "%s"' om.out.debug(msg % (content_type, post_data[:50])) # These lines are for debugging # import traceback # traceback.print_stack() return PlainContainer.from_postdata(headers, post_data)
def dc_from_hdrs_post(headers, post_data): """ :param headers: HTTP request headers, most importantly containing the content-type info. :param post_data: The HTTP request post-data as a string :return: The best-match from POST_DATA_CONTAINERS to hold the information in self._post_data @ FuzzableRequest """ if headers is None: headers = Headers() for pdc_klass in POST_DATA_CONTAINERS: try: return pdc_klass.from_postdata(headers, post_data) except (ValueError, TypeError) as e: pass else: content_type, _ = headers.iget("content-type", "None") msg = 'Unknown post-data. Content-type: "%s" and/or post-data "%s"' om.out.debug(msg % (content_type, post_data[:50])) # These lines are for debugging # import traceback # traceback.print_stack() return PlainContainer.from_postdata(headers, post_data)
def test_get_headers_none(self): dc = PlainContainer('abc') self.assertEqual(dc.get_headers(), [])
def test_is_variant_diff_headers(self): dc1 = PlainContainer('abc', 'text/plain') dc2 = PlainContainer('abc', 'text/xml') self.assertFalse(dc1.is_variant_of(dc2))
def test_is_variant_all_equal(self): dc1 = PlainContainer('abc', 'text/plain') dc2 = PlainContainer('abc', 'text/plain') self.assertTrue(dc1.is_variant_of(dc2))
def test_iter_setters(self): dc = PlainContainer('abc', 'text/plain') tokens = [t for t in dc.iter_setters()] self.assertEqual(tokens, [])
def test_set_token(self): dc = PlainContainer('abc', 'text/plain') # Content is not a token self.assertRaises(RuntimeError, dc.set_token, 'abc')