-
Notifications
You must be signed in to change notification settings - Fork 2k
/
test_autoneg.py
76 lines (65 loc) · 3.17 KB
/
test_autoneg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import cgi
from paste.fixture import AppError
from pylons import config
from pylons import c
from genshi.core import escape as genshi_escape
from difflib import unified_diff
from nose.plugins.skip import SkipTest
from ckan.tests import *
from ckan.tests.html_check import HtmlCheckMethods
from ckan.tests.pylons_controller import PylonsTestCase
from ckan.lib.create_test_data import CreateTestData
from ckan import model
from test_package import TestPackageForm as _TestPackageForm
class TestAutoneg(_TestPackageForm, PylonsTestCase):
@classmethod
def setup_class(cls):
PylonsTestCase.setup_class()
CreateTestData.create()
@classmethod
def teardown_class(cls):
model.repo.rebuild_db()
def test_default(self):
url = url_for(controller='package', action='read', id='annakarenina')
response = self.app.get(url)
assert response.status == 200, response.status
content_type = response.header("Content-Type")
assert "html" in content_type, content_type
def test_chrome(self):
url = url_for(controller='package', action='read', id='annakarenina')
## this is what chrome sends... notice how it prefers pictures of web pages
## to web pages
accept = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
response = self.app.get(url, headers={"Accept": accept})
assert response.status == 200, response.status
content_type = response.header("Content-Type")
assert "html" in content_type, content_type
def test_firefox(self):
url = url_for(controller='package', action='read', id='annakarenina')
## this is what firefox sends
accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
response = self.app.get(url, headers={"Accept": accept})
assert response.status == 200, response.status
content_type = response.header("Content-Type")
assert "html" in content_type, content_type
def test_html_rdf(self):
url = url_for(controller='package', action='read', id='annakarenina')
## this is an important test. rdf appears first, but with a lower priority
## than html. we expect to get html back
accept = "application/rdf+xml;q=0.5,application/xhtml+xml,text/html;q=0.9"
response = self.app.get(url, headers={"Accept": accept})
assert response.status == 200, response.status
content_type = response.header("Content-Type")
assert "html" in content_type, content_type
def test_rdfxml(self):
url = url_for(controller='package', action='read', id='annakarenina')
response = self.app.get(url, headers={"Accept": "application/rdf+xml"})
assert response.status == 200, response.status
ctype = response.header("Content-Type")
assert 'application/rdf+xml' in ctype, ctype
def test_n3(self):
url = url_for(controller='package', action='read', id='annakarenina')
response = self.app.get(url, headers={"Accept": "text/n3"})
assert response.status == 200, response.status
ctype = response.header("Content-Type")
assert 'text/n3' in ctype, ctype