Skip to content

Commit 296fe10

Browse files
Konstantinaccfreskoulix
authored andcommitted
Added test that uploads sketches and compiles them after.
We upload sketches from test_data/cb_compile_tester/ into demo_user at staging, we compile them and delete them at the end. TODO: Find a way to detect a failed upload, in order for the test not to hang when an upload fails.
1 parent 7f56bf2 commit 296fe10

File tree

4 files changed

+55
-10
lines changed

4 files changed

+55
-10
lines changed

codebender_testing/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def jsondump(data):
2424
BASE_URL = "http://localhost"
2525
# URL of the actual Codebender website
2626
LIVE_SITE_URL = "https://codebender.cc"
27+
STAGING_SITE_URL = "https://staging.codebender.cc"
2728

2829
# Names of sources (i.e. repositories) used to generate the codebender site.
2930
SOURCE_BACHELOR = 'bachelor'
@@ -32,6 +33,7 @@ def jsondump(data):
3233
# User whose projects we'd like to compile in our compile_tester
3334
# test case(s).
3435
COMPILE_TESTER_URL = "/user/cb_compile_tester"
36+
COMPILE_TESTER_STAGING_URL = "/user/demo_user"
3537

3638
# The prefix for all filenames of log files.
3739
# Note that it is given as a time format string, which will

codebender_testing/utils.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ def _move_file_to_dropzone_script(dropzone_selector):
7575
VERIFICATION_SUCCESSFUL_MESSAGE = "Verification Successful"
7676
VERIFICATION_FAILED_MESSAGE = "Verification failed."
7777

78+
VERIFICATION_SUCCESSFUL_MESSAGE_EDITOR = 'Verification successful!'
79+
VERIFICATION_FAILED_MESSAGE_EDITOR = 'Verification failed!'
80+
7881
# Max test runtime into saucelabs
7982
# 2.5 hours (3 hours max)
8083
SAUCELABS_TIMEOUT_SECONDS = 10800 - 1800
@@ -460,7 +463,7 @@ def open_all_libraries_and_examples(self, url, logfile):
460463

461464
report_creator('fetch', log_entry, log_file)
462465

463-
def compile_sketch(self, url, boards, iframe=False):
466+
def compile_sketch(self, url, boards, iframe=False, project_view=False):
464467
"""Compiles the sketch located at `url`, or an iframe within the page
465468
referred to by `url`. Raises an exception if it does not compile.
466469
"""
@@ -481,6 +484,11 @@ def compile_sketch(self, url, boards, iframe=False):
481484
result = {
482485
'board': board
483486
}
487+
verification_success_message = VERIFICATION_SUCCESSFUL_MESSAGE_EDITOR
488+
verification_failed_message = VERIFICATION_FAILED_MESSAGE_EDITOR
489+
if project_view or iframe:
490+
verification_success_message = VERIFICATION_SUCCESSFUL_MESSAGE
491+
verification_failed_message = VERIFICATION_FAILED_MESSAGE
484492
try:
485493
self.execute_script(SELECT_BOARD_SCRIPT(board), '$', 'compilerflasher.pluginHandler.plugin_found')
486494
self.execute_script(_VERIFY_SCRIPT, 'compilerflasher')
@@ -490,15 +498,14 @@ def compile_sketch(self, url, boards, iframe=False):
490498
compile_result = WebDriverWait(self.driver, VERIFY_TIMEOUT).until(
491499
any_text_to_be_present_in_element(
492500
(By.CSS_SELECTOR, "[id$=operation_output]"),
493-
VERIFICATION_SUCCESSFUL_MESSAGE, VERIFICATION_FAILED_MESSAGE
501+
verification_success_message, verification_failed_message
494502
)
495503
)
496504
except WebDriverException as error:
497505
compile_result = "%s; %s" % (type(error).__name__, str(error))
498506
result['status'] = 'error'
499507
result['message'] = compile_result
500-
501-
if compile_result == VERIFICATION_SUCCESSFUL_MESSAGE:
508+
if compile_result == verification_success_message:
502509
result['status'] = 'success'
503510
else:
504511
result['status'] = 'fail'
@@ -521,7 +528,7 @@ def compile_all_sketches(self, url, selector, **kwargs):
521528
assert len(sketches) > 0
522529
self.compile_sketches(sketches, **kwargs)
523530

524-
def compile_sketches(self, sketches, iframe=False, logfile=None, compile_type='sketch', create_report=False, comment=False):
531+
def compile_sketches(self, sketches, iframe=False, project_view=False, logfile=None, compile_type='sketch', create_report=False, comment=False):
525532
"""Compiles the sketches with URLs given by the `sketches` list.
526533
`logfile` specifies a path to a file to which test results will be
527534
logged. If it is not `None`, compile errors will not cause the test
@@ -577,7 +584,7 @@ def compile_sketches(self, sketches, iframe=False, logfile=None, compile_type='s
577584

578585
if len(boards) > 0:
579586
# Run Verify
580-
results = self.compile_sketch(sketch, boards, iframe=iframe)
587+
results = self.compile_sketch(sketch, boards, iframe=iframe, project_view=project_view)
581588
else:
582589
results = [
583590
{

tests/compile_tester/test_compile_tester_projects.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
from codebender_testing.config import COMPILE_TESTER_LOGFILE
33
from codebender_testing.config import COMPILE_TESTER_URL
44
from codebender_testing.config import LIVE_SITE_URL
5+
from codebender_testing.config import STAGING_SITE_URL
6+
from codebender_testing.config import COMPILE_TESTER_STAGING_URL
57
from codebender_testing.config import SOURCE_BACHELOR
8+
from codebender_testing.config import TIMEOUT
9+
from selenium.webdriver.common.by import By
610
from codebender_testing.utils import SeleniumTestCase
711
import os
812
import pytest
13+
import time
914

1015

1116
class TestCompileTester(SeleniumTestCase):
@@ -16,5 +21,34 @@ class TestCompileTester(SeleniumTestCase):
1621
def test_compile_all_user_projects(self):
1722
"""Tests that all user's sketches compile successfully."""
1823
self.compile_all_sketches(COMPILE_TESTER_URL, '#user_projects tbody a',
19-
iframe=True, logfile=COMPILE_TESTER_LOGFILE,
20-
compile_type='sketch', create_report=True)
24+
compile_type='sketch',
25+
iframe=True, project_view=True,
26+
create_report=True, logfile=COMPILE_TESTER_LOGFILE)
27+
28+
# Here we upload, compile and delete all sketches included in
29+
# test_data/cb_compile_tester folder using demo_user on staging site.
30+
@pytest.mark.requires_url(STAGING_SITE_URL)
31+
def test_compile_local_files(self, tester_login):
32+
"""Tests that we can upload all of cb_compile_tester's projects
33+
(stored locally in test_data/cb_compile_tester), compile them,
34+
and finally delete them."""
35+
filenames = next(os.walk(COMPILE_TESTER_DIR))[2]
36+
test_files = [os.path.join(COMPILE_TESTER_DIR, name) for name
37+
in next(os.walk(COMPILE_TESTER_DIR))[2]]
38+
projects = [self.upload_project('#uploadFolderZip form', fname,
39+
os.path.splitext(os.path.basename(fname))[0]) for fname
40+
in test_files]
41+
flag = True
42+
while flag:
43+
uploaded_sketches = self.get_elements(By.CSS_SELECTOR, '#project_list > li')
44+
if len(uploaded_sketches) >= len(projects):
45+
flag = False
46+
break
47+
time.sleep(1)
48+
self.compile_all_sketches(COMPILE_TESTER_STAGING_URL,
49+
'#user_projects tbody a',
50+
iframe=False,
51+
compile_type='sketch',
52+
create_report=True, logfile=COMPILE_TESTER_LOGFILE)
53+
for name in projects:
54+
self.delete_project(name.replace(" ", "-"))

tests/libraries/test_libraries.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ class TestLibraryExamples(SeleniumTestCase):
77
def test_compile_all_libraries(self):
88
"""Tests that all library examples compile successfully."""
99
self.compile_all_sketches('/libraries', '.accordion li a',
10-
logfile=LIBRARIES_TEST_LOGFILE,
11-
compile_type='library', create_report=True, comment=True)
10+
compile_type='library',
11+
iframe=False, project_view=True,
12+
create_report=True, logfile=LIBRARIES_TEST_LOGFILE,
13+
comment=True)

0 commit comments

Comments
 (0)