Skip to content

Commit

Permalink
feat: added integration tests in CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas12091101 committed Feb 15, 2024
1 parent aa04de8 commit 7d7da18
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 202 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
- name: Python setup
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

python-version: ${{ matrix.python-version }}
- name: tox install
run: pip install tox

Expand All @@ -36,6 +36,15 @@ jobs:
TOXENV: ${{ matrix.toxenv }}
run: tox

- name: Run Integration Tests
run: |
cd ..
git clone https://github.com/edx/devstack.git
cd devstack
sed -i 's/:cached//g' ./docker-compose-host.yml
make dev.clone.https
DEVSTACK_WORKSPACE=$PWD/.. docker-compose -f docker-compose.yml -f docker-compose-host.yml run -v $PWD/../edx-sga:/edx-sga lms /edx-sga/run_devstack_integration_tests.sh
- name: Upload coverage to CodeCov
if: matrix.python-version == '3.8' && matrix.toxenv == 'py38-django32'
uses: codecov/codecov-action@v3
Expand Down
4 changes: 2 additions & 2 deletions edx_sga/sga.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def get_student_item_dict(self, student_id=None):
"""
if student_id is None and (user_service := self.runtime.service(self, 'user')):
student_id = user_service.get_current_user().opt_attrs.get(ATTR_KEY_ANONYMOUS_USER_ID)

assert student_id != ("MOCK", "Forgot to call 'personalize' in test.")
return {
"student_id": student_id,
Expand Down Expand Up @@ -762,7 +762,7 @@ def student_state(self):
if score:
score = score.get("points_earned")
graded = {"score": score, "comment": force_str(self.comment)}

Check warning on line 764 in edx_sga/sga.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/sga.py#L763-L764

Added lines #L763 - L764 were not covered by tests

else:
uploaded = None

Expand Down
41 changes: 20 additions & 21 deletions edx_sga/tests/integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import json
import os
import shutil
import functools
import tempfile
from unittest import mock

Expand All @@ -32,16 +31,13 @@
from submissions.models import StudentItem
from xblock.field_data import DictFieldData
from xblock.fields import ScopeIds
from xblock.runtime import DictKeyValueStore, KvsFieldData
from xblock.runtime import DictKeyValueStore, KvsFieldData, Mixologist
from xblock.test.tools import TestRuntime

Check warning on line 35 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L34-L35

Added lines #L34 - L35 were not covered by tests
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, mixed_store_config, StoreConstructors
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory
from xmodule.modulestore.xml_exporter import export_course_to_xml
from xmodule.modulestore.xml_importer import import_course_from_xml
from xmodule.modulestore.inheritance import InheritanceMixin
from openedx.core.lib import tempdir
from xblock.runtime import Mixologist

from edx_sga.constants import ShowAnswer
from edx_sga.sga import StaffGradedAssignmentXBlock
Expand Down Expand Up @@ -166,7 +162,7 @@ def make_student(self, block, name, make_state=True, **state):
module.save()

anonymous_id = anonymous_id_for_user(user, self.course_id)

item = StudentItem(
student_id=anonymous_id,
course_id=self.course_id,
Expand All @@ -175,14 +171,14 @@ def make_student(self, block, name, make_state=True, **state):
)
item.save()

if answer:
if answer:
student_id = block.get_student_item_dict(anonymous_id)
submission = submissions_api.create_submission(student_id, answer)
if score is not None:
submissions_api.set_score(
submission["uuid"], score, block.max_score()
)
pass

else:
submission = None

Expand All @@ -204,7 +200,7 @@ def personalize(self, block, module, item, submission):
state = json.loads(student_module.state)
for key, value in state.items():
setattr(block, key, value)

self.runtime.deprecated_anonymous_student_id = item.student_id

Check warning on line 204 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L204

Added line #L204 was not covered by tests

def test_ctor(self):
Expand Down Expand Up @@ -254,7 +250,6 @@ def test_student_view(self, fragment, render_template):
self.assertEqual(student_state["upload_allowed"], True)
self.assertEqual(student_state["max_score"], 100)
self.assertEqual(student_state["graded"], None)
# pylint: disable=no-member
fragment.add_css.assert_called_once_with(
DummyResource("static/css/edx_sga.css")
)
Expand Down Expand Up @@ -327,7 +322,6 @@ def test_student_view_with_score(self, fragment, render_template):
self.assertEqual(student_state["upload_allowed"], False)
self.assertEqual(student_state["max_score"], 100)
self.assertEqual(student_state["graded"], {"comment": "", "score": 10})
# pylint: disable=no-member
fragment.add_css.assert_called_once_with(

Check warning on line 325 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L309-L325

Added lines #L309 - L325 were not covered by tests
DummyResource("static/css/edx_sga.css")
)
Expand Down Expand Up @@ -566,7 +560,8 @@ def test_staff_download(self):
user = student["module"].student
student_id = anonymous_id_for_user(user,self.course_id)

Check warning on line 561 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L560-L561

Added lines #L560 - L561 were not covered by tests

with mock.patch.object(StaffGradedAssignmentXBlock.get_student_item_dict,"__defaults__",(student_id,)), self.dummy_upload(filename, text) as (upload, __):
with mock.patch.object(StaffGradedAssignmentXBlock.get_student_item_dict,"__defaults__",(student_id,)),\

Check warning on line 563 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L563

Added line #L563 was not covered by tests
self.dummy_upload(filename, text) as (upload, __):
block.upload_assignment(mock.Mock(params={"assignment": upload}))
students.append(
(
Expand Down Expand Up @@ -627,8 +622,9 @@ def test_staff_download_unicode_filename(self):
self.personalize(block, **student)
user = student["module"].student
student_id = anonymous_id_for_user(user,self.course_id)

Check warning on line 624 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L623-L624

Added lines #L623 - L624 were not covered by tests

with mock.patch.object(StaffGradedAssignmentXBlock.get_student_item_dict,"__defaults__",(student_id,)), self.dummy_upload("файл.txt") as (upload, expected):

with mock.patch.object(StaffGradedAssignmentXBlock.get_student_item_dict,"__defaults__",(student_id,)),\

Check warning on line 626 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L626

Added line #L626 was not covered by tests
self.dummy_upload("файл.txt") as (upload, expected):
block.upload_assignment(mock.Mock(params={"assignment": upload}))
response = block.staff_download(
mock.Mock(params={"student_id": student["item"].student_id})
Expand Down Expand Up @@ -656,8 +652,9 @@ def test_staff_download_filename_with_spaces(self):
self.personalize(block, **student)
user = student["module"].student
student_id = anonymous_id_for_user(user,self.course_id)

Check warning on line 654 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L653-L654

Added lines #L653 - L654 were not covered by tests

with mock.patch.object(StaffGradedAssignmentXBlock.get_student_item_dict,"__defaults__",(student_id,)), self.dummy_upload(file_name) as (upload, expected):

with mock.patch.object(StaffGradedAssignmentXBlock.get_student_item_dict,"__defaults__",(student_id,)),\

Check warning on line 656 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L656

Added line #L656 was not covered by tests
self.dummy_upload(file_name) as (upload, expected):
block.upload_assignment(mock.Mock(params={"assignment": upload}))
response = block.staff_download(
mock.Mock(params={"student_id": student["item"].student_id})
Expand All @@ -678,8 +675,9 @@ def test_file_download_comma_in_name(self, file_name):
self.personalize(block, **student)
user = student["module"].student
student_id = anonymous_id_for_user(user,self.course_id)

Check warning on line 677 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L676-L677

Added lines #L676 - L677 were not covered by tests

with mock.patch.object(StaffGradedAssignmentXBlock.get_student_item_dict,"__defaults__",(student_id,)), self.dummy_upload(file_name) as (upload, expected):

with mock.patch.object(StaffGradedAssignmentXBlock.get_student_item_dict,"__defaults__",(student_id,)),\

Check warning on line 679 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L679

Added line #L679 was not covered by tests
self.dummy_upload(file_name) as (upload, expected):
block.upload_assignment(mock.Mock(params={"assignment": upload}))
response = block.staff_download(
mock.Mock(params={"student_id": student["item"].student_id})
Expand All @@ -695,7 +693,8 @@ def test_get_staff_grading_data_not_staff(self):
test staff grading data for non staff members.
"""
block = self.make_one()
with mock.patch("edx_sga.sga.StaffGradedAssignmentXBlock.is_course_staff", return_value=False), self.assertRaises(PermissionDenied):
with mock.patch("edx_sga.sga.StaffGradedAssignmentXBlock.is_course_staff", return_value=False),\

Check warning on line 696 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L696

Added line #L696 was not covered by tests
self.assertRaises(PermissionDenied):
block.get_staff_grading_data(None)

def test_get_staff_grading_data(self):
Expand Down Expand Up @@ -934,7 +933,7 @@ def test_has_attempted(self):

@data(True, False)
def test_runtime_user_is_staff(self, is_staff):

staff = StaffFactory.create(course_key=self.course.id)

Check warning on line 937 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L937

Added line #L937 was not covered by tests

render.prepare_runtime_for_user(

Check warning on line 939 in edx_sga/tests/integration_tests.py

View check run for this annotation

Codecov / codecov/patch

edx_sga/tests/integration_tests.py#L939

Added line #L939 was not covered by tests
Expand Down
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
DJANGO_SETTINGS_MODULE = edx_sga.test_settings
addopts = --cov . --ds=edx_sga.test_settings
norecursedirs = .git .tox edx_sga.static edx_sga.locale edx_sga.templates {arch} *.egg
2 changes: 2 additions & 0 deletions run_devstack_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ mkdir -p reports

pip install -r requirements/edx/testing.txt

pip install -e .

cd /edx-sga
pip uninstall edx-sga -y
pip install -e .
Expand Down
177 changes: 0 additions & 177 deletions setup.cfg

This file was deleted.

0 comments on commit 7d7da18

Please sign in to comment.