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:
parent
61cd2beef8
commit
ce79ffe566
@ -40,7 +40,7 @@ class User(db.Model):
|
||||
def __init__(self, api_key, auto_init=True):
|
||||
self.api_key = api_key
|
||||
self.last_updated = datetime.min
|
||||
if auto_init:
|
||||
if auto_init: # pragma: no cover
|
||||
self.last_updated = datetime.utcnow()
|
||||
self.parse_radicals_and_userdata()
|
||||
self.parse_kanji()
|
||||
@ -60,7 +60,7 @@ class User(db.Model):
|
||||
def get_id(self):
|
||||
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.raise_for_status()
|
||||
data = response.json()
|
||||
@ -71,7 +71,7 @@ class User(db.Model):
|
||||
if data.get('requested_information'):
|
||||
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.raise_for_status()
|
||||
data = response.json()
|
||||
@ -80,7 +80,7 @@ class User(db.Model):
|
||||
if data.get('requested_information'):
|
||||
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.raise_for_status()
|
||||
data = response.json()
|
||||
@ -89,7 +89,7 @@ class User(db.Model):
|
||||
if data.get('requested_information'):
|
||||
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):
|
||||
self.parse_radicals_and_userdata()
|
||||
self.parse_kanji()
|
||||
@ -164,7 +164,7 @@ def show_home():
|
||||
if user:
|
||||
login_user(user, remember=True)
|
||||
return flask.redirect(flask.url_for('show_quiz'))
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
try:
|
||||
new_user = User(str(form.api_key.data))
|
||||
login_user(new_user, remember=True)
|
||||
@ -205,7 +205,7 @@ def get_items():
|
||||
|
||||
@app.route('/refresh', methods=['POST'])
|
||||
@login_required
|
||||
def refresh_api():
|
||||
def refresh_api(): # pragma: no cover
|
||||
try:
|
||||
current_user.update_all()
|
||||
return str(datetime_format(current_user.last_updated)), 202
|
||||
|
Loading…
Reference in New Issue
Block a user