Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 2 additions & 46 deletions lms/djangoapps/discussion/rest_api/tests/test_api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse # noqa: F401

import ddt
import httpretty
import pytest
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -58,7 +57,6 @@
)
from lms.djangoapps.discussion.rest_api.serializers import TopicOrdering
from lms.djangoapps.discussion.rest_api.tests.utils import (
CommentsServiceMockMixin, # noqa: F401
ForumMockUtilsMixin,
make_paginated_api_response,
parsed_body, # noqa: F401
Expand Down Expand Up @@ -231,10 +229,6 @@ def tearDownClass(cls):
def setUp(self):
super().setUp()
self.course = CourseFactory.create()
httpretty.reset()
httpretty.enable()
self.addCleanup(httpretty.reset)
self.addCleanup(httpretty.disable)
self.user = UserFactory.create()
self.register_get_user_response(self.user)
self.request = RequestFactory().get("/test_path")
Expand Down Expand Up @@ -609,10 +603,6 @@ def tearDownClass(cls):

def setUp(self):
super().setUp()
httpretty.reset()
httpretty.enable()
self.addCleanup(httpretty.reset)
self.addCleanup(httpretty.disable)
self.course = CourseFactory.create()
self.user = UserFactory.create()
self.register_get_user_response(self.user)
Expand Down Expand Up @@ -1046,10 +1036,6 @@ def tearDownClass(cls):
def setUp(self):
super().setUp()

httpretty.reset()
httpretty.enable()
self.addCleanup(httpretty.reset)
self.addCleanup(httpretty.disable)
self.user = UserFactory.create()
self.register_get_user_response(self.user)
self.request = RequestFactory().get("/test_path")
Expand Down Expand Up @@ -1097,8 +1083,7 @@ def test_empty(self):
)
self.register_thread()
update_thread(self.request, "test_thread", {})
for request in httpretty.httpretty.latest_requests:
assert request.method == "GET"
self.mock_forum_api.update_thread.assert_not_called()

def test_basic(self):
self.register_thread()
Expand Down Expand Up @@ -1703,10 +1688,6 @@ def tearDownClass(cls):
def setUp(self):
super().setUp()

httpretty.reset()
httpretty.enable()
self.addCleanup(httpretty.reset)
self.addCleanup(httpretty.disable)
self.user = UserFactory.create()
self.register_get_user_response(self.user)
self.request = RequestFactory().get("/test_path")
Expand Down Expand Up @@ -1758,8 +1739,7 @@ def test_empty(self):
"""Check that an empty update does not make any modifying requests."""
self.register_comment()
update_comment(self.request, "test_comment", {})
for request in httpretty.httpretty.latest_requests:
assert request.method == "GET"
self.mock_forum_api.update_comment.assert_not_called()

@ddt.data(None, "test_parent")
def test_basic(self, parent_id):
Expand Down Expand Up @@ -2304,10 +2284,6 @@ def tearDownClass(cls):

def setUp(self):
super().setUp()
httpretty.reset()
httpretty.enable()
self.addCleanup(httpretty.reset)
self.addCleanup(httpretty.disable)
self.user = UserFactory.create()
self.register_get_user_response(self.user)
self.request = RequestFactory().get("/test_path")
Expand Down Expand Up @@ -2480,10 +2456,6 @@ def tearDownClass(cls):

def setUp(self):
super().setUp()
httpretty.reset()
httpretty.enable()
self.addCleanup(httpretty.reset)
self.addCleanup(httpretty.disable)
self.user = UserFactory.create()
self.register_get_user_response(self.user)
self.request = RequestFactory().get("/test_path")
Expand Down Expand Up @@ -2666,10 +2638,6 @@ def tearDownClass(cls):

def setUp(self):
super().setUp()
httpretty.reset()
httpretty.enable()
self.addCleanup(httpretty.reset)
self.addCleanup(httpretty.disable)
self.user = UserFactory.create()
self.register_get_user_response(self.user)
self.request = RequestFactory().get("/test_path")
Expand Down Expand Up @@ -2817,10 +2785,6 @@ def tearDownClass(cls):

def setUp(self):
super().setUp()
httpretty.reset()
httpretty.enable()
self.addCleanup(httpretty.reset)
self.addCleanup(httpretty.disable)
self.maxDiff = None # pylint: disable=invalid-name
self.user = UserFactory.create()
self.register_get_user_response(self.user)
Expand Down Expand Up @@ -3449,10 +3413,6 @@ def tearDownClass(cls):

def setUp(self):
super().setUp()
httpretty.reset()
httpretty.enable()
self.addCleanup(httpretty.reset)
self.addCleanup(httpretty.disable)
self.maxDiff = None # pylint: disable=invalid-name
self.user = UserFactory.create()
self.register_get_user_response(self.user)
Expand Down Expand Up @@ -4202,10 +4162,6 @@ def test_other_providers_ordering_error(self):
class GetCourseTopicsTest(ForumMockUtilsMixin, UrlResetMixin, ModuleStoreTestCase):
"""Test for get_course_topics"""
def setUp(self):
httpretty.reset()
httpretty.enable()
self.addCleanup(httpretty.reset)
self.addCleanup(httpretty.disable)
super().setUp()
self.maxDiff = None # pylint: disable=invalid-name
self.partition = UserPartition(
Expand Down
10 changes: 0 additions & 10 deletions lms/djangoapps/discussion/rest_api/tests/test_tasks_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from unittest.mock import Mock

import ddt
import httpretty
from django.conf import settings
from django.test import override_settings
from openedx_events.learning.signals import COURSE_NOTIFICATION_REQUESTED, USER_NOTIFICATION_REQUESTED
Expand Down Expand Up @@ -51,10 +50,6 @@ class TestSendResponseNotifications(DiscussionAPIViewTestMixin, ModuleStoreTestC

def setUp(self):
super().setUp()
httpretty.reset()
httpretty.enable()
self.addCleanup(httpretty.disable)
self.addCleanup(httpretty.reset)

self.course = CourseFactory.create()

Expand Down Expand Up @@ -409,8 +404,6 @@ class TestSendCommentNotification(DiscussionAPIViewTestMixin, ModuleStoreTestCas

def setUp(self):
super().setUp()
httpretty.reset()
httpretty.enable()

self.course = CourseFactory.create()
patcher = mock.patch(
Expand Down Expand Up @@ -492,7 +485,6 @@ def test_new_comment_notification(self, is_subscribed):


@ddt.ddt
@httpretty.activate
@override_settings(ENABLE_DISCUSSION_SERVICE=True)
class TestNewThreadCreatedNotification(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
"""
Expand Down Expand Up @@ -693,8 +685,6 @@ class TestResponseEndorsedNotifications(DiscussionAPIViewTestMixin, ModuleStoreT

def setUp(self):
super().setUp()
httpretty.reset()
httpretty.enable()
self.set_mock_return_value('get_course_id_by_thread', str(self.course.id))
self.set_mock_return_value('get_course_id_by_comment', str(self.course.id))
self.user_1 = UserFactory.create()
Expand Down
14 changes: 1 addition & 13 deletions lms/djangoapps/discussion/rest_api/tests/test_views_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from unittest import mock

import ddt
import httpretty
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import override_settings
from django.urls import reverse
Expand All @@ -39,7 +38,6 @@
from lms.djangoapps.discussion.django_comment_client.tests.utils import config_course_discussions, topic_name_to_id
from lms.djangoapps.discussion.rest_api import api
from lms.djangoapps.discussion.rest_api.tests.utils import (
CommentsServiceMockMixin,
ForumMockUtilsMixin,
ProfileImageTestMixin,
make_minimal_cs_comment,
Expand Down Expand Up @@ -164,7 +162,6 @@ def test_inactive(self):


@ddt.ddt
@httpretty.activate
@disable_signal(api, "thread_edited")
@override_settings(ENABLE_DISCUSSION_SERVICE=True)
class ThreadViewSetPartialUpdateTest(
Expand Down Expand Up @@ -482,7 +479,6 @@ def test_closed_thread_error(self, field, value):


@ddt.ddt
@httpretty.activate
@override_settings(ENABLE_DISCUSSION_SERVICE=True)
class ThreadViewSetListTest(
DiscussionAPIViewTestMixin, ModuleStoreTestCase, ProfileImageTestMixin
Expand Down Expand Up @@ -1093,7 +1089,6 @@ def test_basic(self):


@ddt.ddt
@httpretty.activate
@mock.patch('django.conf.settings.USERNAME_REPLACEMENT_WORKER', 'test_replace_username_service_worker')
@override_settings(ENABLE_DISCUSSION_SERVICE=True)
class ReplaceUsernamesViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
Expand Down Expand Up @@ -1190,16 +1185,12 @@ def test_not_authenticated(self):

@ddt.ddt
@override_settings(ENABLE_DISCUSSION_SERVICE=True)
class CourseTopicsViewTest(DiscussionAPIViewTestMixin, CommentsServiceMockMixin, ModuleStoreTestCase):
class CourseTopicsViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
"""
Tests for CourseTopicsView
"""

def setUp(self):
httpretty.reset()
httpretty.enable()
self.addCleanup(httpretty.reset)
self.addCleanup(httpretty.disable)
super().setUp()
self.url = reverse("course_topics", kwargs={"course_id": str(self.course.id)})
self.thread_counts_map = {
Expand Down Expand Up @@ -1490,7 +1481,6 @@ def test_basic(self):


@ddt.ddt
@httpretty.activate
@override_settings(ENABLE_DISCUSSION_SERVICE=True)
class LearnerThreadViewAPITest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
"""Tests for LearnerThreadView list"""
Expand Down Expand Up @@ -1801,7 +1791,6 @@ def test_status_by(self, post_status):


@ddt.ddt
@httpretty.activate
@override_waffle_flag(ENABLE_DISCUSSIONS_MFE, True)
@override_settings(ENABLE_DISCUSSION_SERVICE=True)
class CourseActivityStatsTest(UrlResetMixin, ForumMockUtilsMixin, APITestCase,
Expand Down Expand Up @@ -1952,7 +1941,6 @@ def test_with_username_param_case(self, username_search_string):
assert response == (username_search_string.lower(), 1, 1)


@httpretty.activate
@override_settings(ENABLE_DISCUSSION_SERVICE=True)
class RetireViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
"""Tests for CourseView"""
Expand Down
25 changes: 10 additions & 15 deletions lms/djangoapps/verify_student/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,16 @@ def test_start_flow_not_verified(self, course_mode, payment_flow):
])
self._assert_upgrade_session_flag(False)

@httpretty.activate
@override_settings(
ECOMMERCE_API_URL=TEST_API_URL,
ECOMMERCE_PUBLIC_URL_ROOT=TEST_PUBLIC_URL_ROOT
)
def test_start_flow_with_ecommerce(self):
"""Verify user gets redirected to ecommerce checkout when ecommerce checkout is enabled."""
sku = 'TESTSKU'
# When passing a SKU ecommerce api gets called.
_mock_payment_processors()
configuration = CommerceConfiguration.objects.create(checkout_on_ecommerce_service=True)
checkout_page = configuration.basket_checkout_page
checkout_page += "?utm_source=test"
httpretty.register_uri(httpretty.GET, f"{TEST_PUBLIC_URL_ROOT}{checkout_page}")

course = self._create_course('verified', sku=sku)
self._enroll(course.id)
Expand Down Expand Up @@ -1191,7 +1187,6 @@ class TestCheckoutWithEcommerceService(ModuleStoreTestCase):
Ensures correct behavior in the function `checkout_with_ecommerce_service`.
"""

@httpretty.activate
@override_settings(ECOMMERCE_API_URL=TEST_API_URL)
def test_create_basket(self):
"""
Expand All @@ -1202,15 +1197,13 @@ def test_create_basket(self):
course_id = 'edX/test/test_run'
course_mode = CourseModeFactory.create(course_id=course_id, sku="test-sku").to_tuple()
expected_payment_data = {'foo': 'bar'}
# mock out the payment processors endpoint
httpretty.register_uri(
httpretty.POST,
f"{TEST_API_URL}/baskets/",
body=json.dumps({'payment_data': expected_payment_data}),
content_type="application/json",
)
# mock out the ecommerce API client's response to the baskets endpoint
mock_api_client = Mock()
mock_api_client.post.return_value.json.return_value = {'payment_data': expected_payment_data}

with mock.patch('lms.djangoapps.verify_student.views.audit_log') as mock_audit_log:
with mock.patch('lms.djangoapps.verify_student.views.audit_log') as mock_audit_log, \
mock.patch('lms.djangoapps.verify_student.views.get_ecommerce_api_client',
return_value=mock_api_client):
# Call the function
actual_payment_data = checkout_with_ecommerce_service(
user,
Expand All @@ -1223,8 +1216,10 @@ def test_create_basket(self):
assert mock_audit_log.called

# Check the api call
assert json.loads(httpretty.last_request().body.decode('utf-8')) ==\
{'products': [{'sku': 'test-sku'}], 'checkout': True, 'payment_processor_name': 'test-processor'}
mock_api_client.post.assert_called_once_with(
f"{TEST_API_URL}/baskets/",
json={'products': [{'sku': 'test-sku'}], 'checkout': True, 'payment_processor_name': 'test-processor'},
)
# Check the response
assert actual_payment_data == expected_payment_data

Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ constraint-dependencies = [
"numpy<2.0.0",
"openedx-core<2",
"path<16.12.0",
"pymongo<4.4.1",
"lxml==5.3.2",
"xmlsec==1.3.14",
"django-debug-toolbar<6.0.0",
Expand Down Expand Up @@ -340,10 +339,6 @@ uv_constraints = [
# needs to be investigated and fixed separately
# Issue for unpinning: https://github.com/openedx/edx-platform/issues/35267
"path<16.12.0",
# Date: 2020-04-08
# Adding pin to avoid any major upgrade
# Issue for unpinning: https://github.com/openedx/edx-platform/issues/35265
"pymongo<4.4.1",
# Date: 2024-08-06
# social-auth-app-django 5.4.2 introduces a new migration that will not play nicely with large installations. This will touch
# user tables, which are quite large, especially on instances like edx.org.
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ pylti1p3==2.0.0
# via openedx-platform
pymemcache==4.0.0
# via openedx-platform
pymongo==4.4.0
pymongo==4.19.0
# via
# edx-opaque-keys
# event-tracking
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ pylti1p3==2.0.0
# via openedx-platform
pymemcache==4.0.0
# via openedx-platform
pymongo==4.4.0
pymongo==4.19.0
# via
# edx-opaque-keys
# event-tracking
Expand Down
7 changes: 0 additions & 7 deletions scripts/structures_pruning/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,4 @@ constraint-dependencies = [
"social-auth-app-django<6.0.0",
"social-auth-core<5.0.0",
"pip<26.2.1",
"pymongo<4.4.1",
]
[tool.edx_lint]
# Adding pin to avoid any major upgrade -- see the root pyproject.toml's
# [tool.edx_lint].uv_constraints for the full rationale.
uv_constraints = [
"pymongo<4.4.1",
]
2 changes: 1 addition & 1 deletion scripts/structures_pruning/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dnspython==2.9.0
# via pymongo
edx-opaque-keys==4.0.1
# via edx-platform-structures-pruning-scripts
pymongo==4.4.0
pymongo==4.19.0
# via
# edx-opaque-keys
# edx-platform-structures-pruning-scripts
Expand Down
Loading
Loading