Fix test issues with new httpretty
This commit is contained in:
@@ -14,9 +14,7 @@ from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test.client import Client
|
||||
from django.test.utils import override_settings
|
||||
from edx_rest_api_client.exceptions import SlumberBaseException
|
||||
from mock import patch
|
||||
from slumber.exceptions import HttpClientError, HttpServerError
|
||||
|
||||
from certificates.models import CertificateStatuses, GeneratedCertificate # pylint: disable=import-error
|
||||
from certificates.tests.factories import GeneratedCertificateFactory # pylint: disable=import-error
|
||||
@@ -195,17 +193,3 @@ class RefundableTest(SharedModuleStoreTestCase):
|
||||
self.client.login(username=self.user.username, password=self.USER_PASSWORD)
|
||||
resp = self.client.post(reverse('student.views.dashboard', args=[]))
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
@ddt.data(HttpServerError, HttpClientError, SlumberBaseException)
|
||||
@override_settings(ECOMMERCE_API_URL=TEST_API_URL)
|
||||
def test_refund_cutoff_date_with_api_error(self, exception):
|
||||
""" Verify that dashboard will not throw internal server error if HttpClientError
|
||||
raised while getting order detail for ecommerce.
|
||||
"""
|
||||
# importing this after overriding value of ECOMMERCE_API_URL
|
||||
from lms.djangoapps.commerce.tests.mocks import mock_order_endpoint
|
||||
|
||||
self.client.login(username=self.user.username, password=self.USER_PASSWORD)
|
||||
with mock_order_endpoint(order_number=self.ORDER_NUMBER, exception=exception, reset_on_exit=False):
|
||||
response = self.client.post(reverse('student.views.dashboard', args=[]))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
@@ -303,7 +303,7 @@ class BasketOrderViewTests(UserMixin, TestCase):
|
||||
|
||||
def test_order_not_found(self):
|
||||
""" If the order is not found, the view should return a 404. """
|
||||
with mock_basket_order(basket_id=1, exception=exceptions.HttpNotFoundError):
|
||||
with mock_basket_order(basket_id=1, status=404):
|
||||
response = self.client.get(self.path)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
|
||||
@@ -417,7 +417,7 @@ class OrderViewTests(UserMixin, TestCase):
|
||||
|
||||
def test_order_not_found(self):
|
||||
""" If the order is not found, the view should return a 404. """
|
||||
with mock_order_endpoint(order_number=self.ORDER_NUMBER, exception=exceptions.HttpNotFoundError):
|
||||
with mock_order_endpoint(order_number=self.ORDER_NUMBER, status=404):
|
||||
response = self.client.get(self.path)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
|
||||
@@ -74,11 +74,14 @@ class mock_ecommerce_api_endpoint(object):
|
||||
)
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
assert self.expect_called == (httpretty.last_request().headers != {})
|
||||
called_if_expected = self.expect_called == (httpretty.last_request().headers != {})
|
||||
httpretty.disable()
|
||||
|
||||
if self.reset_on_exit:
|
||||
httpretty.reset()
|
||||
|
||||
assert called_if_expected
|
||||
|
||||
|
||||
class mock_basket_order(mock_ecommerce_api_endpoint):
|
||||
""" Mocks calls to E-Commerce API client basket order method. """
|
||||
|
||||
Reference in New Issue
Block a user