Skip to content

Commit

Permalink
Added test, code and docs for the glossary function.
Browse files Browse the repository at this point in the history
  • Loading branch information
rshipp committed Jul 5, 2014
1 parent acb6a00 commit 88d0a3b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ from the official API documentation_.
.. autofunction:: dshield.dailysummary
.. autofunction:: dshield.daily404summary
.. autofunction:: dshield.daily404detail
.. autofunction:: dshield.glossary


Exceptions
Expand Down
10 changes: 10 additions & 0 deletions dshield.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,13 @@ def daily404detail(date, limit=None, return_format=None):
if limit:
uri = '/'.join([uri, str(limit)])
return _get(uri, return_format)

def glossary(term=None, return_format=None):
"""List of glossary terms and definitions
:param term: a whole or parital word to "search" in the API
"""
uri = 'glossary'
if term:
uri = '/'.join([uri, term])
return _get(uri, return_format)
16 changes: 16 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,19 @@ def test_daily404detail(self):
self.assertEquals(dshield.daily404detail('2012-02-23', '10'), data)
self.assertEquals(dshield.daily404detail('2012-02-23', return_format=dshield.JSON),
'{"daily404detail":"test"}')

@responses.activate
def test_glossary(self):
responses.add(responses.GET,
'https://dshield.org/api/glossary?json',
body='{"glossary":"test"}',
match_querystring=True, content_type='text/json')
responses.add(responses.GET,
'https://dshield.org/api/glossary/test?json',
body='{"glossary":"test"}',
match_querystring=True, content_type='text/json')
data = {'glossary': 'test'}
self.assertEquals(dshield.glossary(), data)
self.assertEquals(dshield.glossary('test'), data)
self.assertEquals(dshield.glossary(return_format=dshield.JSON),
'{"glossary":"test"}')

0 comments on commit 88d0a3b

Please sign in to comment.