-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for python 3.5/3.8 and django 2.2 + basic tests
- Loading branch information
1 parent
4989680
commit 0abda4d
Showing
11 changed files
with
161 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: feedbackxblock | ||
|
||
on: | ||
push: | ||
branches: [master, main] | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-18.04 | ||
strategy: | ||
matrix: | ||
python-version: [3.5] | ||
tox-env: | ||
- quality | ||
- django22 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
pip install tox | ||
- name: Test with tox | ||
run: tox -e ${{ matrix.tox-env }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
*pyc | ||
rate_xblock.egg-info | ||
*~ | ||
*~ | ||
.coverage | ||
.tox | ||
*.egg-info | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
from .test_feedback import TestFeedback | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
from mock import Mock | ||
|
||
from workbench.runtime import WorkbenchRuntime | ||
from xblock.fields import ScopeIds | ||
from xblock.runtime import DictKeyValueStore, KvsFieldData | ||
|
||
from feedback.feedback import FeedbackXBlock | ||
|
||
|
||
def generate_scope_ids(runtime, block_type): | ||
""" helper to generate scope IDs for an XBlock """ | ||
def_id = runtime.id_generator.create_definition(block_type) | ||
usage_id = runtime.id_generator.create_usage(def_id) | ||
return ScopeIds('user', block_type, def_id, usage_id) | ||
|
||
|
||
@pytest.fixture | ||
def feedback_xblock(): | ||
"""Feedback XBlock pytest fixture.""" | ||
runtime = WorkbenchRuntime() | ||
key_store = DictKeyValueStore() | ||
db_model = KvsFieldData(key_store) | ||
ids = generate_scope_ids(runtime, 'feedback') | ||
feedback_xblock = FeedbackXBlock(runtime, db_model, scope_ids=ids) | ||
feedback_xblock.usage_id = Mock() | ||
return feedback_xblock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Tests for the Feedback XBlock with heavy mocking. | ||
""" | ||
|
||
from mock import Mock | ||
|
||
|
||
def test_template_content(feedback_xblock): | ||
""" Test content of FeedbackXBlock's student view """ | ||
student_fragment = feedback_xblock.render('student_view', Mock()) | ||
assert 'feedback' in student_fragment.content | ||
|
||
|
||
def test_studio_view(feedback_xblock): | ||
""" Test content of FeedbackXBlock's author view """ | ||
student_fragment = feedback_xblock.render('studio_view', Mock()) | ||
assert 'feedback' in student_fragment.content | ||
|
||
|
||
def test_studio_submit(feedback_xblock): | ||
""" Test the FeedbackXBlock's save action """ | ||
request_body = b"""{ | ||
"display_name": "foo" | ||
}""" | ||
request = Mock(method='POST', body=request_body) | ||
response = feedback_xblock.studio_submit(request) | ||
assert response.status_code == 200 and {'result': 'success'} == response.json, response.json | ||
|
||
|
||
def test_vote(feedback_xblock): | ||
""" Test content of FeedbackXBlock's vote() method """ | ||
feedback_xblock.vote({'vote': 1}) | ||
|
||
|
||
def test_feedback_method(feedback_xblock): | ||
""" Test content of FeedbackXBlock's feedback() method """ | ||
request_body = b"""{ | ||
"freeform": "yes", | ||
"vote": 1 | ||
}""" | ||
request = Mock(method='POST', body=request_body) | ||
response = feedback_xblock.feedback(request) | ||
|
||
expected_response_json = { | ||
"aggregate": [0, 1, 0, 0, 0], | ||
"freeform": "yes", | ||
"response": "Thank you for your feedback!", | ||
"success": True, | ||
"vote": 1, | ||
} | ||
|
||
assert response.status_code == 200 and response.json == expected_response_json, response.json |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
Test settings for the Feedback XBlock. | ||
""" | ||
|
||
from workbench.settings import * | ||
|
||
from django.conf.global_settings import LOGGING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[tox] | ||
envlist = py{35,38}-django22,py38-django3 | ||
skipsdist = True | ||
|
||
[pytest] | ||
# 58, 228-229, 250, 279-288, 307-317, 330-363, 373, 391-396 | ||
addopts = --cov=feedback --cov-report=term-missing | ||
|
||
[testenv] | ||
usedevelop=True | ||
passenv = | ||
SELENIUM_BROWSER | ||
setenv = | ||
DJANGO_SETTINGS_MODULE = test_settings | ||
deps = | ||
django11: Django>=1.11,<2 | ||
django22: Django>=2.2,<2.3 | ||
bok-choy | ||
six | ||
django-pyfs | ||
flake8 | ||
mock | ||
pytest | ||
pytest-cov | ||
pytest-django | ||
xblock | ||
xblock-sdk | ||
commands = | ||
# TODO: Activate the rest of the tests once they're fixed | ||
{posargs:pytest feedbacktests/test_feedback_unit.py} | ||
|
||
[flake8] | ||
max-line-length = 160 | ||
|
||
[testenv:quality] | ||
commands = | ||
flake8 feedback feedbacktests makeicons setup.py |