Skip to content

Commit

Permalink
Merge pull request #228 from edx-solutions/awais786/python3-travis
Browse files Browse the repository at this point in the history
BOM-470
  • Loading branch information
awais786 authored Oct 4, 2019
2 parents 797a480 + c621de3 commit 8bf4b66
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 22 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: python
sudo: false
python:
- "2.7"
- "3.5"
services:
- xvfb
install:
Expand Down
13 changes: 10 additions & 3 deletions drag_and_drop_v2/drag_and_drop_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,7 @@ def has_submission_deadline_passed(self):
def student_view_user_state(self, request, suffix=''):
""" GET all user-specific data, and any applicable feedback """
data = self._get_user_state()

return webob.Response(body=json.dumps(data), content_type='application/json')
return webob.Response(body=json.dumps(data).encode('utf-8'), content_type='application/json')

def _validate_do_attempt(self):
"""
Expand Down Expand Up @@ -836,7 +835,15 @@ def _mark_complete_and_publish_grade(self):
# ... and from higher grade to lower
# if we have an old-style (i.e. unreliable) grade, override no matter what
saved_raw_earned = self._get_raw_earned_if_set()
if current_raw_earned is None or current_raw_earned > saved_raw_earned:

current_raw_earned_is_greater = False
if current_raw_earned is None or saved_raw_earned is None:
current_raw_earned_is_greater = True

if current_raw_earned is not None and saved_raw_earned is not None and current_raw_earned > saved_raw_earned:
current_raw_earned_is_greater = True

if current_raw_earned is None or current_raw_earned_is_greater:
self.raw_earned = current_raw_earned
self._publish_grade(Score(self.raw_earned, self.max_score()))

Expand Down
2 changes: 1 addition & 1 deletion install_test_deps.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Installs xblock-sdk and dependencies needed to run the tests suite.
# Run this script inside a fresh virtual environment.
pip install -e git://github.com/edx/xblock-sdk.git@3b64219024d111f247a14e267cd5eaee72aefcd8#egg=xblock-sdk
pip install -e git://github.com/edx/xblock-sdk.git@4d0027a040aec1be1a22dc9a4b8fc667bba0ddba#egg=xblock-sdk
cd $VIRTUAL_ENV/src/xblock-sdk/ && pip install -r requirements/base.txt \
&& pip install -r requirements/test.txt && cd -
pip install -r requirements.txt
10 changes: 10 additions & 0 deletions openedx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file describes this Open edX repo, as described in OEP-2:
# http://open-edx-proposals.readthedocs.io/en/latest/oeps/oep-0002.html#specification

tags:
- xblock-drag-and-drop-v2
- library
oeps:
oep-2: false
oep-7: true
oep-18: true
16 changes: 8 additions & 8 deletions tests/integration/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,27 +600,27 @@ def _assert_zone_align_item(self, item_id, zone_id, align, action_key=None):
"""
# parent container has the expected alignment
item_wrapper_selector = "div[data-uid='{zone_id}'] .item-wrapper".format(zone_id=zone_id)
self.assertEquals(self._get_style(item_wrapper_selector, 'textAlign'), align)
self.assertEqual(self._get_style(item_wrapper_selector, 'textAlign'), align)

# Items placed in zones with align setting are children of the zone
zone_item_selector = '{item_wrapper_selector} .option'.format(item_wrapper_selector=item_wrapper_selector)
prev_placed_items = self._page.find_elements_by_css_selector(zone_item_selector)

self.place_item(item_id, zone_id, action_key)
placed_items = self._page.find_elements_by_css_selector(zone_item_selector)
self.assertEquals(len(placed_items), len(prev_placed_items) + 1)
self.assertEqual(len(placed_items), len(prev_placed_items) + 1)

# Not children of the target
target_item = '.target > .option'
self.assertEquals(len(self._page.find_elements_by_css_selector(target_item)), 0)
self.assertEqual(len(self._page.find_elements_by_css_selector(target_item)), 0)

# Aligned items are relative positioned, with no transform or top/left
self.assertEquals(self._get_style(zone_item_selector, 'position'), 'relative')
self.assertEquals(self._get_style(zone_item_selector, 'transform'), 'none')
self.assertEquals(self._get_style(zone_item_selector, 'left'), '0px')
self.assertEquals(self._get_style(zone_item_selector, 'top'), '0px')
self.assertEqual(self._get_style(zone_item_selector, 'position'), 'relative')
self.assertEqual(self._get_style(zone_item_selector, 'transform'), 'none')
self.assertEqual(self._get_style(zone_item_selector, 'left'), '0px')
self.assertEqual(self._get_style(zone_item_selector, 'top'), '0px')

self.assertEquals(self._get_style(zone_item_selector, 'display'), 'inline-block')
self.assertEqual(self._get_style(zone_item_selector, 'display'), 'inline-block')

@data(
([0, 1, 2], "Zone No Align", "center"),
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _test_item_style(self, item_element, style_settings):
else:
expected_background_color = Colors.rgb(style_settings['background-color'])
background_color = self._get_style(item_selector, 'backgroundColor')
self.assertEquals(background_color, expected_background_color)
self.assertEqual(background_color, expected_background_color)

# Check text color
color_property = 'color'
Expand All @@ -101,7 +101,7 @@ def _test_item_style(self, item_element, style_settings):
else:
expected_color = Colors.rgb(style_settings['color'])
color = self._get_style(item_selector, 'color')
self.assertEquals(color, expected_color)
self.assertEqual(color, expected_color)

# Check outline color
outline_color_property = 'outline-color'
Expand All @@ -110,7 +110,7 @@ def _test_item_style(self, item_element, style_settings):
# Outline color should match text color to ensure it does not meld into background color:
expected_outline_color = expected_color
outline_color = self._get_style(item_selector, 'outlineColor')
self.assertEquals(outline_color, expected_outline_color)
self.assertEqual(outline_color, expected_outline_color)

def test_items_default_colors(self):
self.load_scenario()
Expand Down Expand Up @@ -341,5 +341,5 @@ def test_zone_align(self):
}
for zone_id, expected_alignment in expected_alignments.items():
selector = "{zone_id} .item-wrapper".format(zone_id=zone_id)
self.assertEquals(self._get_style(selector, "textAlign"), expected_alignment)
self.assertEquals(self._get_style(selector, "textAlign", computed=True), expected_alignment)
self.assertEqual(self._get_style(selector, "textAlign"), expected_alignment)
self.assertEqual(self._get_style(selector, "textAlign", computed=True), expected_alignment)
2 changes: 1 addition & 1 deletion tests/integration/test_sizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _svg_to_data_uri(path):
data_path = os.path.dirname(__file__) + "/data/"
with open(data_path + path, "rb") as svg_fh:
encoded = base64.b64encode(svg_fh.read())
return "data:image/svg+xml;base64,{}".format(encoded)
return "data:image/svg+xml;base64,{}".format(encoded.decode('utf-8'))


Expectation = namedtuple('Expectation', [
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def test_do_attempt_has_deadline_passed(self, is_past_deadline, status_code, exp
response = self.call_handler(self.DO_ATTEMPT_HANDLER, data={}, expect_json=False)
self.assertEqual(response.status_code, status_code)
if expect_error:
self.assertIn("Submission deadline has passed.", response.body)
self.assertIn("Submission deadline has passed.", response.body.decode('utf-8'))

@ddt.data(*[random.randint(1, 50) for _ in range(5)]) # pylint: disable=star-args
def test_do_attempt_correct_mark_complete_and_publish_grade(self, weight):
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def test_legacy_state_support(self):
'4': {'zone': BOTTOM_ZONE_ID, 'correct': False},
}
self.block.save()

self.assertEqual(self.call_handler('student_view_user_state')['items'], {
'0': {'correct': True, 'zone': TOP_ZONE_ID},
'1': {'correct': True, 'zone': MIDDLE_ZONE_ID},
Expand Down
5 changes: 3 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def make_request(data, method='POST'):
""" Make a webob JSON Request """
request = Request.blank('/')
request.method = 'POST'
request.body = json.dumps(data).encode('utf-8') if data is not None else ""
data = json.dumps(data).encode('utf-8') if data is not None else b''
request.body = data
request.method = method
return request

Expand Down Expand Up @@ -74,5 +75,5 @@ def call_handler(self, handler_name, data=None, expect_json=True, method='POST')
response = self.block.handle(handler_name, make_request(data, method=method))
if expect_json:
self.assertEqual(response.status_code, 200)
return json.loads(response.body)
return json.loads(response.body.decode('utf-8'))
return response

0 comments on commit 8bf4b66

Please sign in to comment.