Skip to content
Draft
9 changes: 1 addition & 8 deletions common/djangoapps/course_modes/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import ddt
import freezegun
import httpretty
from django.conf import settings
from django.test import override_settings
from django.urls import reverse
Expand All @@ -22,7 +21,6 @@
from common.djangoapps.util.testing import UrlResetMixin
from common.djangoapps.util.tests.mixins.discovery import CourseCatalogServiceMockMixin
from lms.djangoapps.commerce.tests import test_utils as ecomm_test_utils
from lms.djangoapps.commerce.tests.mocks import mock_payment_processors
from lms.djangoapps.verify_student.services import IDVerificationService
from openedx.core.djangoapps.catalog.tests.mixins import CatalogIntegrationMixin
from openedx.core.djangoapps.embargo.test_utils import restrict_course
Expand Down Expand Up @@ -63,7 +61,6 @@ def setUp(self):
self.client.login(username=self.user.username, password="edx")

@skip_unless_lms
@httpretty.activate
@ddt.data(
# is_active?, enrollment_mode, redirect?, has_started
(True, 'verified', True, False),
Expand Down Expand Up @@ -148,7 +145,6 @@ def test_no_id_redirect_otto(self):
self.assertRedirects(response, '/test_basket/add/?sku=TEST', fetch_redirect_response=False)
ecomm_test_utils.update_commerce_config(enabled=False)

@httpretty.activate
@ddt.data(
'',
'1,,2',
Expand Down Expand Up @@ -301,8 +297,7 @@ def test_choose_mode_redirect(self, course_mode, expected_redirect):
else:
self.fail("Must provide a valid redirect URL name")

with mock_payment_processors(expect_called=None):
self.assertRedirects(response, redirect_url, fetch_redirect_response=False,)
self.assertRedirects(response, redirect_url, fetch_redirect_response=False)

def test_choose_mode_audit_enroll_on_post(self):
audit_mode = 'audit'
Expand Down Expand Up @@ -456,7 +451,6 @@ def test_multiple_mode_creation(self):

@skip_unless_lms
@with_comprehensive_theme("edx.org")
@httpretty.activate
def test_hide_nav(self):
# Create the course modes
for mode in ["honor", "verified"]:
Expand Down Expand Up @@ -688,7 +682,6 @@ def test_embargo_restrict(self):
response = self.client.get(self.url)
self.assertRedirects(response, redirect_url)

@httpretty.activate
def test_embargo_allow(self):
response = self.client.get(self.url)
assert response.status_code == 200
40 changes: 20 additions & 20 deletions common/djangoapps/student/tests/test_refunds.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from zoneinfo import ZoneInfo

import ddt
import httpretty
import responses

# Explicitly import the cache from ConfigurationModel so we can reset it after each test
from config_models.models import cache
Expand Down Expand Up @@ -129,7 +129,7 @@ def test_refundable_with_cutoff_date(self, cutoff_date):
(timedelta(days=2), timedelta(days=1), timedelta(days=2), 1),
)
@ddt.unpack
@httpretty.activate
@responses.activate
@override_settings(ECOMMERCE_API_URL=TEST_API_URL)
def test_refund_cutoff_date(self, order_date_delta, course_start_delta, expected_date_delta, days):
"""
Expand All @@ -143,11 +143,11 @@ def test_refund_cutoff_date(self, order_date_delta, course_start_delta, expected
date_placed = order_date.strftime(ECOMMERCE_DATE_FORMAT)
expected_content = f'{{"date_placed": "{date_placed}"}}'

httpretty.register_uri(
httpretty.GET,
responses.add(
responses.GET,
f'{TEST_API_URL}/orders/{self.ORDER_NUMBER}/',
status=200, body=expected_content,
adding_headers={'Content-Type': JSON}
content_type=JSON
)

self.enrollment.course_overview.start = course_start
Expand Down Expand Up @@ -178,19 +178,19 @@ def test_refund_cutoff_date(self, order_date_delta, course_start_delta, expected
(datetime.now(ZoneInfo("UTC")) - timedelta(minutes=5), False),
)
@ddt.unpack
@httpretty.activate
@responses.activate
@override_settings(ECOMMERCE_API_URL=TEST_API_URL)
def test_is_order_voucher_refundable(self, voucher_expiration_date, expected):
"""
Assert that the correct value is returned based on voucher expiration date.
"""
voucher_expiration_date_str = voucher_expiration_date.strftime(ECOMMERCE_DATE_FORMAT)
response = json.dumps({"vouchers": [{"end_datetime": voucher_expiration_date_str}]})
httpretty.register_uri(
httpretty.GET,
responses.add(
responses.GET,
f'{TEST_API_URL}/orders/{self.ORDER_NUMBER}/',
status=200, body=response,
adding_headers={'Content-Type': JSON}
content_type=JSON
)

self.enrollment.attributes.create(
Expand All @@ -205,7 +205,7 @@ def test_refund_cutoff_date_no_attributes(self):
""" Assert that the None is returned when no order number attribute is found."""
assert self.enrollment.refund_cutoff_date() is None

@httpretty.activate
@responses.activate
@override_settings(ECOMMERCE_API_URL=TEST_API_URL)
def test_is_order_voucher_refundable_no_attributes(self, ):
""" Assert that False is returned when no order number or vouchers attribute is found in response."""
Expand All @@ -214,11 +214,11 @@ def test_is_order_voucher_refundable_no_attributes(self, ):

# no voucher information in orders api response
response = json.dumps({"vouchers": []})
httpretty.register_uri(
httpretty.GET,
responses.add(
responses.GET,
f'{TEST_API_URL}/orders/{self.ORDER_NUMBER}/',
status=200, body=response,
adding_headers={'Content-Type': JSON}
content_type=JSON
)

self.enrollment.attributes.create(
Expand All @@ -230,11 +230,11 @@ def test_is_order_voucher_refundable_no_attributes(self, ):
assert self.enrollment.is_order_voucher_refundable() is False

response = json.dumps({"vouchers": None})
httpretty.register_uri(
httpretty.GET,
responses.add(
responses.GET,
f'{TEST_API_URL}/orders/{self.ORDER_NUMBER}/',
status=200, body=response,
adding_headers={'Content-Type': JSON}
content_type=JSON
)
assert self.enrollment.is_order_voucher_refundable() is False

Expand Down Expand Up @@ -279,19 +279,19 @@ def test_refund_cutoff_date_with_date_placed_attr(self, mock_ecommerce_api_clien
assert self.enrollment.refund_cutoff_date() == (order_date + refund_config.refund_window)
mock_ecommerce_api_client.assert_not_called()

@httpretty.activate
@responses.activate
@override_settings(ECOMMERCE_API_URL=TEST_API_URL)
def test_multiple_refunds_dashbaord_page_error(self):
""" Order with mutiple refunds will not throw 500 error when dashboard page will access."""
now = datetime.now(ZoneInfo("UTC")).replace(microsecond=0)
order_date = now + timedelta(days=1)
expected_content = f'{{"date_placed": "{order_date.strftime(ECOMMERCE_DATE_FORMAT)}"}}'

httpretty.register_uri(
httpretty.GET,
responses.add(
responses.GET,
f'{TEST_API_URL}/orders/{self.ORDER_NUMBER}/',
status=200, body=expected_content,
adding_headers={'Content-Type': JSON}
content_type=JSON
)

# creating multiple attributes for same order.
Expand Down
Loading
Loading