Skip to content

Commit 1e5c5d9

Browse files
committed
Merge pull request #25 from codebendercc/tests_fixes
Tests fixes
2 parents e5a5151 + 60b1aca commit 1e5c5d9

File tree

6 files changed

+95
-63
lines changed

6 files changed

+95
-63
lines changed

bin/seleniumbender

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ URL="https://codebender.cc"
6868
email_date=$(date +"%Y-%m-%d %H:%M:%S")
6969

7070
RETVAL=0
71-
NO_LOGS=0 # flag for tests that do not send any logs on their email
7271

7372
if [ "${target}" -eq 1 ]; then
7473
IDENTIFIER="test_target_libraries"
@@ -86,12 +85,10 @@ elif [ "${common}" -eq 1 ]; then
8685
IDENTIFIER="common"
8786
tox tests/common -- --url=${URL} --plugin
8887
RETVAL=$?
89-
NO_LOGS=1
9088
elif [ "${noplugin}" -eq 1 ]; then
9189
IDENTIFIER="noplugin"
9290
tox tests/noplugin -- --url=${URL}
9391
RETVAL=$?
94-
NO_LOGS=1
9592
elif [ "${walkthrough}" -eq 1 ]; then
9693
IDENTIFIER="walkthrough"
9794
RETVALS=()
@@ -117,25 +114,24 @@ elif [ "${walkthrough}" -eq 1 ]; then
117114
RETVAL=${i}
118115
fi
119116
done
120-
NO_LOGS=1
117+
121118
elif [ "${staging}" -eq 1 ]; then
122119
IDENTIFIER="cb_compile_tester_staging"
123120
URL="https://staging.codebender.cc"
124121
tox tests/compile_tester -- --url=${URL} -F --plugin
125-
# No need to send email for tests in staging
122+
# No need to send email for tests in staging.
126123
exit $?
127124
fi
128125

129-
# email notification without attaching any logs
126+
# Email notification without attaching any logs (options: common, noplugin, walkthrough).
130127
if [ ${RETVAL} -ne 0 ]; then
131128
mail -s "Selenium Tests: ${IDENTIFIER} Failed To Run" ${EMAIL} <<< "Something went wrong with ${IDENTIFIER} tests. Please check the logs."
132-
fi
133-
134-
if [ ${NO_LOGS} -eq 1 ]; then
129+
exit ${RETVAL}
130+
elif [ ${RETVAL} -eq 0 ]; then
135131
exit ${RETVAL}
136132
fi
137133

138-
# email notification with attaching the produced reports
134+
# Email notification attaching the produced logs/reports(options: target, examples, libraries, sketches).
139135
LOGS="${ROOTDIR}/logs"
140136
REPORTS="${ROOTDIR}/reports"
141137

codebender_testing/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ def create_webdriver(command_executor, desired_capabilities):
151151

152152
if browser_name == "chrome":
153153
desired_capabilities = DesiredCapabilities.CHROME.copy()
154-
options = chrome.options.Options()
155-
browser_profile_path = os.path.join('/tmp', _get_chrome_profile())
156-
options.add_argument('--user-data-dir=' + browser_profile_path)
157154
if desired_capabilities["version"] > CHROME_EXT_MAX_CHROME_VERSION:
158155
# Add the chrome app to capabilities.
156+
options = chrome.options.Options()
157+
browser_profile_path = os.path.join('/tmp', _get_chrome_profile())
158+
options.add_argument('--user-data-dir=' + browser_profile_path)
159159
options.add_extension(os.path.join(_EXTENSIONS_DIR, _CHROME_APP_FNAME))
160160
options.add_argument("--user-agent=" + TESTS_USER_AGENT_CHROME)
161161
else:

codebender_testing/disqus.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ def update_comment(self, sketch, results, current_date, log_entry, openFailFlag,
6363
`self.last_library`: The library in which belongs the previously compiled example.
6464
`library_to_comment`: The library in which a comment should be added.
6565
"""
66-
6766
library_match = re.match(r'.+\/example\/(.+)\/.+', sketch)
6867
library = None
6968
library_to_comment = None
7069

70+
# Set the library in which belongs the currently compiled example.
7171
if library_match:
7272
library = library_match.group(1)
7373

@@ -76,11 +76,10 @@ def update_comment(self, sketch, results, current_date, log_entry, openFailFlag,
7676
library_to_comment = library
7777

7878
#Check if we should add a comment to the library.
79-
if library_to_comment:
79+
if library_to_comment and library not in self.examples_without_library:
8080
log_entry = self.handle_library_comment(library_to_comment, current_date, log_entry)
8181

8282
self.last_library = library
83-
8483
#Add a comment to the currently compiled library example.
8584
if not openFailFlag:
8685
log_entry = self.handle_example_comment(sketch, results, current_date, log_entry)
@@ -90,25 +89,42 @@ def update_comment(self, sketch, results, current_date, log_entry, openFailFlag,
9089
def handle_library_comment(self, library, current_date, log):
9190
url = '/library/' + library
9291
identifier = 'ident:' + url
92+
9393
if url not in log:
9494
log[url] = {}
9595
try:
9696
log[url]['comment'] = False
97+
98+
""" Returns a Paginator object that matches the desired criteria:
99+
`self.disqus.api.threads.list`: Returns a list containg all urls in which Disqus loaded.
100+
`forum`: Looks up a forum by short name.
101+
`thread`: Looks up a thread by ID BUT you may pass us the 'ident' query type instead of
102+
an ID by including 'forum'. Filters results returned from `self.disqus.api.threads.list`
103+
and returns only those which match `forum` and `thread`.
104+
IMPORTANT: If `thread` is not found, all threads are returned!!!
105+
"""
97106
paginator = disqusapi.Paginator(self.disqus.api.threads.list,
98107
forum=FORUM,
99-
thread=identifier, method='GET')
108+
thread=identifier)
100109
if paginator:
101110
comment_updated = False
102111
new_message = self.messages['library'].replace('TEST_DATE', current_date)
103-
for page in paginator:
104-
post_id, existing_message = self.get_posts(page['id'])
112+
113+
for thread in paginator:
114+
115+
# Check if library has already a comment.
116+
post_id, existing_message = self.get_posts(thread['id'])
117+
118+
#If library already has a comment, update it.
105119
if post_id and existing_message:
106120
log[url]['comment'] = self.update_post(post_id, new_message)
107121
comment_updated = True
108122
break
109123

124+
#If library doesn't have a comment, create it.
110125
if not comment_updated:
111126
log[url]['comment'] = self.create_post(identifier, new_message)
127+
112128
except Exception as error:
113129
print 'Error:', error
114130
log[url]['comment'] = False
@@ -161,15 +177,21 @@ def get_posts(self, thread_id):
161177
post_id = None
162178
raw_message = None
163179
try:
180+
""" Returns a Paginator object that matches the desired criteria:
181+
`self.disqus.api.posts.list`: Returns a list of posts ordered by the date created.
182+
`forum`: Looks up a forum by short name.
183+
`thread`: Looks up a thread by ID. Filters results returned from `self.disqus.api.posts.list`
184+
and returns only those which match `forum` and `thread`.
185+
"""
164186
paginator = disqusapi.Paginator(self.disqus.api.posts.list,
165187
forum=FORUM,
166188
thread=thread_id,
167-
order='asc', method='GET')
189+
order='asc')
168190
if paginator:
169-
for result in paginator:
170-
if result['author']['name'] == self.user['username'] and result['author']['url'] == AUTHOR_URL:
171-
post_id = result['id']
172-
raw_message = result['raw_message']
191+
for post in paginator:
192+
if post['author']['name'] == self.user['username'] and post['author']['url'] == AUTHOR_URL:
193+
post_id = post['id']
194+
raw_message = post['raw_message']
173195
break
174196
except Exception as error:
175197
print 'Error:', error

codebender_testing/utils.py

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,17 @@ def read_last_log(compile_type):
123123
}
124124

125125

126-
# Creates a report json after each compile test
127126
def report_creator(compile_type, log_entry, log_file):
127+
"""Creates a report json after each compile.
128+
`logs`: a list in which all log files located in logs directory are added.
129+
`logs_to_examine`: the list of all log files located in logs directory sorted.
130+
`tail`: the two most recent logs in logs directory.
131+
`diff`: a dictionary where all differences between the two logs are stored.
132+
`changes`: a counter indicating the number of differences found between the two logs.
133+
"""
134+
128135
logs = os.listdir(get_path('logs'))
136+
129137
logs_re = re.compile(r'.+cb_compile_tester.+')
130138
if compile_type == 'library':
131139
logs_re = re.compile(r'.+libraries_test.+')
@@ -134,8 +142,10 @@ def report_creator(compile_type, log_entry, log_file):
134142
elif compile_type == 'target_library':
135143
logs_re = re.compile(r'.+target_libraries.+')
136144

137-
logs = sorted([x for x in logs if x != '.gitignore' and logs_re.match(x)])
145+
logs = sorted([x for x in logs if logs_re.match(x)])
138146
tail = logs[-2:]
147+
148+
# Opens the last, or the last two log files and gathers all their contents.
139149
logs_to_examine = []
140150
for log in tail:
141151
try:
@@ -146,68 +156,75 @@ def report_creator(compile_type, log_entry, log_file):
146156

147157
diff = {}
148158
changes = 0
159+
160+
# We have only one log file, it is the first time we run the test.
161+
if len(logs_to_examine) == 1:
162+
diff = logs_to_examine[0]
163+
changes += 1
164+
165+
# We have more than one log files, it is not the first time we run the test.
149166
if len(logs_to_examine) >= 2:
167+
150168
old_log = logs_to_examine[0]
151169
new_log = logs_to_examine[1]
152170

171+
#Iterate over all new_log keys (urls).
153172
for url in new_log.keys():
173+
174+
# Check if key (url) is included in `old_log`. If not, add an entry to `diff` dictionary.
154175
if url not in old_log:
155176
diff[url] = new_log[url]
156177
changes += 1
157178
continue
158179

180+
"""Check if log comes from test test_libraries_fetch.py test.
181+
If yes, we check if the `old_log[url]`value is the same with
182+
`new_log[url]`value. If not, add an entry to `diff` dictionary."""
159183
if compile_type == 'fetch':
160184
if old_log[url] != new_log[url]:
161185
diff[url] = new_log[url]
162186
changes += 1
163187
continue
164188

165-
for result in new_log[url].keys():
166-
if result not in old_log[url]:
167-
if not url in diff:
189+
"""Iterate over all `new_log[url]` keys. Keys can have one of the following
190+
values: 'success', 'fail', 'open_fail', 'error', 'comment'."""
191+
for result in new_log[url].keys():
192+
193+
"""Check if for the specific url, result is included in
194+
`old_log[url]` keys. If not, check if specific url has an entry in
195+
`diff` dictionary and if not create one. Then add the `result` value.
196+
e.g. `result`: success
197+
`old_log[url].keys()`: ['fail', 'success']"""
198+
199+
if result not in old_log[url].keys():
200+
if url not in diff:
168201
diff[url] = {}
169202
diff[url][result] = new_log[url][result]
170203
changes += 1
171204
continue
172205

173-
if result == 'success' or result == 'fail':
174-
if result not in old_log[url]:
175-
if not url in diff:
206+
# Check if for the specific url, the result is `comment` or `open_fail` or `error`.
207+
if result == 'comment' or result == 'open_fail' or result == 'error':
208+
# Check if the value for the specific result is the same in both logs.
209+
if old_log[url][result] != new_log[url][result]:
210+
# Check if the url is on diff dictionary, if not I add it.
211+
if url not in diff:
176212
diff[url] = {}
177213
diff[url][result] = new_log[url][result]
178214
changes += 1
179-
continue
180215

216+
# Check if for the specific url, the result is `success` or `fail`.
217+
elif result == 'success' or result == 'fail':
181218
for board in new_log[url][result]:
182-
oposite = 'success'
183-
if result == 'success':
184-
oposite = 'fail'
185-
if oposite in old_log[url] and board in old_log[url][oposite]:
186-
if not url in diff:
219+
if board not in old_log[url][result]:
220+
if url not in diff:
187221
diff[url] = {}
188222
if result not in diff[url]:
189223
diff[url][result] = []
190224
diff[url][result].append(board)
191225
changes += 1
192-
elif result == 'open_fail' or result == 'error' or result == 'comment':
193-
if result not in old_log[url]:
194-
if not url in diff:
195-
diff[url] = {}
196-
diff[url][result] = new_log[url][result]
197-
changes += 1
198-
continue
199-
if old_log[url][result] != new_log[url][result]:
200-
if not url in diff:
201-
diff[url] = {}
202-
diff[url][result] = new_log[url][result]
203-
changes += 1
204-
elif len(logs_to_examine) == 1:
205-
diff = logs_to_examine[0]
206-
changes += 1
207-
else:
208-
diff = log_entry
209-
changes += 1
210226

227+
#Create report and write the results.
211228
filename_tokens = os.path.basename(log_file).split('.')
212229
filename = '.'.join(filename_tokens[0:-1])
213230
extension = filename_tokens[-1]
@@ -696,7 +713,7 @@ def compile_sketches(self, sketches, iframe=False, project_view=False, logfile=N
696713
return
697714

698715
# Generate a report if requested.
699-
if compile_type != 'target_library' and create_report:
716+
if compile_type != 'target_library' and create_report and self.run_full_compile_tests:
700717
report_creator(compile_type, log_entry, log_file)
701718
print '\nTest duration:', int(toc - tic), 'sec'
702719

tests/common/how_it_works/test_how_it_works.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_how_it_works_page_7 (self):
106106
WebDriverWait(self.driver, TIMEOUT).until(
107107
expected_conditions.text_to_be_present_in_element(
108108
(By.CSS_SELECTOR,
109-
'.navbar .popover:nth-child(3) .popover-title'),
109+
'.navbar-inner .nav.pull-right .popover.fade.bottom.in .popover-title'),
110110
"That's all for now."
111111
)
112112
)

tests/target_libraries/test_target_libraries.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@
88

99
GET_ALL_LIBRARIES_SCRIPT = """
1010
var libraries = {};
11-
var humanNameRegExp = /^.+\((.+)\)$/;
1211
$('#mycontainer').find('.library-expand-handle').map(function () {
13-
var libraryName = $(this).text();
14-
if (humanNameRegExp.test(libraryName)) {
15-
libraryName = libraryName.match(humanNameRegExp)[1].trim().replace(/\.h/, '');
16-
}
12+
var libraryName = $(this).parents('.accordion-group').attr('data-name');
1713
libraries[libraryName] = $(this).parent().find('.library_link').attr('href');
1814
});
1915
return libraries;
@@ -38,6 +34,7 @@ def test_compile_target_libraries(self):
3834

3935
urls_to_follow = []
4036
for target in targets:
37+
target = target.lower()
4138
if target in libraries:
4239
library_url = libraries[target]
4340
self.open(library_url)

0 commit comments

Comments
 (0)