Commit fe713dbb by Clinton Blackburn

Test Cleanup

Numerous test issues have been fixed in preparation for running tests with MySQL.

ECOM-7111
parent 9586c9d6
...@@ -98,18 +98,23 @@ class UserTests(CourseCatalogTestMixin, LmsApiMockMixin, TestCase): ...@@ -98,18 +98,23 @@ class UserTests(CourseCatalogTestMixin, LmsApiMockMixin, TestCase):
user = self.create_user() user = self.create_user()
user_details = {'is_active': True} user_details = {'is_active': True}
self.mock_account_api(self.request, user.username, data=user_details) self.mock_account_api(self.request, user.username, data=user_details)
self.mock_access_token_response()
self.assertDictEqual(user.account_details(self.request), user_details) self.assertDictEqual(user.account_details(self.request), user_details)
@httpretty.activate
def test_user_details_uses_jwt(self): def test_user_details_uses_jwt(self):
"""Verify user_details uses jwt from site configuration to call EdxRestApiClient.""" """Verify user_details uses jwt from site configuration to call EdxRestApiClient."""
user = self.create_user() user = self.create_user()
with mock.patch("ecommerce.core.models.EdxRestApiClient") as patched_info: user_details = {'is_active': True}
user.account_details(self.request) self.mock_account_api(self.request, user.username, data=user_details)
patched_info.assert_called_once_with( token = self.mock_access_token_response()
self.request.site.siteconfiguration.build_lms_url('/api/user/v1'),
append_slash=False, user.account_details(self.request)
jwt=self.request.site.siteconfiguration.access_token last_request = httpretty.last_request()
)
# Verify the headers passed to the API were correct.
expected = {'Authorization': 'JWT {}'.format(token), }
self.assertDictContainsSubset(expected, last_request.headers)
def test_no_user_details(self): def test_no_user_details(self):
""" Verify False is returned when there is a connection error. """ """ Verify False is returned when there is a connection error. """
...@@ -183,6 +188,8 @@ class UserTests(CourseCatalogTestMixin, LmsApiMockMixin, TestCase): ...@@ -183,6 +188,8 @@ class UserTests(CourseCatalogTestMixin, LmsApiMockMixin, TestCase):
user = self.create_user() user = self.create_user()
expected_response = {'user_deactivated': True} expected_response = {'user_deactivated': True}
self.mock_deactivation_api(self.request, user.username, response=json.dumps(expected_response)) self.mock_deactivation_api(self.request, user.username, response=json.dumps(expected_response))
self.mock_access_token_response()
self.assertEqual(user.deactivate_account(self.request.site.siteconfiguration), expected_response) self.assertEqual(user.deactivate_account(self.request.site.siteconfiguration), expected_response)
def test_deactivation_exception_handling(self): def test_deactivation_exception_handling(self):
......
...@@ -9,7 +9,7 @@ from django.core.urlresolvers import reverse ...@@ -9,7 +9,7 @@ from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponse, HttpResponseRedirect from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext as _
from django.shortcuts import render from django.shortcuts import render
from django.utils import timezone from django.utils import timezone
from django.views.generic import TemplateView, View from django.views.generic import TemplateView, View
......
...@@ -13,9 +13,6 @@ ProductRecord = get_model('analytics', 'ProductRecord') ...@@ -13,9 +13,6 @@ ProductRecord = get_model('analytics', 'ProductRecord')
class AnalyticsTests(BasketCreationMixin, TestCase): class AnalyticsTests(BasketCreationMixin, TestCase):
"""Test analytics behavior in controlled scenarios.""" """Test analytics behavior in controlled scenarios."""
def setUp(self):
super(AnalyticsTests, self).setUp()
@override_settings(INSTALL_DEFAULT_ANALYTICS_RECEIVERS=False) @override_settings(INSTALL_DEFAULT_ANALYTICS_RECEIVERS=False)
def test_order_receiver_disabled(self): def test_order_receiver_disabled(self):
"""Verify that Oscar's Analytics order receiver can be disabled.""" """Verify that Oscar's Analytics order receiver can be disabled."""
......
...@@ -36,10 +36,10 @@ LOGGER_NAME = 'ecommerce.extensions.api.v2.views.baskets' ...@@ -36,10 +36,10 @@ LOGGER_NAME = 'ecommerce.extensions.api.v2.views.baskets'
) )
# Why TransactionTestCase? See http://stackoverflow.com/a/23326971. # Why TransactionTestCase? See http://stackoverflow.com/a/23326971.
class BasketCreateViewTests(BasketCreationMixin, ThrottlingMixin, TransactionTestCase): class BasketCreateViewTests(BasketCreationMixin, ThrottlingMixin, TransactionTestCase):
FREE_SKU = u'𝑭𝑹𝑬𝑬-𝑷𝑹𝑶𝑫𝑼𝑪𝑻' FREE_SKU = 'FREE_PRODUCT'
PAID_SKU = u'𝑷𝑨𝑰𝑫-𝑷𝑹𝑶𝑫𝑼𝑪𝑻' PAID_SKU = 'PAID_PRODUCT'
ALTERNATE_FREE_SKU = u'𝑨𝑳𝑻𝑬𝑹𝑵𝑨𝑻𝑬-𝑭𝑹𝑬𝑬-𝑷𝑹𝑶𝑫𝑼𝑪𝑻' ALTERNATE_FREE_SKU = 'ALTERNATE_FREE_PRODUCT'
ALTERNATE_PAID_SKU = u'𝑨𝑳𝑻𝑬𝑹𝑵𝑨𝑻𝑬-𝑷𝑨𝑰𝑫-𝑷𝑹𝑶𝑫𝑼𝑪𝑻' ALTERNATE_PAID_SKU = 'ALTERNATE_PAID_PRODUCT'
BAD_SKU = 'not-a-sku' BAD_SKU = 'not-a-sku'
UNAVAILABLE = False UNAVAILABLE = False
UNAVAILABLE_MESSAGE = 'Unavailable' UNAVAILABLE_MESSAGE = 'Unavailable'
...@@ -51,7 +51,7 @@ class BasketCreateViewTests(BasketCreationMixin, ThrottlingMixin, TransactionTes ...@@ -51,7 +51,7 @@ class BasketCreateViewTests(BasketCreationMixin, ThrottlingMixin, TransactionTes
self.paid_product = factories.ProductFactory( self.paid_product = factories.ProductFactory(
structure='child', structure='child',
parent=self.base_product, parent=self.base_product,
title=u'𝐋𝐏 𝟓𝟔𝟎-𝟒', title='LP 560-4',
stockrecords__partner_sku=self.PAID_SKU, stockrecords__partner_sku=self.PAID_SKU,
stockrecords__price_excl_tax=Decimal('180000.00'), stockrecords__price_excl_tax=Decimal('180000.00'),
stockrecords__partner__short_code='oscr', stockrecords__partner__short_code='oscr',
...@@ -67,7 +67,7 @@ class BasketCreateViewTests(BasketCreationMixin, ThrottlingMixin, TransactionTes ...@@ -67,7 +67,7 @@ class BasketCreateViewTests(BasketCreationMixin, ThrottlingMixin, TransactionTes
factories.ProductFactory( factories.ProductFactory(
structure='child', structure='child',
parent=self.base_product, parent=self.base_product,
title=u'𝐋𝐏 𝟓𝟕𝟎-𝟒 𝐒𝐮𝐩𝐞𝐫𝐥𝐞𝐠𝐠𝐞𝐫𝐚', title='LP 570-4 Superleggera',
stockrecords__partner_sku=self.ALTERNATE_PAID_SKU, stockrecords__partner_sku=self.ALTERNATE_PAID_SKU,
stockrecords__price_excl_tax=Decimal('240000.00'), stockrecords__price_excl_tax=Decimal('240000.00'),
stockrecords__partner__short_code='dummy', stockrecords__partner__short_code='dummy',
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import json
import datetime import datetime
import json
from decimal import Decimal from decimal import Decimal
from uuid import uuid4 from uuid import uuid4
...@@ -24,7 +24,7 @@ from ecommerce.extensions.api.v2.views.coupons import CouponViewSet ...@@ -24,7 +24,7 @@ from ecommerce.extensions.api.v2.views.coupons import CouponViewSet
from ecommerce.extensions.catalogue.tests.mixins import CourseCatalogTestMixin from ecommerce.extensions.catalogue.tests.mixins import CourseCatalogTestMixin
from ecommerce.extensions.voucher.models import CouponVouchers from ecommerce.extensions.voucher.models import CouponVouchers
from ecommerce.invoice.models import Invoice from ecommerce.invoice.models import Invoice
from ecommerce.tests.factories import ProductFactory, SiteConfigurationFactory, SiteFactory from ecommerce.tests.factories import ProductFactory, SiteConfigurationFactory
from ecommerce.tests.mixins import ThrottlingMixin from ecommerce.tests.mixins import ThrottlingMixin
from ecommerce.tests.testcases import TestCase from ecommerce.tests.testcases import TestCase
...@@ -88,12 +88,6 @@ class CouponViewSetTest(CouponMixin, CourseCatalogTestMixin, TestCase): ...@@ -88,12 +88,6 @@ class CouponViewSetTest(CouponMixin, CourseCatalogTestMixin, TestCase):
request.COOKIES = {} request.COOKIES = {}
return request return request
def setup_site_configuration(self):
site_configuration = SiteConfigurationFactory(partner__name='TestX')
site = SiteFactory()
site.siteconfiguration = site_configuration
return site
def test_create(self): def test_create(self):
"""Test the create method.""" """Test the create method."""
max_uses = 2 max_uses = 2
...@@ -115,12 +109,17 @@ class CouponViewSetTest(CouponMixin, CourseCatalogTestMixin, TestCase): ...@@ -115,12 +109,17 @@ class CouponViewSetTest(CouponMixin, CourseCatalogTestMixin, TestCase):
response = view.create(request) response = view.create(request)
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
coupon = Product.objects.get(title=title)
basket = Basket.objects.last()
order = Order.objects.last()
self.assertDictEqual( self.assertDictEqual(
response.data, response.data,
{'payment_data': {'payment_processor_name': 'Invoice'}, 'id': 1, 'order': 1, 'coupon_id': 3} {'payment_data': {'payment_processor_name': 'Invoice'}, 'id': basket.id, 'order': order.id,
'coupon_id': coupon.id}
) )
coupon = Product.objects.get(title=title)
self.assertEqual( self.assertEqual(
coupon.attr.coupon_vouchers.vouchers.first().offers.first().max_global_applications, coupon.attr.coupon_vouchers.vouchers.first().offers.first().max_global_applications,
max_uses max_uses
...@@ -246,16 +245,18 @@ class CouponViewSetTest(CouponMixin, CourseCatalogTestMixin, TestCase): ...@@ -246,16 +245,18 @@ class CouponViewSetTest(CouponMixin, CourseCatalogTestMixin, TestCase):
def test_create_order(self): def test_create_order(self):
"""Test the order creation.""" """Test the order creation."""
self.create_coupon(partner=self.partner) coupon = self.create_coupon(partner=self.partner)
order = Order.objects.first()
self.assertEqual(Order.objects.count(), 1)
self.assertDictEqual( self.assertDictEqual(
self.response_data, self.response_data,
{'payment_data': {'payment_processor_name': 'Invoice'}, 'id': 1, 'order': 1, 'coupon_id': 3} {'payment_data': {'payment_processor_name': 'Invoice'}, 'id': self.basket.id, 'order': order.id,
'coupon_id': coupon.id}
) )
self.assertEqual(Order.objects.count(), 1) self.assertEqual(order.status, 'Complete')
self.assertEqual(Order.objects.first().status, 'Complete') self.assertEqual(order.total_incl_tax, 100)
self.assertEqual(Order.objects.first().total_incl_tax, 100)
self.assertEqual(Basket.objects.first().status, 'Submitted') self.assertEqual(Basket.objects.first().status, 'Submitted')
def test_create_update_data_dict(self): def test_create_update_data_dict(self):
...@@ -283,7 +284,7 @@ class CouponViewSetTest(CouponMixin, CourseCatalogTestMixin, TestCase): ...@@ -283,7 +284,7 @@ class CouponViewSetTest(CouponMixin, CourseCatalogTestMixin, TestCase):
self.assertEqual(coupon_voucher_qs.first().vouchers.count(), 5) self.assertEqual(coupon_voucher_qs.first().vouchers.count(), 5)
request = RequestFactory() request = RequestFactory()
request.site = self.setup_site_configuration() request.site = SiteConfigurationFactory().site
response = CouponViewSet().destroy(request, coupon.id) response = CouponViewSet().destroy(request, coupon.id)
self.assertEqual(Product.objects.filter(product_class=self.coupon_product_class).count(), 0) self.assertEqual(Product.objects.filter(product_class=self.coupon_product_class).count(), 0)
...@@ -306,8 +307,10 @@ class CouponViewSetFunctionalTest(CouponMixin, CourseCatalogTestMixin, CourseCat ...@@ -306,8 +307,10 @@ class CouponViewSetFunctionalTest(CouponMixin, CourseCatalogTestMixin, CourseCat
super(CouponViewSetFunctionalTest, self).setUp() super(CouponViewSetFunctionalTest, self).setUp()
self.user = self.create_user(is_staff=True) self.user = self.create_user(is_staff=True)
self.client.login(username=self.user.username, password=self.password) self.client.login(username=self.user.username, password=self.password)
self.create_course_and_seat(course_id='edx/Demo_Course1/DemoX', price=50)
self.create_course_and_seat(course_id='edx/Demo_Course2/DemoX', price=100) __, seat = self.create_course_and_seat(course_id='edx/Demo_Course1/DemoX', price=50)
__, other_seat = self.create_course_and_seat(course_id='edx/Demo_Course2/DemoX', price=100)
self.data = { self.data = {
'benefit_type': Benefit.PERCENTAGE, 'benefit_type': Benefit.PERCENTAGE,
'benefit_value': 100, 'benefit_value': 100,
...@@ -319,7 +322,7 @@ class CouponViewSetFunctionalTest(CouponMixin, CourseCatalogTestMixin, CourseCat ...@@ -319,7 +322,7 @@ class CouponViewSetFunctionalTest(CouponMixin, CourseCatalogTestMixin, CourseCat
'price': 100, 'price': 100,
'quantity': 2, 'quantity': 2,
'start_datetime': str(now() - datetime.timedelta(days=10)), 'start_datetime': str(now() - datetime.timedelta(days=10)),
'stock_record_ids': [1, 2], 'stock_record_ids': [seat.stockrecords.first().id, other_seat.stockrecords.first().id],
'title': 'Tešt čoupon', 'title': 'Tešt čoupon',
'voucher_type': Voucher.SINGLE_USE, 'voucher_type': Voucher.SINGLE_USE,
} }
...@@ -429,12 +432,18 @@ class CouponViewSetFunctionalTest(CouponMixin, CourseCatalogTestMixin, CourseCat ...@@ -429,12 +432,18 @@ class CouponViewSetFunctionalTest(CouponMixin, CourseCatalogTestMixin, CourseCat
def test_response(self): def test_response(self):
"""Test the response data given after the order was created.""" """Test the response data given after the order was created."""
basket = Basket.objects.last()
order = Order.objects.last()
self.assertEqual(self.response.status_code, status.HTTP_200_OK) self.assertEqual(self.response.status_code, status.HTTP_200_OK)
response_data = json.loads(self.response.content) response_data = json.loads(self.response.content)
self.assertDictEqual( expected = {
response_data, 'payment_data': {'payment_processor_name': 'Invoice'},
{'payment_data': {'payment_processor_name': 'Invoice'}, 'id': 1, 'order': 1, 'coupon_id': 5} 'id': basket.id,
) 'order': order.id,
'coupon_id': self.coupon.id
}
self.assertDictEqual(response_data, expected)
def test_order(self): def test_order(self):
"""Test the order data after order creation.""" """Test the order data after order creation."""
......
...@@ -61,8 +61,6 @@ class UtilsTests(CourseCatalogTestMixin, TestCase): ...@@ -61,8 +61,6 @@ class UtilsTests(CourseCatalogTestMixin, TestCase):
stock_record = self.seat.stockrecords.first() stock_record = self.seat.stockrecords.first()
self.catalog.stock_records.add(stock_record) self.catalog.stock_records.add(stock_record)
self.assertEqual(self.catalog.id, 1)
existing_catalog, created = get_or_create_catalog( existing_catalog, created = get_or_create_catalog(
name='Test', name='Test',
partner=self.partner, partner=self.partner,
...@@ -154,12 +152,11 @@ class CouponCreationTests(CouponMixin, TestCase): ...@@ -154,12 +152,11 @@ class CouponCreationTests(CouponMixin, TestCase):
def test_coupon_note(self): def test_coupon_note(self):
"""Test creating a coupon with a note.""" """Test creating a coupon with a note."""
note_coupon = self.create_custom_coupon( note = 'Ñote'
note='𝑵𝑶𝑻𝑬', title = 'Coupon'
title='Coupon', note_coupon = self.create_custom_coupon(note=note, title=title)
) self.assertEqual(note_coupon.attr.note, note)
self.assertEqual(note_coupon.attr.note, '𝑵𝑶𝑻𝑬') self.assertEqual(note_coupon.title, title)
self.assertEqual(note_coupon.title, 'Coupon')
def test_custom_code_string(self): def test_custom_code_string(self):
"""Test creating a coupon with custom voucher code.""" """Test creating a coupon with custom voucher code."""
......
...@@ -195,7 +195,7 @@ class EdxOrderPlacementMixinTests(BusinessIntelligenceMixin, PaymentEventsMixin, ...@@ -195,7 +195,7 @@ class EdxOrderPlacementMixinTests(BusinessIntelligenceMixin, PaymentEventsMixin,
with patch('ecommerce.extensions.checkout.mixins.fulfill_order.delay') as mock_delay: with patch('ecommerce.extensions.checkout.mixins.fulfill_order.delay') as mock_delay:
EdxOrderPlacementMixin().handle_successful_order(self.order) EdxOrderPlacementMixin().handle_successful_order(self.order)
self.assertTrue(mock_delay.called) self.assertTrue(mock_delay.called)
mock_delay.assert_called_once_with(self.order.number, site_code='edX') mock_delay.assert_called_once_with(self.order.number, site_code=self.partner.short_code)
def test_place_free_order(self, __): def test_place_free_order(self, __):
""" Verify an order is placed and the basket is submitted. """ """ Verify an order is placed and the basket is submitted. """
......
...@@ -239,6 +239,7 @@ class OrderDetailViewTests(DashboardViewTestMixin, OrderViewTestsMixin, RefundTe ...@@ -239,6 +239,7 @@ class OrderDetailViewTests(DashboardViewTestMixin, OrderViewTestsMixin, RefundTe
class OrderDetailViewBrowserTests(OrderViewTestsMixin, RefundTestMixin, OrderViewBrowserTestBase): class OrderDetailViewBrowserTests(OrderViewTestsMixin, RefundTestMixin, OrderViewBrowserTestBase):
@skipIf(os.environ.get('TRAVIS'), 'This test consistently fails on Travis.')
@override_settings(FULFILLMENT_MODULES=['ecommerce.extensions.fulfillment.tests.modules.FakeFulfillmentModule', ]) @override_settings(FULFILLMENT_MODULES=['ecommerce.extensions.fulfillment.tests.modules.FakeFulfillmentModule', ])
def test_retry_fulfillment(self): def test_retry_fulfillment(self):
""" """
......
...@@ -118,20 +118,22 @@ class CybersourceMixin(PaymentEventsMixin): ...@@ -118,20 +118,22 @@ class CybersourceMixin(PaymentEventsMixin):
with LogCapture(logger_name) as l: with LogCapture(logger_name) as l:
self.client.post(self.path, notification) self.client.post(self.path, notification)
self.assert_processor_response_recorded( ppr_id = self.assert_processor_response_recorded(
self.processor_name, self.processor_name,
notification[u'transaction_id'], notification['transaction_id'],
notification, notification,
basket=self.basket basket=self.basket
) )
error_message = error_message.format(basket_id=self.basket.id, response_id=ppr_id)
l.check( l.check(
( (
logger_name, logger_name,
'INFO', 'INFO',
'Received CyberSource merchant notification for transaction [{transaction_id}], ' 'Received CyberSource merchant notification for transaction [{transaction_id}], '
'associated with basket [{basket_id}].'.format( 'associated with basket [{basket_id}].'.format(
transaction_id=notification[u'transaction_id'], transaction_id=notification['transaction_id'],
basket_id=self.basket.id basket_id=self.basket.id
) )
), ),
...@@ -401,7 +403,7 @@ class CybersourceNotificationTestsMixin(CybersourceMixin): ...@@ -401,7 +403,7 @@ class CybersourceNotificationTestsMixin(CybersourceMixin):
with mock.patch.object(self.view, 'handle_payment', side_effect=error_class) as fake_handle_payment: with mock.patch.object(self.view, 'handle_payment', side_effect=error_class) as fake_handle_payment:
self._assert_processing_failure( self._assert_processing_failure(
notification, notification,
error_message.format(basket_id=self.basket.id, response_id=1), error_message,
log_level log_level
) )
self.assertTrue(fake_handle_payment.called) self.assertTrue(fake_handle_payment.called)
......
...@@ -42,9 +42,7 @@ class PaymentProcessorTestCaseMixin(RefundTestMixin, CourseCatalogTestMixin, Pay ...@@ -42,9 +42,7 @@ class PaymentProcessorTestCaseMixin(RefundTestMixin, CourseCatalogTestMixin, Pay
def test_configuration(self): def test_configuration(self):
""" Verifies configuration is read from settings. """ """ Verifies configuration is read from settings. """
other_site = SiteConfigurationFactory(partner__name='other').site other_site = SiteConfigurationFactory(partner__short_code='other').site
self.assertEqual(self.site.siteconfiguration.partner.short_code, 'edX')
self.assertEqual(other_site.siteconfiguration.partner.short_code, 'other')
for site in (self.site, other_site): for site in (self.site, other_site):
processor = self.processor_class(site) # pylint: disable=not-callable processor = self.processor_class(site) # pylint: disable=not-callable
......
...@@ -42,7 +42,7 @@ class SDNCheckTests(TestCase): ...@@ -42,7 +42,7 @@ class SDNCheckTests(TestCase):
def setUp(self): def setUp(self):
super(SDNCheckTests, self).setUp() super(SDNCheckTests, self).setUp()
self.name = 'Dr. Evil' self.name = 'Dr. Evil'
self.country = 'Evilland' self.country = 'EL'
self.user = self.create_user(full_name=self.name) self.user = self.create_user(full_name=self.name)
self.site_configuration = self.site.siteconfiguration self.site_configuration = self.site.siteconfiguration
self.site_configuration.enable_sdn_check = True, self.site_configuration.enable_sdn_check = True,
......
import factory
from oscar.test.factories import BasketFactory
from ecommerce.referrals.models import Referral
from ecommerce.tests.factories import SiteFactory
class ReferralFactory(factory.DjangoModelFactory):
class Meta(object):
model = Referral
basket = factory.SubFactory(BasketFactory)
site = factory.SubFactory(SiteFactory)
from __future__ import unicode_literals from __future__ import unicode_literals
from StringIO import StringIO
from django.contrib.sites.models import Site import six
from django.core.management import call_command, CommandError from django.core.management import call_command, CommandError
from ecommerce.referrals.models import Referral from ecommerce.referrals.models import Referral
from ecommerce.referrals.tests.factories import ReferralFactory
from ecommerce.tests.testcases import TestCase from ecommerce.tests.testcases import TestCase
...@@ -13,10 +13,7 @@ class AddSiteToReferralsCommandTests(TestCase): ...@@ -13,10 +13,7 @@ class AddSiteToReferralsCommandTests(TestCase):
def setUp(self): def setUp(self):
super(AddSiteToReferralsCommandTests, self).setUp() super(AddSiteToReferralsCommandTests, self).setUp()
self.site = Site.objects.create(domain='acme.fake') self.unassociated_referrals = ReferralFactory.create_batch(3, site=None)
site = Site.objects.create(domain='test.fake')
self.associated_referrals = [Referral.objects.create(basket_id=i, site=site) for i in range(0, 2)]
self.unassociated_referrals = [Referral.objects.create(basket_id=i) for i in range(3, 6)]
def test_without_commit(self): def test_without_commit(self):
""" Verify the command does not modify any referrals, if the commit flag is not specified. """ """ Verify the command does not modify any referrals, if the commit flag is not specified. """
...@@ -24,7 +21,7 @@ class AddSiteToReferralsCommandTests(TestCase): ...@@ -24,7 +21,7 @@ class AddSiteToReferralsCommandTests(TestCase):
expected = queryset.count() expected = queryset.count()
# Call the command with dry-run flag # Call the command with dry-run flag
out = StringIO() out = six.StringIO()
call_command(self.command, site_id=self.site.id, commit=False, stdout=out) call_command(self.command, site_id=self.site.id, commit=False, stdout=out)
# Verify no referrals affected # Verify no referrals affected
...@@ -49,7 +46,7 @@ class AddSiteToReferralsCommandTests(TestCase): ...@@ -49,7 +46,7 @@ class AddSiteToReferralsCommandTests(TestCase):
self.assertEqual(queryset.count(), 0) self.assertEqual(queryset.count(), 0)
# Call the command # Call the command
out = StringIO() out = six.StringIO()
call_command(self.command, site_id=self.site.id, commit=True, stdout=out) call_command(self.command, site_id=self.site.id, commit=True, stdout=out)
# The referrals should be associated with the site # The referrals should be associated with the site
......
...@@ -13,7 +13,7 @@ class PartnerFactory(factory.DjangoModelFactory): ...@@ -13,7 +13,7 @@ class PartnerFactory(factory.DjangoModelFactory):
django_get_or_create = ('name',) django_get_or_create = ('name',)
name = FuzzyText(prefix='test-partner-') name = FuzzyText(prefix='test-partner-')
short_code = factory.SelfAttribute('name') short_code = FuzzyText(length=8)
class SiteFactory(factory.DjangoModelFactory): class SiteFactory(factory.DjangoModelFactory):
......
...@@ -94,7 +94,7 @@ class JwtMixin(object): ...@@ -94,7 +94,7 @@ class JwtMixin(object):
class BasketCreationMixin(UserMixin, JwtMixin): class BasketCreationMixin(UserMixin, JwtMixin):
"""Provides utility methods for creating baskets in test cases.""" """Provides utility methods for creating baskets in test cases."""
PATH = reverse('api:v2:baskets:create') PATH = reverse('api:v2:baskets:create')
FREE_SKU = u'𝑭𝑹𝑬𝑬-𝑷𝑹𝑶𝑫𝑼𝑪𝑻' FREE_SKU = 'FREE_PRODUCT'
def setUp(self): def setUp(self):
super(BasketCreationMixin, self).setUp() super(BasketCreationMixin, self).setUp()
...@@ -102,20 +102,20 @@ class BasketCreationMixin(UserMixin, JwtMixin): ...@@ -102,20 +102,20 @@ class BasketCreationMixin(UserMixin, JwtMixin):
self.user = self.create_user() self.user = self.create_user()
product_class = factories.ProductClassFactory( product_class = factories.ProductClassFactory(
name=u'𝑨𝒖𝒕𝒐𝒎𝒐𝒃𝒊𝒍𝒆', name=u'Áutomobilé',
requires_shipping=False, requires_shipping=False,
track_stock=False track_stock=False
) )
self.base_product = factories.ProductFactory( self.base_product = factories.ProductFactory(
structure='parent', structure='parent',
title=u'𝑳𝒂𝒎𝒃𝒐𝒓𝒈𝒉𝒊𝒏𝒊 𝑮𝒂𝒍𝒍𝒂𝒓𝒅𝒐', title=u'Lamborghinï Gallardœ',
product_class=product_class, product_class=product_class,
stockrecords=None, stockrecords=None,
) )
self.free_product = factories.ProductFactory( self.free_product = factories.ProductFactory(
structure='child', structure='child',
parent=self.base_product, parent=self.base_product,
title=u'𝑪𝒂𝒓𝒅𝒃𝒐𝒂𝒓𝒅 𝑪𝒖𝒕𝒐𝒖𝒕', title='Cardboard Cutout',
stockrecords__partner_sku=self.FREE_SKU, stockrecords__partner_sku=self.FREE_SKU,
stockrecords__price_excl_tax=Decimal('0.00'), stockrecords__price_excl_tax=Decimal('0.00'),
) )
...@@ -259,6 +259,7 @@ class SiteMixin(object): ...@@ -259,6 +259,7 @@ class SiteMixin(object):
'SOCIAL_AUTH_EDX_OIDC_SECRET': 'secret' 'SOCIAL_AUTH_EDX_OIDC_SECRET': 'secret'
}, },
partner__name='edX', partner__name='edX',
partner__short_code='edx',
segment_key='fake_segment_key', segment_key='fake_segment_key',
site__domain=domain, site__domain=domain,
site__id=settings.SITE_ID, site__id=settings.SITE_ID,
......
from django.test import (TestCase as DjangoTestCase, from django.core.cache import cache
LiveServerTestCase as DjangoLiveServerTestCase, from django.test import (
TransactionTestCase as DjangoTransactionTestCase) TestCase as DjangoTestCase,
LiveServerTestCase as DjangoLiveServerTestCase,
TransactionTestCase as DjangoTransactionTestCase
)
from ecommerce.tests.mixins import SiteMixin, UserMixin, TestServerUrlMixin from ecommerce.tests.mixins import SiteMixin, UserMixin, TestServerUrlMixin
class TestCase(TestServerUrlMixin, UserMixin, SiteMixin, DjangoTestCase): class CacheMixin(object):
def setUp(self):
cache.clear()
super(CacheMixin, self).setUp()
def tearDown(self):
cache.clear()
super(CacheMixin, self).tearDown()
class TestCase(TestServerUrlMixin, UserMixin, SiteMixin, CacheMixin, DjangoTestCase):
""" """
Base test case for ecommerce tests. Base test case for ecommerce tests.
...@@ -14,7 +27,7 @@ class TestCase(TestServerUrlMixin, UserMixin, SiteMixin, DjangoTestCase): ...@@ -14,7 +27,7 @@ class TestCase(TestServerUrlMixin, UserMixin, SiteMixin, DjangoTestCase):
pass pass
class LiveServerTestCase(TestServerUrlMixin, UserMixin, SiteMixin, DjangoLiveServerTestCase): class LiveServerTestCase(TestServerUrlMixin, UserMixin, SiteMixin, CacheMixin, DjangoLiveServerTestCase):
""" """
Base test case for ecommerce tests. Base test case for ecommerce tests.
...@@ -23,7 +36,7 @@ class LiveServerTestCase(TestServerUrlMixin, UserMixin, SiteMixin, DjangoLiveSer ...@@ -23,7 +36,7 @@ class LiveServerTestCase(TestServerUrlMixin, UserMixin, SiteMixin, DjangoLiveSer
pass pass
class TransactionTestCase(TestServerUrlMixin, UserMixin, SiteMixin, DjangoTransactionTestCase): class TransactionTestCase(TestServerUrlMixin, UserMixin, SiteMixin, CacheMixin, DjangoTransactionTestCase):
""" """
Base test case for ecommerce tests. Base test case for ecommerce tests.
......
...@@ -8,7 +8,7 @@ django-filter==0.11.0 ...@@ -8,7 +8,7 @@ django-filter==0.11.0
django-libsass==0.5 django-libsass==0.5
django-oscar==1.1.1 django-oscar==1.1.1
django-rest-swagger[reST]==0.3.10 django-rest-swagger[reST]==0.3.10
django_simple_history==1.6.3 django-simple-history==1.8.2
django-solo==1.1.2 django-solo==1.1.2
django-threadlocals==0.8 django-threadlocals==0.8
django-waffle==0.11.1 django-waffle==0.11.1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment