Skip to content

Commit 0cbbc75

Browse files
author
konstantina
committed
Fixed issue: Disqus comment is not created when library has no examples.
Modified test_libraries.py in order to test that all library examples compile successfully and that Disqus comments are created on library url pages and on examples.
1 parent ed135b4 commit 0cbbc75

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

tests/libraries/test_libraries.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,47 @@
11
from codebender_testing.config import LIBRARIES_TEST_LOGFILE
22
from codebender_testing.utils import SeleniumTestCase
33

4+
GET_SKETCHES_SCRIPT = "return $('{selector}').map(function() {{ return this.href; }}).toArray();"
45

6+
GET_ALL_LIBRARIES_EXAMPLES_URLS_SCRIPT = """
7+
var librariesMap = {};
8+
var machineNameFilter = /.+\(\s(.+)\.h\s\)/;
9+
var accordionHeadings = $('#mycontainer').find('.accordion-heading');
10+
$.each(accordionHeadings, function (key, value) {{
11+
var libraryName = $(value).text().trim();
12+
if (machineNameFilter.test(libraryName)) {{
13+
libraryName = libraryName.match(machineNameFilter)[1].trim();
14+
}}
15+
if (!librariesMap.hasOwnProperty(libraryName)) {{
16+
librariesMap[libraryName] = [];
17+
}}
18+
19+
var examples = $(value).parent().find('.accordion-body').find('li a');
20+
21+
$.each(examples, function (k, v) {{
22+
var href = $(v).attr('href');
23+
librariesMap[libraryName].push(href);
24+
}});
25+
}});
26+
console.log(librariesMap);
27+
return librariesMap;
28+
"""
529
class TestLibraryExamples(SeleniumTestCase):
630

731
def test_compile_all_libraries(self):
8-
"""Tests that all library examples compile successfully."""
9-
self.compile_all_sketches('/libraries', '.accordion li a',
10-
compile_type='library',
11-
iframe=False, project_view=True,
12-
create_report=True, logfile=LIBRARIES_TEST_LOGFILE,
13-
comment=True)
32+
url = '/libraries'
33+
self.open(url)
34+
35+
examples = self.execute_script(GET_SKETCHES_SCRIPT.format(selector='.accordion li a'), '$')
36+
assert len(examples) > 0
37+
libraries = self.execute_script(GET_SKETCHES_SCRIPT.format(selector='.library_link'), '$')
38+
assert len(libraries) > 0
39+
examples_libraries = examples + libraries
40+
41+
"""Tests that all library examples compile successfully and comments on library url page and on its examples."""
42+
library_examples_urls = self.execute_script(GET_ALL_LIBRARIES_EXAMPLES_URLS_SCRIPT, '$')
43+
44+
self.comment_compile_libraries_examples(examples_libraries, library_examples_urls,
45+
compile_type='library', iframe=False,
46+
project_view=True, create_report=True,
47+
logfile=LIBRARIES_TEST_LOGFILE, comment=True)

0 commit comments

Comments
 (0)