Skip to content

Commit

Permalink
concept and conceptscheme visit log for csv #214
Browse files Browse the repository at this point in the history
  • Loading branch information
cahytinne committed Jul 28, 2015
1 parent 513ea92 commit da50cc7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
15 changes: 10 additions & 5 deletions atramhasis/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@


def _origin_from_request(request):
if 'text/html' in request.accept:
return 'HTML'
elif 'application/json' in request.accept:
return 'REST'
elif 'application/rdf+xml' in request.accept \
if request.url.endswith('.csv'):
return 'CSV'
elif request.url.endswith('.rdf') \
or 'application/rdf+xml' in request.accept \
or 'text/turtle' in request.accept \
or 'application/x-turtle' in request.accept:
return 'RDF'
elif 'text/html' in request.accept:
return 'HTML'
elif 'application/json' in request.accept:
return 'REST'
else:
return 'onbekend'

Expand All @@ -28,6 +31,8 @@ def _origin_from_response(response):
or response.content_type == 'text/turtle' \
or response.content_type == 'application/x-turtle':
return 'RDF'
elif response.content_type == 'text/csv':
return 'CSV'
else:
return 'onbekend'

Expand Down
1 change: 1 addition & 0 deletions atramhasis/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def set_locale_cookie(self):
max_age=31536000) # max_age = year
return response

@audit
@view_config(route_name='search_result_export', renderer='csv')
def results_csv(self):
header = ['conceptscheme', 'id', 'uri', 'type', 'label', 'prefLabels', 'altLabels', 'definition', 'broader',
Expand Down
16 changes: 16 additions & 0 deletions tests/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def _check(self, nr, origin, type_id_list):
self.assertEqual('1', getattr(self.audit_manager.saved_objects[nr-1], type_id))

def test_audit_rest(self):
self.dummy_parent.request.url = "http://host/conceptschemes/STYLES"
self.dummy_parent.request.accept = ['application/json']
self.dummy_parent.request.matchdict = {'scheme_id': '1'}
self.dummy_parent.dummy()
Expand All @@ -56,6 +57,7 @@ def test_audit_rest(self):
self._check(2, 'REST', ['conceptscheme_id', 'concept_id'])

def test_audit_html(self):
self.dummy_parent.request.url = "http://host/conceptschemes/STYLES"
self.dummy_parent.request.accept = ['text/html']
self.dummy_parent.request.matchdict = {'scheme_id': '1'}
self.dummy_parent.dummy()
Expand All @@ -65,6 +67,7 @@ def test_audit_html(self):
self._check(2, 'HTML', ['conceptscheme_id', 'concept_id'])

def test_audit_rdf_xml(self):
self.dummy_parent.request.url = "http://host/conceptschemes/STYLES.rdf"
self.dummy_parent.request.accept = ['application/rdf+xml']
self.dummy_parent.request.matchdict = {'scheme_id': '1'}
self.dummy_parent.dummy()
Expand All @@ -73,7 +76,18 @@ def test_audit_rdf_xml(self):
self.dummy_parent.dummy()
self._check(2, 'RDF', ['conceptscheme_id', 'concept_id'])

def test_audit_csv(self):
self.dummy_parent.request.url = "http://host/conceptschemes/STYLES.csv"
self.dummy_parent.request.accept = "text/csv"
self.dummy_parent.request.matchdict = {'scheme_id': '1'}
self.dummy_parent.dummy()
self._check(1, 'CSV', ['conceptscheme_id'])
self.dummy_parent.request.matchdict = {'scheme_id': '1', 'c_id': '1'}
self.dummy_parent.dummy()
self._check(2, 'CSV', ['conceptscheme_id', 'concept_id'])

def test_audit_other(self):
self.dummy_parent.request.url = "http://host/conceptschemes/STYLES"
self.dummy_parent.request.accept = ['application/octet-stream']
self.dummy_parent.request.matchdict = {'scheme_id': '1'}
self.dummy_parent.dummy()
Expand All @@ -89,6 +103,8 @@ def test_origin_from_response(self):
self.assertEqual('HTML', _origin_from_response(res))
res = Response(content_type='application/json')
self.assertEqual('REST', _origin_from_response(res))
res = Response(content_type='text/csv')
self.assertEqual('CSV', _origin_from_response(res))
res = Response(content_type='application/octet-stream')
self.assertEqual('onbekend', _origin_from_response(res))

0 comments on commit da50cc7

Please sign in to comment.