Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 0cfd687

Browse files
author
Konstantin Sivakov
authored
Merge pull request ckan#4441 from smotornyuk/streaming-response-test-clean-up
Update tests so that one could understand, what feature is tested
2 parents e5b54ba + 33836a3 commit 0cfd687

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

ckan/views/dataset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ def history(package_type, id):
10981098
revision_date = h.date_str_to_datetime(revision_dict[u'timestamp'])
10991099
try:
11001100
dayHorizon = int(request.args.get(u'days'))
1101-
except:
1101+
except Exception:
11021102
dayHorizon = 30
11031103
dayAge = (datetime.datetime.now() - revision_date).days
11041104
if dayAge >= dayHorizon:

ckanext/example_flask_streaming/tests/test_streaming_responses.py

+24-19
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
import os.path as path
44

5-
from nose.tools import eq_, assert_raises
5+
from nose.tools import eq_, assert_raises, ok_
66
from webtest.app import TestRequest
77
from webtest import lint # NOQA
88
import ckan.plugins as plugins
99
import ckan.tests.helpers as helpers
1010

1111

1212
class TestFlaskStreaming(helpers.FunctionalTestBase):
13-
1413
def _get_resp(self, url):
1514
req = TestRequest.blank(url)
1615
app = lint.middleware(self.app.app)
@@ -25,46 +24,52 @@ def setup(self):
2524
plugins.load(u'example_flask_streaming')
2625
plugin = plugins.get_plugin(u'example_flask_streaming')
2726
self.app.flask_app.register_extension_blueprint(
28-
plugin.get_blueprint())
27+
plugin.get_blueprint()
28+
)
2929

3030
def test_accordance_of_chunks(self):
31-
u'''Test extension sets up a unique route.'''
32-
url = str(u'/stream/string')
31+
u'''Test streaming of items collection.'''
32+
url = str(u'/stream/string') # produces list of words
3333
resp = self._get_resp(url)
3434
eq_(
3535
u'Hello World, this is served from an extension'.split(),
36-
list(resp.app_iter))
36+
list(resp.app_iter)
37+
)
3738
resp.app_iter.close()
3839

3940
def test_template_streaming(self):
40-
u'''Test extension sets up a unique route.'''
41-
url = str(u'/stream/template')
42-
resp = self._get_resp(url)
43-
eq_(1, len(list(resp.app_iter)))
44-
45-
url = str(u'/stream/template/7')
41+
u'''Test streaming of template response.'''
42+
bound = 7
43+
url = str(u'/stream/template/{}'.format(bound)) # produces nums list
4644
resp = self._get_resp(url)
47-
eq_(2, len(list(resp.app_iter)))
45+
content = u''.join(resp.app_iter)
46+
for i in range(bound):
47+
ok_(str(i) in content)
4848
resp._app_iter.close()
4949

5050
def test_file_streaming(self):
51-
u'''Test extension sets up a unique route.'''
52-
url = str(u'/stream/file')
51+
u'''Test streaming of existing file(10lines.txt).'''
52+
url = str(u'/stream/file') # streams file
5353
resp = self._get_resp(url)
54-
f_path = path.join(path.dirname(path.abspath(__file__)), u'10lines.txt')
54+
f_path = path.join(
55+
path.dirname(path.abspath(__file__)), u'10lines.txt'
56+
)
5557
with open(f_path) as test_file:
5658
content = test_file.readlines()
5759
eq_(content, list(resp.app_iter))
5860
resp._app_iter.close()
5961

6062
def test_render_with_context(self):
61-
u'''Test extension sets up a unique route.'''
62-
url = str(u'/stream/context?var=10')
63+
u'''Test availability of context inside templates.'''
64+
url = str(u'/stream/context?var=10') # produces `var` value
6365
resp = self._get_resp(url)
6466
eq_(u'10', resp.body)
6567

6668
def test_render_without_context(self):
67-
u'''Test extension sets up a unique route.'''
69+
u'''
70+
Test that error raised if there is an
71+
attempt to pick variable if context is not provider.
72+
'''
6873
url = str(u'/stream/without_context?var=10')
6974
resp = self._get_resp(url)
7075
assert_raises(AttributeError, u''.join, resp.app_iter)

0 commit comments

Comments
 (0)