def setUp(self): """ Set up initial data (e.g., site configuration, category) prior to running tests """ super(SeedEnterpriseDevstackDataTests, self).setUp() self.site_config = SiteConfigurationFactory.create( oauth_settings=self.site_oauth_settings, ) self.command = seed_command() self.command.site = self.site_config CategoryFactory.create(name='coupons') self.ent_customer_uuid = str(uuid4()) self.ent_catalog_uuid = str(uuid4()) self.access_token = 'fake_access_token'
def test_can_create_a_product_without_stockrecord(self): category = CategoryFactory() product_class = ProductClass.objects.create(name="Book") page = self.get(reverse('dashboard:catalogue-product-create', args=(product_class.slug,))) form = page.form form['upc'] = '123456' form['title'] = 'new product' form['productcategory_set-0-category'] = category.id form.submit() self.assertEqual(Product.objects.count(), 1)
def test_doesnt_allow_duplicate_upc(self): ProductFactory(parent=None, upc="12345") category = CategoryFactory() self.assertTrue(Product.objects.get(upc="12345")) response = self.submit(title="Nice T-Shirt", category=category, upc="12345") self.assertEqual(Product.objects.count(), 1) self.assertNotEqual( Product.objects.get(upc='12345').title, 'Nice T-Shirt') self.assertContains(response, "Product with this UPC already exists.")
def test_can_create_product_with_required_attributes(self): category = CategoryFactory() attribute = ProductAttributeFactory(required=True) product_class = attribute.product_class page = self.get(reverse('dashboard:catalogue-product-create', args=(product_class.slug,))) form = page.form form['upc'] = '123456' form['title'] = 'new product' form['attr_weight'] = '5' form['productcategory_set-0-category'] = category.id form.submit() self.assertEqual(Product.objects.count(), 1)
def test_can_create_and_continue_editing_a_product(self): category = CategoryFactory() product_class = ProductClass.objects.create(name="Book") page = self.get(reverse('dashboard:catalogue-product-create', args=(product_class.slug,))) form = page.form form['upc'] = '123456' form['title'] = 'new product' form['productcategory_set-0-category'] = category.id form['stockrecords-0-partner'] = self.partner.id form['stockrecords-0-partner_sku'] = '14' form['stockrecords-0-num_in_stock'] = '555' form['stockrecords-0-price_excl_tax'] = '13.99' page = form.submit(name='action', value='continue') self.assertEqual(Product.objects.count(), 1) product = Product.objects.all()[0] self.assertEqual(product.stockrecords.all()[0].partner, self.partner) self.assertRedirects(page, reverse('dashboard:catalogue-product', kwargs={'pk': product.id}))
def test_can_update_a_product_without_stockrecord(self): new_title = u'foobar' category = CategoryFactory() product = ProductFactory(stockrecords=[]) page = self.get( reverse('dashboard:catalogue-product', kwargs={'pk': product.id})) form = page.forms[0] form['productcategory_set-0-category'] = category.id self.assertNotEqual(form['title'].value, new_title) form['title'] = new_title form.submit() try: product = Product.objects.get(pk=product.pk) except Product.DoesNotExist: pass else: self.assertTrue(product.title == new_title) if product.has_stockrecords: self.fail('Product has stock records but should not')
def test_for_smoke(self): category = CategoryFactory() response = self.submit(title='testing', category=category) self.assertIsRedirect(response) self.assertEqual(Product.objects.count(), 1)
from django.conf import settings from django.test import LiveServerTestCase as DjangoLiveServerTestCase from django.test import TestCase as DjangoTestCase from django.test import TransactionTestCase as DjangoTransactionTestCase from edx_django_utils.cache import TieredCache from oscar.test.factories import CategoryFactory from ecommerce.tests.mixins import SiteMixin, TestServerUrlMixin, TestWaffleFlagMixin, UserMixin # When all unit tests are run, the catalog category table will sometimes be empty. However, if only a single test # is run, Category will have been populated by migrations (in particular, see # ecommerce/extensions/catalogue/migrations/0002_auto_20150223_1052.py). This can lead to conflicting paths if a test # creates more than one ProductFactory, since the CategoryFactory will attempt to reuse the path 0001. CategoryFactory.reset_sequence(1000) class TieredCacheMixin: # TODO: Once the CacheIsolationMixin and CacheIsolationTestCase from edx-platform, # are moved to edx-django-utils, this can be replaced. def setUp(self): TieredCache.dangerous_clear_all_tiers() super(TieredCacheMixin, self).setUp() def tearDown(self): TieredCache.dangerous_clear_all_tiers() super(TieredCacheMixin, self).tearDown() class ViewTestMixin(TieredCacheMixin): path = None