Skip to content

Commit

Permalink
Merge pull request #33 from open-craft/CefBoud/variablize-password-in…
Browse files Browse the repository at this point in the history
…-tests

fix: use TEST_PASSWORD variable in tests + quince & palm as test targets
  • Loading branch information
Agrendalath authored Nov 7, 2023
2 parents 789ca42 + 7c3f251 commit ad306ee
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ jobs:
- branch: opencraft-release/nutmeg.2
remote: open-craft
release: nutmeg
- branch: opencraft-release/palm.1
remote: open-craft
release: palm
- branch: open-release/quince.master
remote: openedx
release: quince
- branch: master
remote: openedx
release: master
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Change Log
Unreleased
**********

[0.4.1] - 2023-11-07
********************

Fixed
=======

* Compatibility of ``compat`` imports with Palm.

[0.4.0] - 2023-05-18
********************
Expand Down
2 changes: 1 addition & 1 deletion section_to_course/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Factors sections from Open edX courses into their own new course.
"""

__version__ = '0.4.0'
__version__ = '0.4.1'
18 changes: 9 additions & 9 deletions section_to_course/api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

# pylint: disable=no-self-use
from common.djangoapps.student.tests.factories import UserFactory
from common.djangoapps.student.tests.factories import TEST_PASSWORD, UserFactory
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APITestCase
Expand Down Expand Up @@ -47,14 +47,14 @@ def test_rejects_unauthenticated(self):
response = self.client.get(
reverse('section_to_course:section_autocomplete', kwargs={'course_id': 'course-v1:edX+DemoX+Demo_Course'})
)
assert response.status_code == status.HTTP_403_FORBIDDEN
assert response.status_code in (status.HTTP_401_UNAUTHORIZED, status.HTTP_403_FORBIDDEN)

def test_rejects_unauthorized(self):
"""
Test that the API rejects unauthorized users.
"""
user = UserFactory.create()
assert self.client.login(username=user.username, password='test')
assert self.client.login(username=user.username, password=TEST_PASSWORD)
response = self.client.get(
reverse('section_to_course:section_autocomplete', kwargs={'course_id': 'course-v1:edX+DemoX+Demo_Course'})
)
Expand All @@ -65,7 +65,7 @@ def test_rejects_malformed(self):
Test that the API rejects malformed course IDs.
"""
user = UserFactory.create(is_staff=True)
assert self.client.login(username=user.username, password='test')
assert self.client.login(username=user.username, password=TEST_PASSWORD)
response = self.client.get(
reverse('section_to_course:section_autocomplete', kwargs={'course_id': 'malarkey'})
)
Expand All @@ -76,7 +76,7 @@ def test_handles_nonexistent(self):
Test that the API rejects malformed course IDs.
"""
user = UserFactory.create(is_staff=True)
assert self.client.login(username=user.username, password='test')
assert self.client.login(username=user.username, password=TEST_PASSWORD)
response = self.client.get(
reverse('section_to_course:section_autocomplete', kwargs={'course_id': 'course-v1:edX+DemoX+Demo_Course'}),
)
Expand All @@ -87,7 +87,7 @@ def test_handles_blank(self):
Test that blank terms return all sections.
"""
user = UserFactory.create(is_staff=True)
assert self.client.login(username=user.username, password='test')
assert self.client.login(username=user.username, password=TEST_PASSWORD)
create_subsections()
response = self.client.get(
reverse('section_to_course:section_autocomplete', kwargs={'course_id': 'course-v1:edX+DemoX+Demo_Course'}),
Expand All @@ -105,7 +105,7 @@ def test_filters_existing(self):
Test that autocomplete filters existing sections.
"""
user = UserFactory.create(is_staff=True)
assert self.client.login(username=user.username, password='test')
assert self.client.login(username=user.username, password=TEST_PASSWORD)
section_data = create_subsections()
SectionToCourseLinkFactory(source_course=section_data['course'], source_section=section_data['experimentation'])
response = self.client.get(
Expand All @@ -123,7 +123,7 @@ def test_filters_names(self):
Test that autocomplete filters names.
"""
user = UserFactory.create(is_staff=True)
assert self.client.login(username=user.username, password='test')
assert self.client.login(username=user.username, password=TEST_PASSWORD)
create_subsections()
response = self.client.get(
reverse('section_to_course:section_autocomplete', kwargs={'course_id': 'course-v1:edX+DemoX+Demo_Course'})
Expand All @@ -141,7 +141,7 @@ def test_filters_keys(self):
Test that autocomplete filters keys.
"""
user = UserFactory.create(is_staff=True)
assert self.client.login(username=user.username, password='test')
assert self.client.login(username=user.username, password=TEST_PASSWORD)
create_subsections()
response = self.client.get(
reverse('section_to_course:section_autocomplete', kwargs={'course_id': 'course-v1:edX+DemoX+Demo_Course'})
Expand Down
18 changes: 14 additions & 4 deletions section_to_course/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,15 @@ def duplicate_block(
Duplicate a block using the upstream function.
"""
try:
# Quince and newer
from cms.djangoapps.contentstore.utils import duplicate_block as upstream_duplicate_block
except ImportError:
# This is no longer needed in Palm.
from cms.djangoapps.contentstore.views.item import duplicate_block as upstream_duplicate_block
try:
# Palm
from cms.djangoapps.contentstore.views.block import duplicate_block as upstream_duplicate_block
except ModuleNotFoundError:
# Nutmeg
from cms.djangoapps.contentstore.views.item import duplicate_block as upstream_duplicate_block
return upstream_duplicate_block(
parent_usage_key=destination_course.location,
duplicate_source_usage_key=source_block_usage_key,
Expand All @@ -115,10 +120,15 @@ def update_from_source(
Update a block's attributes from a source block. See upstream function.
"""
try:
# Quince and newer
from cms.djangoapps.contentstore.utils import update_from_source as upstream_update_from_source
except ImportError:
# This is no longer needed in Palm.
from cms.djangoapps.contentstore.views.item import update_from_source as upstream_update_from_source
try:
# Palm
from cms.djangoapps.contentstore.views.block import update_from_source as upstream_update_from_source
except ModuleNotFoundError:
# Nutmeg
from cms.djangoapps.contentstore.views.item import update_from_source as upstream_update_from_source
upstream_update_from_source(
source_block=source_block, destination_block=destination_block, user_id=user.id,
)
Expand Down
4 changes: 2 additions & 2 deletions section_to_course/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Tests for the admin views of the section_to_course app.
"""
from common.djangoapps.student.tests.factories import UserFactory # pylint: disable=import-error
from common.djangoapps.student.tests.factories import TEST_PASSWORD, UserFactory # pylint: disable=import-error
from django.test import TestCase
from django.urls import reverse
from django.utils import timezone
Expand Down Expand Up @@ -31,7 +31,7 @@ def setUp(self):
"""Set up our admin test cases."""
super().setUp()
user = UserFactory.create(is_staff=True, is_superuser=True)
self.client.login(username=user.username, password='test')
self.client.login(username=user.username, password=TEST_PASSWORD)

def test_listing(self):
"""Test that the admin listing page loads."""
Expand Down

0 comments on commit ad306ee

Please sign in to comment.