Skip to content

Commit

Permalink
[#3196] Add some tests for common context object
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Aug 12, 2016
1 parent 9f1d70b commit c5cbcca
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion ckan/tests/test_common.py
Expand Up @@ -7,7 +7,7 @@

from ckan.tests import helpers
from ckan.common import (CKANConfig, config as ckan_config,
request as ckan_request)
request as ckan_request, g as ckan_g, c as ckan_c)


class TestConfigObject(object):
Expand Down Expand Up @@ -233,3 +233,40 @@ def test_other_missing_attributes_raise_attributeerror_exceptions(self):
with app.flask_app.test_request_context(u'/hello?a=1'):

assert_raises(AttributeError, getattr, ckan_request, u'not_here')


class TestCommonG(object):

def test_flask_g_is_used_on_a_flask_request(self):

app = helpers._get_test_app()

with app.flask_app.test_request_context():

assert u'flask.g' in unicode(ckan_g)

flask.g.user = u'example'

eq_(ckan_g.user, u'example')

def test_can_also_use_c_on_a_flask_request(self):

app = helpers._get_test_app()

with app.flask_app.test_request_context():

flask.g.user = u'example'

eq_(ckan_c.user, u'example')

ckan_g.user = u'example2'

eq_(ckan_c.user, u'example2')

def test_accessing_missing_key_raises_error_on_flask_request(self):

app = helpers._get_test_app()

with app.flask_app.test_request_context():

assert_raises(AttributeError, getattr, ckan_g, u'user')

0 comments on commit c5cbcca

Please sign in to comment.