From 23503f5226aeec64dadeaa6e842f32a7f25763f0 Mon Sep 17 00:00:00 2001 From: bmedx Date: Fri, 15 Dec 2017 12:26:44 -0500 Subject: [PATCH] Fix test issues with new httpretty --- common/djangoapps/student/tests/test_refunds.py | 16 ---------------- .../commerce/api/v0/tests/test_views.py | 2 +- .../commerce/api/v1/tests/test_views.py | 2 +- lms/djangoapps/commerce/tests/mocks.py | 5 ++++- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/common/djangoapps/student/tests/test_refunds.py b/common/djangoapps/student/tests/test_refunds.py index ae521f3fb4..ecf0a513e6 100644 --- a/common/djangoapps/student/tests/test_refunds.py +++ b/common/djangoapps/student/tests/test_refunds.py @@ -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) diff --git a/lms/djangoapps/commerce/api/v0/tests/test_views.py b/lms/djangoapps/commerce/api/v0/tests/test_views.py index 35e9d18ba1..88608a09ef 100644 --- a/lms/djangoapps/commerce/api/v0/tests/test_views.py +++ b/lms/djangoapps/commerce/api/v0/tests/test_views.py @@ -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) diff --git a/lms/djangoapps/commerce/api/v1/tests/test_views.py b/lms/djangoapps/commerce/api/v1/tests/test_views.py index 027a890421..9252dcec40 100644 --- a/lms/djangoapps/commerce/api/v1/tests/test_views.py +++ b/lms/djangoapps/commerce/api/v1/tests/test_views.py @@ -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) diff --git a/lms/djangoapps/commerce/tests/mocks.py b/lms/djangoapps/commerce/tests/mocks.py index a42be0021d..a22cc69baf 100644 --- a/lms/djangoapps/commerce/tests/mocks.py +++ b/lms/djangoapps/commerce/tests/mocks.py @@ -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. """