Skip to content

Commit

Permalink
refactor: remove bok-choy package and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan committed Oct 13, 2023
1 parent 07dee3e commit 00f6dcb
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 471 deletions.
1 change: 0 additions & 1 deletion requirements/test.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pytest-cov # pytest extension for code coverage statistics
pytest-django # pytest extension for better Django support
ddt # data-driven tests

bok-choy # integration tests
selenium # integration tests
mock # required by the workbench
openedx-django-pyfs # required by the workbench
Expand Down
182 changes: 1 addition & 181 deletions tests/integration/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@

from __future__ import absolute_import

import json
from collections import namedtuple
from xml.sax.saxutils import escape

from bok_choy.promise import EmptyPromise
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from six.moves import range
from workbench import scenarios
from xblock.utils.base_test import SeleniumBaseTest
from xblock.utils.resources import ResourceLoader

from drag_and_drop_v2.default_data import (BOTTOM_ZONE_ID, BOTTOM_ZONE_TITLE,
DEFAULT_DATA, FINISH_FEEDBACK,
FINISH_FEEDBACK,
ITEM_ANY_ZONE_FEEDBACK,
ITEM_ANY_ZONE_NAME,
ITEM_BOTTOM_ZONE_NAME,
Expand All @@ -33,13 +28,11 @@
ITEM_TOP_ZONE_NAME, MIDDLE_ZONE_ID,
MIDDLE_ZONE_TITLE, START_FEEDBACK,
TOP_ZONE_ID, TOP_ZONE_TITLE)
from drag_and_drop_v2.utils import Constants

# Globals ###########################################################

loader = ResourceLoader(__name__)


# Classes ###########################################################

ItemDefinition = namedtuple( # pylint: disable=invalid-name
Expand All @@ -56,179 +49,6 @@
)


class BaseIntegrationTest(SeleniumBaseTest):
default_css_selector = '.themed-xblock.xblock--drag-and-drop'
module_name = __name__

_additional_escapes = {
'"': """,
"'": "'"
}

# pylint: disable=too-many-arguments
# pylint: disable=bad-continuation
@classmethod
def _make_scenario_xml(
cls, display_name="Test DnDv2", show_title=True, problem_text="Question", completed=False,
show_problem_header=True, max_items_per_zone=0, data=None, mode=Constants.STANDARD_MODE
):
if not data:
data = json.dumps(DEFAULT_DATA)
return """
<vertical_demo>
<drag-and-drop-v2
display_name='{display_name}'
show_title='{show_title}'
question_text='{problem_text}'
show_question_header='{show_problem_header}'
weight='1'
completed='{completed}'
max_items_per_zone='{max_items_per_zone}'
mode='{mode}'
data='{data}'
/>
</vertical_demo>
""".format(
display_name=escape(display_name),
show_title=show_title,
problem_text=escape(problem_text),
show_problem_header=show_problem_header,
completed=completed,
max_items_per_zone=max_items_per_zone,
mode=mode,
data=escape(data, cls._additional_escapes)
)

def _get_custom_scenario_xml(self, filename):
data = loader.load_unicode(filename)
return "<vertical_demo><drag-and-drop-v2 data='{data}'/></vertical_demo>".format(
data=escape(data, self._additional_escapes)
)

def _add_scenario(self, identifier, title, xml):
scenarios.add_xml_scenario(identifier, title, xml)
self.addCleanup(scenarios.remove_scenario, identifier)

def _get_items(self):
items_container = self._page.find_element_by_css_selector('.item-bank')
return items_container.find_elements_by_css_selector('.option')

def _get_zones(self):
return self._page.find_elements_by_css_selector(".drag-container .zone")

def _get_popup(self):
return self._page.find_element_by_css_selector(".popup")

def _get_popup_wrapper(self):
return self._page.find_element_by_css_selector(".popup-wrapper")

def _get_popup_content(self):
return self._page.find_element_by_css_selector(".popup .popup-content")

def _get_keyboard_help(self):
return self._page.find_element_by_css_selector(".keyboard-help")

def _get_keyboard_help_button(self):
return self._page.find_element_by_css_selector(".keyboard-help-button")

def _get_keyboard_help_dialog(self):
return self._page.find_element_by_css_selector(".keyboard-help-dialog")

def _get_go_to_beginning_button(self):
return self._page.find_element_by_css_selector('.go-to-beginning-button')

def _get_reset_button(self):
return self._page.find_element_by_css_selector('.problem-action-button-wrapper .reset')

def _get_show_answer_button(self):
return self._page.find_element_by_css_selector('.problem-action-button-wrapper .show')

def _get_submit_button(self):
return self._page.find_element_by_css_selector('.submit-attempt-container .submit')

def _get_attempts_info(self):
return self._page.find_element_by_css_selector('.submission-feedback')

def _get_feedback(self):
return self._page.find_element_by_css_selector(".feedback-content")

def _get_feedback_message(self):
return self._page.find_element_by_css_selector(".feedback .message")

def _get_explanation(self):
return self._page.find_element_by_css_selector(".solution-span")

def scroll_down(self, pixels=50):
self.browser.execute_script("$(window).scrollTop({})".format(pixels))

def is_element_in_viewport(self, element):
"""Determines if the element lies at least partially in the viewport."""
viewport = self.browser.execute_script(
"return {"
"top: window.scrollY,"
"left: window.scrollX,"
"bottom: window.scrollY + window.outerHeight,"
"right: window.scrollX + window.outerWidth"
"};"
)

return all([
any([
viewport["top"] <= element.rect["y"] <= viewport["bottom"],
viewport["top"] <= element.rect["y"] + element.rect["height"] <= viewport["bottom"]
]),
any([
viewport["left"] <= element.rect["x"] <= viewport["right"],
viewport["left"] <= element.rect["x"] + element.rect["width"] <= viewport["right"]
])
])

def _get_style(self, selector, style, computed=True):
if computed:
query = 'return getComputedStyle($("{selector}").get(0)).{style}'
else:
query = 'return $("{selector}").get(0).style.{style}'
return self.browser.execute_script(query.format(selector=selector, style=style))

def assertFocused(self, element):
focused_element = self.browser.switch_to.active_element
self.assertTrue(element == focused_element, 'expected element to have focus')

def assertNotFocused(self, element):
focused_element = self.browser.switch_to.active_element
self.assertTrue(element != focused_element, 'expected element to not have focus')

@staticmethod
def get_element_html(element):
return element.get_attribute('innerHTML').strip()

@staticmethod
def get_element_classes(element):
return element.get_attribute('class').split()

def wait_until_html_in(self, html, elem):
wait = WebDriverWait(elem, 2)
wait.until(lambda e: html in e.get_attribute('innerHTML'),
u"{} should be in {}".format(html, elem.get_attribute('innerHTML')))

@staticmethod
def wait_until_has_class(class_name, elem):
wait = WebDriverWait(elem, 2)
wait.until(lambda e: class_name in e.get_attribute('class').split(),
u"Class name {} not in {}".format(class_name, elem.get_attribute('class')))

def wait_for_ajax(self, timeout=15):
"""
Wait for jQuery to be loaded and for all ajax requests to finish.
Same as bok-choy's PageObject.wait_for_ajax()
"""
def is_ajax_finished():
""" Check if all the ajax calls on the current page have completed. """
return self.browser.execute_script("return typeof(jQuery)!='undefined' && jQuery.active==0")

EmptyPromise(is_ajax_finished, "Finished waiting for ajax requests.", timeout=timeout).fulfill()


class DefaultDataTestMixin(object):
"""
Provides a test scenario with default options.
Expand Down
Loading

0 comments on commit 00f6dcb

Please sign in to comment.