Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nbp/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def download(url):
try:
resp = urllib2.urlopen(url)
if hasattr(resp, 'getcode') and resp.getcode() == 200:
return resp
if hasattr(resp, 'info') and resp.info()['content-type'] == 'text/xml':
return resp
return None
except urllib2.URLError, e:
resp = None
return resp
Expand Down
16 changes: 16 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import nbp
from datetime import date
from nose.tools import assert_equals


Expand All @@ -18,3 +19,18 @@ def test_downloads_exchange_rate_properly():
}
currency_data = nbp.download_exchange_rate(nbp.date(2010, 7, 11), 'EUR')
assert_equals(expexted, currency_data)

def test_downloads_exchange_rate_properly_even_with_broken_nbp_404_200():
expexted = {
'search_date': '2014-11-03',
'table_no': u'213/A/NBP/2014',
'pub_date': u'2014-11-03',
'url': 'http://rss.nbp.pl/kursy/xml2/2014/a/14a213.xml',
'currency': {
'name': u'euro',
'rate': 4.2209,
'code': u'EUR',
},
}
currency_data = nbp.download_exchange_rate(date.today(), 'EUR')
assert_equals(date.today().strftime('%Y-%m-%d'), currency_data['pub_date'])