Skip to content

Commit f5adadd

Browse files
committed
Moved into try-except block all the Disqus API related code.
If the Disqus API rate limit is reached, failure to update the Disqus comment is logged and the tests continue.
1 parent a0cb0ae commit f5adadd

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

codebender_testing/disqus.py

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,46 +77,54 @@ def update_comment(self, sketch, results, current_date, log_entry, openFailFlag,
7777
def handle_library_comment(self, library, current_date, log):
7878
url = '/library/' + library
7979
identifier = 'ident:' + url
80-
paginator = disqusapi.Paginator(self.disqus.api.threads.list, forum=FORUM, thread=identifier, method='GET')
81-
if paginator:
82-
for page in paginator:
83-
post_id, existing_message = self.get_posts(page['id'])
84-
if post_id and existing_message:
85-
new_message = self.messages['library'].replace('TEST_DATE', current_date)
86-
if url not in log:
87-
log[url] = {}
88-
log[url]['comment'] = self.update_post(post_id, new_message)
89-
else:
80+
try:
81+
paginator = disqusapi.Paginator(self.disqus.api.threads.list, forum=FORUM, thread=identifier, method='GET')
82+
if paginator:
83+
for page in paginator:
84+
post_id, existing_message = self.get_posts(page['id'])
85+
if post_id and existing_message:
86+
new_message = self.messages['library'].replace('TEST_DATE', current_date)
87+
if url not in log:
88+
log[url] = {}
89+
log[url]['comment'] = self.update_post(post_id, new_message)
90+
else:
91+
log[url]['comment'] = False
92+
except Exception as error:
93+
print 'Error:', error
9094
log[url]['comment'] = False
9195
return log
9296

9397
def handle_example_comment(self, url, results, current_date, log):
9498
identifier = url.replace('https://codebender.cc', '')
9599
identifier = 'ident:' + identifier
96-
paginator = disqusapi.Paginator(self.disqus.api.threads.list, forum=FORUM, thread=identifier, method='GET')
97-
if paginator:
98-
for page in paginator:
99-
post_id, existing_message = self.get_posts(page['id'])
100-
if post_id and existing_message:
101-
boards = []
102-
unsupportedFlag = False
103-
for result in results:
104-
if result['status'] == 'success':
105-
board = result['board']
106-
if re.match(r'Arduino Mega.+', board):
107-
board = 'Arduino Mega'
108-
boards.append(board)
109-
elif result['status'] == 'unsupported':
110-
unsupportedFlag = True
111-
112-
new_message = self.messages['example_fail'].replace('TEST_DATE', current_date)
113-
if len(boards) > 0:
114-
new_message = self.messages['example_success'].replace('TEST_DATE', current_date).replace('BOARDS_LIST', ', '.join(boards))
115-
elif unsupportedFlag:
116-
new_message = self.messages['example_unsupported'].replace('TEST_DATE', current_date)
117-
log[url]['comment'] = self.update_post(post_id, new_message)
118-
break
119-
else:
100+
try:
101+
paginator = disqusapi.Paginator(self.disqus.api.threads.list, forum=FORUM, thread=identifier, method='GET')
102+
if paginator:
103+
for page in paginator:
104+
post_id, existing_message = self.get_posts(page['id'])
105+
if post_id and existing_message:
106+
boards = []
107+
unsupportedFlag = False
108+
for result in results:
109+
if result['status'] == 'success':
110+
board = result['board']
111+
if re.match(r'Arduino Mega.+', board):
112+
board = 'Arduino Mega'
113+
boards.append(board)
114+
elif result['status'] == 'unsupported':
115+
unsupportedFlag = True
116+
117+
new_message = self.messages['example_fail'].replace('TEST_DATE', current_date)
118+
if len(boards) > 0:
119+
new_message = self.messages['example_success'].replace('TEST_DATE', current_date).replace('BOARDS_LIST', ', '.join(boards))
120+
elif unsupportedFlag:
121+
new_message = self.messages['example_unsupported'].replace('TEST_DATE', current_date)
122+
log[url]['comment'] = self.update_post(post_id, new_message)
123+
break
124+
else:
125+
log[url]['comment'] = False
126+
except Exception as error:
127+
print 'Error:', error
120128
log[url]['comment'] = False
121129
return log
122130

0 commit comments

Comments
 (0)