Git Browser
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

41 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. from django.test.testcases import SimpleTestCase
  3. from gitbrowser.utils.http import parse_accept, bestof
  4. class UtilsHTTPTestCase(SimpleTestCase):
  5. def test_parse_accept(self):
  6. header = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
  7. cts = parse_accept(header)
  8. self.assertEqual(cts, [
  9. ('text/html', 0.9),
  10. ('application/xhtml+xml', 0.9),
  11. ('application/xml', 0.9),
  12. ('image/webp', 0.8),
  13. ('*/*', 0.8)
  14. ])
  15. def test_parse_accept_no_q(self):
  16. header = "text/html"
  17. cts = parse_accept(header)
  18. self.assertEqual(cts, [
  19. ('text/html', 1.0)
  20. ])
  21. def test_parse_accept_empty(self):
  22. self.assertEqual(parse_accept(""), [])
  23. def test_bestof(self):
  24. header = "text/html;q=1.0,text/plain;q=0.9,application/xml;q=0.5"
  25. x = bestof(header, 'text/plain', 'text/html')
  26. self.assertEqual(x, 'text/html')
  27. def test_bestof_list(self):
  28. header = "text/html;q=1.0,text/plain;q=0.9,application/xml;q=0.5"
  29. x = bestof(header, ['text/plain', 'text/html'])
  30. self.assertEqual(x, 'text/html')