Skip to content

Commit

Permalink
Merge pull request #293 from open-craft/agrendalath/improve_ci
Browse files Browse the repository at this point in the history
build: fix CI and simplify dev setup
  • Loading branch information
Agrendalath authored Sep 28, 2022
2 parents d093b84 + cfd2b2d commit 3fddeb5
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 70 deletions.
49 changes: 13 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,31 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04]
python-version: [3.5]
os: [ubuntu-20.04]
python-version: [3.8]

steps:
- name: checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive

- name: setup python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

# `libgtk2.0-0` and `libxt6` are required by an older version of Firefox.
- name: Install Required System Packages
run: |
sudo apt-get update && sudo apt-get install libxmlsec1-dev ubuntu-restricted-extras xvfb
sudo apt-get install libxml2-dev libxslt-dev python3-dev libevent-dev
- name: Setup Environment
# Remove the last two lines of this step after our test suite is compatible with selenium 3.
run: |
export DISPLAY=:99.0
sudo apt-get install xvfb
pip install wheel
sh install_test_deps.sh
pip uninstall -y selenium
pip install selenium==2.53.6
sudo apt-get update
sudo apt-get install -y libxmlsec1-dev ubuntu-restricted-extras xvfb libxml2-dev libxslt-dev python3-dev libevent-dev python3-pip python3-venv libgtk2.0-0 libxt6
- name: Install Dependencies
run: |
python setup.py sdist
pip install dist/xblock-drag-and-drop-v2-*.tar.gz
pip install pylint==1.7.6
run: make requirements

- name: Install Firefox 43.0
run: |
sudo apt-get purge firefox
wget "https://ftp.mozilla.org/pub/firefox/releases/43.0/linux-x86_64/en-US/firefox-43.0.tar.bz2"
tar -xjf firefox-43.0.tar.bz2
sudo mv firefox /opt/firefox
sudo ln -s /opt/firefox/firefox /usr/bin/firefox
- name: Run pycodestyle check
run: pycodestyle drag_and_drop_v2 tests --max-line-length=120

- name: Run pylint checks
run: |
pylint drag_and_drop_v2
pylint tests --rcfile=tests/pylintrc
- name: Run quality checks
run: make test.quality

- name: Run unit tests
run: xvfb-run python run_tests.py
run: make test.unit
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ target/
# IDEs
.idea
.idea/*

test_helpers/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "xblock-sdk"]
path = xblock-sdk
url = https://github.com/openedx/xblock-sdk
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Drag and Drop XBlock changelog
==============================

Version 2.4.0 (2022-09-23)
---------------------------

* Drop the support for Python 3.5 and Ubuntu 18.04.

Version 2.3.11 (2022-07-22)
---------------------------

Expand Down
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,22 @@ pull_translations: ## pull translations from transifex

push_translations: ## push translations to transifex
cd $(WORKING_DIR) && i18n_tool transifex push

install_firefox:
mkdir -p test_helpers
cd test_helpers && wget "https://ftp.mozilla.org/pub/firefox/releases/43.0/linux-x86_64/en-US/firefox-43.0.tar.bz2" && tar -xjf firefox-43.0.tar.bz2

requirements: install_firefox
pip install wheel
pip install -r xblock-sdk/requirements/base.txt -r xblock-sdk/requirements/test.txt
pip install -r requirements.txt

test.quality: ## run quality checkers on the codebase
pycodestyle drag_and_drop_v2 tests --max-line-length=120
pylint drag_and_drop_v2
pylint tests --rcfile=tests/pylintrc

test.unit: ## run python unit and integration tests
PATH=test_helpers/firefox:$$PATH xvfb-run python run_tests.py

test: test.quality test.unit ## Run all tests
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ refreshes. All checking and record keeping is done on the server side.
The following screenshot shows the Drag and Drop XBlock rendered
inside the edX LMS before the user starts solving the problem:

![Student view start](/doc/img/student-view-start.png)
![Student view start](doc/img/student-view-start.png)

This screenshot shows the XBlock after the learner successfully
completed the Drag and Drop problem:

![Student view finish](/doc/img/student-view-finish.png)
![Student view finish](doc/img/student-view-finish.png)

Installation
------------
Expand Down Expand Up @@ -93,7 +93,7 @@ Usage
The Drag and Drop XBlock features an interactive editor. Add the Drag
and Drop component to a lesson, then click the `EDIT` button.

![Edit view](/doc/img/edit-view.png)
![Edit view](doc/img/edit-view.png)

In the first step, you can set some basic properties of the component, such as
the title, the problem mode, the maximum number of attempts, the maximum score,
Expand All @@ -110,7 +110,7 @@ There are two problem modes available:
limited. When all attempts are used, the learner can click a "Show Answer"
button to temporarily place items on their correct drop zones.

![Drop zone edit](/doc/img/edit-view-zones.png)
![Drop zone edit](doc/img/edit-view-zones.png)

In the next step, you set the URL and description for the background
image and define the properties of the drop zones. For each zone you
Expand All @@ -130,7 +130,7 @@ right to left across the zone. Items dropped in a zone will not overlap,
but if the zone is not made large enough for all its items, they will overflow the bottom
of the zone, and potentially overlap the zones below.

![Drag item edit](/doc/img/edit-view-items.png)
![Drag item edit](doc/img/edit-view-items.png)

In the final step, you define the background and text color for drag items, as
well as the drag items themselves. A drag item can contain either text or an
Expand Down Expand Up @@ -449,25 +449,26 @@ Inside a fresh virtualenv, `cd` into the root folder of this repository
(`xblock-drag-and-drop-v2`) and run

```bash
$ sh install_test_deps.sh
$ git submodule update --init --recursive
$ make requirements
```

You can then run the entire test suite via

```bash
$ python run_tests.py
$ make test
```

To only run the unit test suite, do
To only run the quality checks, do

```bash
$ python run_tests.py tests/unit/
$ make test.quality
```

Similarly, you can run the integration test suite via
Similarly, you can run unit and integration test suite via

```bash
$ python run_tests.py tests/integration/
$ make test.unit
```


Expand Down
5 changes: 3 additions & 2 deletions drag_and_drop_v2/drag_and_drop_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import json
import logging

import pkg_resources
import six
import six.moves.urllib.error # pylint: disable=import-error
import six.moves.urllib.parse # pylint: disable=import-error
import six.moves.urllib.request # pylint: disable=import-error
import pkg_resources
import six
import webob

from django.utils import translation
Expand Down Expand Up @@ -1091,6 +1091,7 @@ def _get_zone_by_uid(self, uid):
for zone in self.zones:
if zone["uid"] == uid:
return zone
return None

def _get_item_stats(self):
"""
Expand Down
10 changes: 5 additions & 5 deletions drag_and_drop_v2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ def _clean_data(data):
return cleaned_text


class DummyTranslationService(object):
class DummyTranslationService:
"""
Dummy drop-in replacement for i18n XBlock service
"""
gettext = _
ngettext = ngettext_fallback


class FeedbackMessages(object):
class FeedbackMessages:
"""
Feedback messages collection
"""
class MessageClasses(object):
class MessageClasses:
"""
Namespace for message classes
"""
Expand Down Expand Up @@ -108,7 +108,7 @@ def not_placed(number, ngettext=ngettext_fallback):
)


class Constants(object):
class Constants:
"""
Namespace class for various constants
"""
Expand All @@ -119,7 +119,7 @@ class Constants(object):
ASSESSMENT_MODE = "assessment"


class StateMigration(object):
class StateMigration:
"""
Helper class to apply zone data and item state migrations
"""
Expand Down
6 changes: 0 additions & 6 deletions install_test_deps.sh

This file was deleted.

15 changes: 10 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
mako==1.0.7
# FIXME: This pins Django to `1.11.29`.
# Using Django 2.2 results in non-deterministc behavior of Selenium tests - they are randomly failing to find CSS selectors.
edx-i18n-tools==0.4.7
pycodestyle==2.5.0
django-statici18n==1.8.0
django-statici18n==1.9.0
transifex-client==0.14.2
bleach==3.3.0
git+https://github.com/openedx/xblock-utils.git@v1.2.2#egg=xblock-utils==1.2.2
XBlock==1.2.6
bleach==3.3.1
xblock-utils==1.2.2
selenium==2.53.6
pylint==2.4.2
# HACK: This repo contains submodule with `xblock-sdk==0.1.9`, but it doesn't support `Django<2.2`.
# We are using `0.1.9` (which introducted Python 3.8 compatibility) for installing dependencies, but `v0.1.8` for running tests.
-e git+https://github.com/openedx/xblock-sdk.git@v0.1.8#egg=xblock-sdk
-e .
3 changes: 3 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging
import os
import sys
import warnings
import workbench

if __name__ == "__main__":
Expand All @@ -24,6 +25,8 @@

# Silence too verbose Django logging
logging.disable(logging.DEBUG)
# TODO: Delete this after upgrading `xblock-sdk`.
warnings.simplefilter(action='ignore', category=FutureWarning)

try:
os.mkdir('var')
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ def package_data(pkg, root_list):

setup(
name='xblock-drag-and-drop-v2',
version='2.3.11',
version='2.4.0',
description='XBlock - Drag-and-Drop v2',
packages=['drag_and_drop_v2'],
install_requires=[
'XBlock',
'xblock-utils',
'ddt',
'mock',
'bleach',
],
entry_points={
Expand Down
1 change: 0 additions & 1 deletion src/xblock-sdk
Submodule xblock-sdk deleted from 0c9873
4 changes: 3 additions & 1 deletion tests/integration/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ def setUp(self):
# Resize window so that the entire drag container is visible.
# Selenium has issues when dragging to an area that is off screen.
self.browser.set_window_size(1024, 1024)
wait = WebDriverWait(self.browser, 2)
wait.until(lambda browser: browser.get_window_size()["width"] == 1024)

@staticmethod
def _get_items_with_zone(items_map):
Expand All @@ -300,7 +302,7 @@ def _get_items_without_zone(items_map):

@staticmethod
def _get_items_by_zone(items_map):
zone_ids = set([definition.zone_ids[0] for _, definition in items_map.items() if definition.zone_ids])
zone_ids = {definition.zone_ids[0] for _, definition in items_map.items() if definition.zone_ids}
return {
zone_id: {item_key: definition for item_key, definition in items_map.items()
if definition.zone_ids and definition.zone_ids[0] is zone_id}
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ class DragScrollingTest(InteractionTestBase, BaseIntegrationTest):
def setUp(self):
super(DragScrollingTest, self).setUp()
self.browser.set_window_size(320, 480)
wait = WebDriverWait(self.browser, 2)
wait.until(lambda browser: browser.get_window_size()["width"] == 320)

def _get_scenario_xml(self):
return self._get_custom_scenario_xml("data/test_html_data.json")
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def rgb(cls, color):
return 'rgb(255, 127, 80)'
elif color == cls.CORNFLOWERBLUE:
return 'rgb(100, 149, 237)'
return None


@ddt
Expand Down
1 change: 1 addition & 0 deletions xblock-sdk
Submodule xblock-sdk added at 446e97

0 comments on commit 3fddeb5

Please sign in to comment.