Added coverage.py pragma comments to mark code that will not be covered by unit tests due to external api dependencies.

This commit is contained in:
neviyn 2016-01-26 02:56:44 +00:00
parent 61cd2beef8
commit ce79ffe566

View File

@ -40,7 +40,7 @@ class User(db.Model):
def __init__(self, api_key, auto_init=True): def __init__(self, api_key, auto_init=True):
self.api_key = api_key self.api_key = api_key
self.last_updated = datetime.min self.last_updated = datetime.min
if auto_init: if auto_init: # pragma: no cover
self.last_updated = datetime.utcnow() self.last_updated = datetime.utcnow()
self.parse_radicals_and_userdata() self.parse_radicals_and_userdata()
self.parse_kanji() self.parse_kanji()
@ -60,7 +60,7 @@ class User(db.Model):
def get_id(self): def get_id(self):
return str(self.api_key) return str(self.api_key)
def parse_radicals_and_userdata(self): def parse_radicals_and_userdata(self): # pragma: no cover
response = requests.get("https://www.wanikani.com/api/user/" + self.api_key + "/radicals/") response = requests.get("https://www.wanikani.com/api/user/" + self.api_key + "/radicals/")
response.raise_for_status() response.raise_for_status()
data = response.json() data = response.json()
@ -71,7 +71,7 @@ class User(db.Model):
if data.get('requested_information'): if data.get('requested_information'):
self.radicals = json.dumps(data['requested_information'], ensure_ascii=False) self.radicals = json.dumps(data['requested_information'], ensure_ascii=False)
def parse_kanji(self): def parse_kanji(self): # pragma: no cover
response = requests.get("https://www.wanikani.com/api/user/" + self.api_key + "/kanji/") response = requests.get("https://www.wanikani.com/api/user/" + self.api_key + "/kanji/")
response.raise_for_status() response.raise_for_status()
data = response.json() data = response.json()
@ -80,7 +80,7 @@ class User(db.Model):
if data.get('requested_information'): if data.get('requested_information'):
self.kanji = json.dumps(data['requested_information'], ensure_ascii=False) self.kanji = json.dumps(data['requested_information'], ensure_ascii=False)
def parse_vocabulary(self): def parse_vocabulary(self): # pragma: no cover
response = requests.get("https://www.wanikani.com/api/user/" + self.api_key + "/vocabulary/") response = requests.get("https://www.wanikani.com/api/user/" + self.api_key + "/vocabulary/")
response.raise_for_status() response.raise_for_status()
data = response.json() data = response.json()
@ -89,7 +89,7 @@ class User(db.Model):
if data.get('requested_information'): if data.get('requested_information'):
self.vocabulary = json.dumps(data['requested_information']['general'], ensure_ascii=False) self.vocabulary = json.dumps(data['requested_information']['general'], ensure_ascii=False)
def update_all(self): def update_all(self): # pragma: no cover
if (datetime.utcnow() - self.last_updated) > timedelta(hours=1): if (datetime.utcnow() - self.last_updated) > timedelta(hours=1):
self.parse_radicals_and_userdata() self.parse_radicals_and_userdata()
self.parse_kanji() self.parse_kanji()
@ -164,7 +164,7 @@ def show_home():
if user: if user:
login_user(user, remember=True) login_user(user, remember=True)
return flask.redirect(flask.url_for('show_quiz')) return flask.redirect(flask.url_for('show_quiz'))
else: else: # pragma: no cover
try: try:
new_user = User(str(form.api_key.data)) new_user = User(str(form.api_key.data))
login_user(new_user, remember=True) login_user(new_user, remember=True)
@ -205,7 +205,7 @@ def get_items():
@app.route('/refresh', methods=['POST']) @app.route('/refresh', methods=['POST'])
@login_required @login_required
def refresh_api(): def refresh_api(): # pragma: no cover
try: try:
current_user.update_all() current_user.update_all()
return str(datetime_format(current_user.last_updated)), 202 return str(datetime_format(current_user.last_updated)), 202