From 34b5aacb5dc9c5de2c678860a329febe8feea584 Mon Sep 17 00:00:00 2001 From: Sanford Student Date: Fri, 10 Mar 2017 15:03:00 -0500 Subject: [PATCH] upgrade xblock --- .gitignore | 1 + .travis.yml | 7 +++++++ requirements/base.txt | 7 +------ sample_xblocks/filethumbs/filethumbs.py | 14 +++++++------- workbench/test/selenium_test.py | 13 +++++++++++++ workbench/test/test_filethumbs.py | 1 + workbench/test/test_thumbs.py | 3 +++ 7 files changed, 33 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 7c50b5e9..fa3574ea 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ local_settings.py .treerc .coverage htmlcov +geckodriver.log *.DS_Store workbench/static/djpyfs/ diff --git a/.travis.yml b/.travis.yml index 4437b826..6a8ae3b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ sudo: false language: python +addons: + firefox: "52.0esr" + python: - "2.7" @@ -15,6 +18,10 @@ cache: before_install: - "export DISPLAY=:99" - "sh -e /etc/init.d/xvfb start" + - "wget https://github.com/mozilla/geckodriver/releases/download/v0.15.0/geckodriver-v0.15.0-linux64.tar.gz" + - "mkdir geckodriver" + - "tar -xzf geckodriver-v0.15.0-linux64.tar.gz -C geckodriver" + - "export PATH=$PATH:$PWD/geckodriver" install: - "make install" diff --git a/requirements/base.txt b/requirements/base.txt index 04dc3a14..6a85db32 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -5,12 +5,7 @@ requests webob simplejson lazy - -# XBlock -# This is not in/from PyPi, since it moves fast --e git+https://github.com/edx/XBlock.git@xblock-0.4.7#egg=XBlock==0.4.7 -#-e ../XBlock - +XBlock>=0.5.0 fs pypng -e git+https://github.com/edx/django-pyfs.git@1.0.3#egg=django-pyfs==1.0.3 diff --git a/sample_xblocks/filethumbs/filethumbs.py b/sample_xblocks/filethumbs/filethumbs.py index d1794ead..b74e09b0 100644 --- a/sample_xblocks/filethumbs/filethumbs.py +++ b/sample_xblocks/filethumbs/filethumbs.py @@ -75,12 +75,12 @@ def student_view(self, context=None): # pylint: disable=W0613 html_str = pkg_resources.resource_string(__name__, "static/html/thumbs.html") frag = Fragment(unicode(html_str)) - if not self.fs.exists("thumbsvotes.json"): - with self.fs.open('thumbsvotes.json', 'wb') as file_output: + if not self.fs.exists(u"thumbsvotes.json"): + with self.fs.open(u'thumbsvotes.json', 'wb') as file_output: json.dump({'up': 0, 'down': 0}, file_output) file_output.close() - votes = json.load(self.fs.open("thumbsvotes.json")) + votes = json.load(self.fs.open(u"thumbsvotes.json")) self.upvotes = votes['up'] self.downvotes = votes['down'] @@ -92,10 +92,10 @@ def student_view(self, context=None): # pylint: disable=W0613 "static/js/src/thumbs.js") frag.add_javascript(unicode(js_str)) - with self.fs.open('uparrow.png', 'wb') as file_output: + with self.fs.open(u'uparrow.png', 'wb') as file_output: png.Writer(len(ARROW[0]), len(ARROW), greyscale=True, bitdepth=1).write(file_output, ARROW) - with self.fs.open('downarrow.png', 'wb') as file_output: + with self.fs.open(u'downarrow.png', 'wb') as file_output: png.Writer(len(ARROW[0]), len(ARROW), greyscale=True, bitdepth=1).write(file_output, ARROW[::-1]) frag.initialize_js('FileThumbsBlock', {'up': self.upvotes, @@ -119,7 +119,7 @@ def vote(self, data, suffix=''): # pylint: disable=unused-argument # log.error("cheater!") # return - votes = json.load(self.fs.open("thumbsvotes.json")) + votes = json.load(self.fs.open(u"thumbsvotes.json")) self.upvotes = votes['up'] self.downvotes = votes['down'] @@ -132,7 +132,7 @@ def vote(self, data, suffix=''): # pylint: disable=unused-argument else: self.downvotes += 1 - with self.fs.open('thumbsvotes.json', 'wb') as file_output: + with self.fs.open(u'thumbsvotes.json', 'wb') as file_output: json.dump({'up': self.upvotes, 'down': self.downvotes}, file_output) self.voted = True diff --git a/workbench/test/selenium_test.py b/workbench/test/selenium_test.py index ad9246a8..87cade18 100644 --- a/workbench/test/selenium_test.py +++ b/workbench/test/selenium_test.py @@ -7,6 +7,9 @@ from workbench.runtime import reset_global_state +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support.expected_conditions import staleness_of + @attr('selenium') class SeleniumTest(WebAppTest, StaticLiveServerTestCase): @@ -19,3 +22,13 @@ def setUp(self): # Clear the in-memory key value store, the usage store, and whatever # else needs to be cleared and re-initialized. reset_global_state() + + def wait_for_page_load(self, old_element, timeout=30): + """ + Uses Selenium's built-in "staleness" hook to wait until the page has + loaded. For use when clicking a link to ensure that the new page + has loaded before selecting elements. I think that this could be used + to check that elements have been made stale via ajax as well, but it + is not being used for that in any of the tests here. + """ + return WebDriverWait(self.browser, timeout).until(staleness_of(old_element)) diff --git a/workbench/test/test_filethumbs.py b/workbench/test/test_filethumbs.py index eaa755d0..d6052901 100644 --- a/workbench/test/test_filethumbs.py +++ b/workbench/test/test_filethumbs.py @@ -27,6 +27,7 @@ def test_three_thumbs_initial_state(self): # She clicks on the three thumbs at once scenario link = self.browser.find_element_by_link_text('three file thumbs test') link.click() + self.wait_for_page_load(link, timeout=10) # The header reflects the XBlock header1 = self.browser.find_element_by_css_selector('h1') diff --git a/workbench/test/test_thumbs.py b/workbench/test/test_thumbs.py index 61b389c4..0b3a055b 100644 --- a/workbench/test/test_thumbs.py +++ b/workbench/test/test_thumbs.py @@ -27,6 +27,7 @@ def test_three_thumbs_initial_state(self): # She clicks on the three thumbs at once scenario link = self.browser.find_element_by_link_text('three thumbs test') link.click() + self.wait_for_page_load(link, timeout=10) # The header reflects the XBlock header1 = self.browser.find_element_by_css_selector('h1') @@ -58,6 +59,7 @@ def test_three_upvoting(self): # She clicks on the three thumbs at once scenario link = self.browser.find_element_by_link_text('three thumbs test') link.click() + self.wait_for_page_load(link, timeout=10) # The vertical that contains the thumbs vertical_css = 'div.student_view > div.xblock-v1 > div.vertical' @@ -88,6 +90,7 @@ def test_three_downvoting(self): # She clicks on the three thumbs at once scenario link = self.browser.find_element_by_link_text('three thumbs test') link.click() + self.wait_for_page_load(link, timeout=10) # The vertical that contains the thumbs vertical_css = 'div.student_view > div.xblock-v1 > div.vertical'