def test_no_functions_throw_exceptions(self): try: dshield.backscatter() dshield.handler() dshield.infocon() dshield.ip('8.8.8.8') dshield.port(80) dshield.portdate(80) dshield.topports() dshield.topips() dshield.sources() dshield.porthistory(80) dshield.asnum(1) dshield.dailysummary() dshield.daily404summary(datetime.date(2011, 12, 1)) dshield.daily404detail(datetime.date(2011, 12, 1)) dshield.glossary() dshield.webhoneypotsummary(datetime.date(2011, 12, 1)) dshield.webhoneypotbytype(datetime.date(2011, 12, 1)) except requests.RequestException: # don't care about network errors pass except Exception: # anything else is a fail self.assertTrue(False)
def test_porthistory(self): responses.add(responses.GET, 'https://dshield.org/api/porthistory/80/2011-07-20/2011-07-23?json', body='{"porthistory":"test"}', match_querystring=True, content_type='text/json') responses.add(responses.GET, 'https://dshield.org/api/porthistory/80/2011-07-20?json', body='{"porthistory":"test"}', match_querystring=True, content_type='text/json') responses.add(responses.GET, 'https://dshield.org/api/porthistory/80?json', body='{"porthistory":"test"}', match_querystring=True, content_type='text/json') responses.add(responses.GET, 'https://dshield.org/api/porthistory/80/{date}?json'.format(date=(datetime.datetime.now() - datetime.timedelta(days=30)).strftime("%Y-%m-%d")), body='{"porthistory":"test"}', match_querystring=True, content_type='text/json') responses.add(responses.GET, 'https://dshield.org/api/porthistory/badport/{date}?json'.format(date=(datetime.datetime.now() - datetime.timedelta(days=30)).strftime("%Y-%m-%d")), body='{"porthistory":{"error":"bad port number"}}', match_querystring=True, content_type='text/json') data = {'porthistory': 'test'} self.assertEquals(dshield.porthistory(80), data) self.assertEquals(dshield.porthistory('80'), data) self.assertEquals(dshield.porthistory(80, datetime.date(2011, 7, 20)), data) self.assertEquals(dshield.porthistory(80, '2011-07-20', datetime.date(2011, 7, 23)), data) self.assertEquals(dshield.porthistory(80, '2011-07-20', '2011-07-23'), data) self.assertEquals(dshield.porthistory(80, return_format=dshield.JSON), '{"porthistory":"test"}') self.assertRaises(dshield.Error, dshield.porthistory, 'badport')
def test_porthistory(self): responses.add( responses.GET, 'https://dshield.org/api/porthistory/80/2011-07-20/2011-07-23?json', body='{"porthistory":"test"}', match_querystring=True, content_type='text/json') responses.add(responses.GET, 'https://dshield.org/api/porthistory/80/2011-07-20?json', body='{"porthistory":"test"}', match_querystring=True, content_type='text/json') responses.add(responses.GET, 'https://dshield.org/api/porthistory/80?json', body='{"porthistory":"test"}', match_querystring=True, content_type='text/json') responses.add( responses.GET, 'https://dshield.org/api/porthistory/80/{date}?json'.format( date=(datetime.datetime.now() - datetime.timedelta(days=30)).strftime("%Y-%m-%d")), body='{"porthistory":"test"}', match_querystring=True, content_type='text/json') responses.add( responses.GET, 'https://dshield.org/api/porthistory/badport/{date}?json'.format( date=(datetime.datetime.now() - datetime.timedelta(days=30)).strftime("%Y-%m-%d")), body='{"porthistory":{"error":"bad port number"}}', match_querystring=True, content_type='text/json') data = {'porthistory': 'test'} self.assertEquals(dshield.porthistory(80), data) self.assertEquals(dshield.porthistory('80'), data) self.assertEquals(dshield.porthistory(80, datetime.date(2011, 7, 20)), data) self.assertEquals( dshield.porthistory(80, '2011-07-20', datetime.date(2011, 7, 23)), data) self.assertEquals(dshield.porthistory(80, '2011-07-20', '2011-07-23'), data) self.assertEquals(dshield.porthistory(80, return_format=dshield.JSON), '{"porthistory":"test"}') self.assertRaises(dshield.Error, dshield.porthistory, 'badport')