class TestWishListRemoveProduct(WishListTestMixin, WebTestCase): def setUp(self): super().setUp() self.wishlist = WishListFactory(owner=self.user) self.wishlist.add(self.product) self.line = self.wishlist.lines.get(product=self.product) def test_remove_wishlist_line(self): delete_wishlist_line_url = reverse_lazy( 'customer:wishlists-remove-product', kwargs={ 'key': self.wishlist.key, 'line_pk': self.line.pk }) self.get(delete_wishlist_line_url).forms[0].submit() # Test WishList doesnt contain line and return 404 self.assertEqual( self.get(delete_wishlist_line_url, expect_errors=True).status_code, 404) def test_remove_wishlist_product(self): delete_wishlist_product_url = reverse_lazy( 'customer:wishlists-remove-product', kwargs={ 'key': self.wishlist.key, 'product_pk': self.line.product.id }) self.get(delete_wishlist_product_url).forms[0].submit() # Test WishList doesnt contain line and return 404 self.assertEqual( self.get(delete_wishlist_product_url, expect_errors=True).status_code, 404)
class TestMovedClasses(TestCase): def setUp(self): user = UserFactory() product = create_product() self.wishlist = WishListFactory(owner=user) self.wishlist.add(product) def test_load_formset_old_destination(self): BaseBasketLineFormSet = get_class('basket.forms', 'BaseBasketLineFormSet') self.assertEqual('oscar.apps.basket.formsets', BaseBasketLineFormSet.__module__) StockRecordFormSet = get_class('dashboard.catalogue.forms', 'StockRecordFormSet') self.assertEqual('oscar.apps.dashboard.catalogue.formsets', StockRecordFormSet.__module__) OrderedProductFormSet = get_class('dashboard.promotions.forms', 'OrderedProductFormSet') OrderedProductForm = get_class('dashboard.promotions.forms', 'OrderedProductForm') # Since OrderedProductFormSet created with metaclass, it has __module__ # attribute pointing to the Django module. Thus, we test if formset was # loaded correctly by initiating class instance and checking its forms. self.assertTrue(isinstance(OrderedProductFormSet().forms[0], OrderedProductForm)) LineFormset = get_class('wishlists.forms', 'LineFormset') WishListLineForm = get_class('wishlists.forms', 'WishListLineForm') self.assertTrue(isinstance(LineFormset(instance=self.wishlist).forms[0], WishListLineForm)) def test_load_formset_new_destination(self): BaseBasketLineFormSet = get_class('basket.formsets', 'BaseBasketLineFormSet') self.assertEqual('oscar.apps.basket.formsets', BaseBasketLineFormSet.__module__) StockRecordFormSet = get_class('dashboard.catalogue.formsets', 'StockRecordFormSet') self.assertEqual('oscar.apps.dashboard.catalogue.formsets', StockRecordFormSet.__module__) OrderedProductFormSet = get_class('dashboard.promotions.formsets', 'OrderedProductFormSet') OrderedProductForm = get_class('dashboard.promotions.forms', 'OrderedProductForm') self.assertTrue(isinstance(OrderedProductFormSet().forms[0], OrderedProductForm)) LineFormset = get_class('wishlists.formsets', 'LineFormset') WishListLineForm = get_class('wishlists.forms', 'WishListLineForm') self.assertTrue(isinstance(LineFormset(instance=self.wishlist).forms[0], WishListLineForm)) def test_load_formsets_mixed_destination(self): BaseBasketLineFormSet, BasketLineForm = get_classes( 'basket.forms', ('BaseBasketLineFormSet', 'BasketLineForm')) self.assertEqual('oscar.apps.basket.formsets', BaseBasketLineFormSet.__module__) self.assertEqual('oscar.apps.basket.forms', BasketLineForm.__module__) StockRecordForm, StockRecordFormSet = get_classes( 'dashboard.catalogue.forms', ('StockRecordForm', 'StockRecordFormSet') ) self.assertEqual('oscar.apps.dashboard.catalogue.forms', StockRecordForm.__module__) OrderedProductForm, OrderedProductFormSet = get_classes( 'dashboard.promotions.forms', ('OrderedProductForm', 'OrderedProductFormSet') ) self.assertEqual('oscar.apps.dashboard.promotions.forms', OrderedProductForm.__module__) self.assertTrue(isinstance(OrderedProductFormSet().forms[0], OrderedProductForm)) LineFormset, WishListLineForm = get_classes('wishlists.forms', ('LineFormset', 'WishListLineForm')) self.assertEqual('oscar.apps.wishlists.forms', WishListLineForm.__module__) self.assertTrue(isinstance(LineFormset(instance=self.wishlist).forms[0], WishListLineForm))
def test_wishlists_containing_product(self): p1 = ProductFactory() p2 = ProductFactory() user = UserFactory() wishlist1 = WishListFactory(owner=user) WishListFactory(owner=user) wishlist1.add(p1) containing_one = wishlists_containing_product(Wishlist.objects.all(), p1) self.assertEqual(len(containing_one), 1) self.assertEqual(containing_one[0], wishlist1) containing_none = wishlists_containing_product(Wishlist.objects.all(), p2) self.assertEqual(len(containing_none), 0)
class TestMoveProductToAnotherWishList(WishListTestMixin, WebTestCase): def setUp(self): super().setUp() self.wishlist1 = WishListFactory(owner=self.user) self.wishlist2 = WishListFactory(owner=self.user) def test_move_product_to_another_wishlist_already_containing_it(self): self.wishlist1.add(self.product) line1 = self.wishlist1.lines.get(product=self.product) self.wishlist2.add(self.product) url = reverse_lazy('customer:wishlists-move-product-to-another', kwargs={'key': self.wishlist1.key, 'line_pk': line1.pk, 'to_key': self.wishlist2.key}) self.get(url) self.assertEqual(self.wishlist1.lines.filter(product=self.product).count(), 1) self.assertEqual(self.wishlist2.lines.filter(product=self.product).count(), 1) def test_move_product_to_another_wishlist(self): self.wishlist1.add(self.product) line1 = self.wishlist1.lines.get(product=self.product) url = reverse_lazy('customer:wishlists-move-product-to-another', kwargs={'key': self.wishlist1.key, 'line_pk': line1.pk, 'to_key': self.wishlist2.key}) self.get(url) self.assertEqual(self.wishlist1.lines.filter(product=self.product).count(), 0) self.assertEqual(self.wishlist2.lines.filter(product=self.product).count(), 1)
class TestMoveProductToAnotherWishList(WishListTestMixin, WebTestCase): def setUp(self): super().setUp() self.wishlist1 = WishListFactory(owner=self.user) self.wishlist2 = WishListFactory(owner=self.user) def test_move_product_to_another_wishlist_already_containing_it(self): self.wishlist1.add(self.product) line1 = self.wishlist1.lines.get(product=self.product) self.wishlist2.add(self.product) url = reverse_lazy('customer:wishlists-move-product-to-another', kwargs={ 'key': self.wishlist1.key, 'line_pk': line1.pk, 'to_key': self.wishlist2.key }) self.get(url) self.assertEqual( self.wishlist1.lines.filter(product=self.product).count(), 1) self.assertEqual( self.wishlist2.lines.filter(product=self.product).count(), 1) def test_move_product_to_another_wishlist(self): self.wishlist1.add(self.product) line1 = self.wishlist1.lines.get(product=self.product) url = reverse_lazy('customer:wishlists-move-product-to-another', kwargs={ 'key': self.wishlist1.key, 'line_pk': line1.pk, 'to_key': self.wishlist2.key }) self.get(url) self.assertEqual( self.wishlist1.lines.filter(product=self.product).count(), 0) self.assertEqual( self.wishlist2.lines.filter(product=self.product).count(), 1) # Test WishList doesnt contain line and return 404 self.assertEqual(self.get(url, expect_errors=True).status_code, 404)
def setUp(self): super(TestMoveProductToAnotherWishList, self).setUp() self.wishlist1 = WishListFactory(owner=self.user) self.wishlist2 = WishListFactory(owner=self.user)
def setUp(self): user = UserFactory() product = create_product() self.wishlist = WishListFactory(owner=user) self.wishlist.add(product)
class TestMovedClasses(TestCase): def setUp(self): user = UserFactory() product = create_product() self.wishlist = WishListFactory(owner=user) self.wishlist.add(product) def test_load_formset_old_destination(self): BaseBasketLineFormSet = get_class('basket.forms', 'BaseBasketLineFormSet') self.assertEqual('oscar.apps.basket.formsets', BaseBasketLineFormSet.__module__) StockRecordFormSet = get_class('dashboard.catalogue.forms', 'StockRecordFormSet') self.assertEqual('oscar.apps.dashboard.catalogue.formsets', StockRecordFormSet.__module__) OrderedProductFormSet = get_class('dashboard.promotions.forms', 'OrderedProductFormSet') OrderedProductForm = get_class('dashboard.promotions.forms', 'OrderedProductForm') # Since OrderedProductFormSet created with metaclass, it has __module__ # attribute pointing to the Django module. Thus, we test if formset was # loaded correctly by initiating class instance and checking its forms. self.assertTrue( isinstance(OrderedProductFormSet().forms[0], OrderedProductForm)) LineFormset = get_class('wishlists.forms', 'LineFormset') WishListLineForm = get_class('wishlists.forms', 'WishListLineForm') self.assertTrue( isinstance( LineFormset(instance=self.wishlist).forms[0], WishListLineForm)) def test_load_formset_new_destination(self): BaseBasketLineFormSet = get_class('basket.formsets', 'BaseBasketLineFormSet') self.assertEqual('oscar.apps.basket.formsets', BaseBasketLineFormSet.__module__) StockRecordFormSet = get_class('dashboard.catalogue.formsets', 'StockRecordFormSet') self.assertEqual('oscar.apps.dashboard.catalogue.formsets', StockRecordFormSet.__module__) OrderedProductFormSet = get_class('dashboard.promotions.formsets', 'OrderedProductFormSet') OrderedProductForm = get_class('dashboard.promotions.forms', 'OrderedProductForm') self.assertTrue( isinstance(OrderedProductFormSet().forms[0], OrderedProductForm)) LineFormset = get_class('wishlists.formsets', 'LineFormset') WishListLineForm = get_class('wishlists.forms', 'WishListLineForm') self.assertTrue( isinstance( LineFormset(instance=self.wishlist).forms[0], WishListLineForm)) def test_load_formsets_mixed_destination(self): BaseBasketLineFormSet, BasketLineForm = get_classes( 'basket.forms', ('BaseBasketLineFormSet', 'BasketLineForm')) self.assertEqual('oscar.apps.basket.formsets', BaseBasketLineFormSet.__module__) self.assertEqual('oscar.apps.basket.forms', BasketLineForm.__module__) StockRecordForm, StockRecordFormSet = get_classes( 'dashboard.catalogue.forms', ('StockRecordForm', 'StockRecordFormSet')) self.assertEqual('oscar.apps.dashboard.catalogue.forms', StockRecordForm.__module__) OrderedProductForm, OrderedProductFormSet = get_classes( 'dashboard.promotions.forms', ('OrderedProductForm', 'OrderedProductFormSet')) self.assertEqual('oscar.apps.dashboard.promotions.forms', OrderedProductForm.__module__) self.assertTrue( isinstance(OrderedProductFormSet().forms[0], OrderedProductForm)) LineFormset, WishListLineForm = get_classes( 'wishlists.forms', ('LineFormset', 'WishListLineForm')) self.assertEqual('oscar.apps.wishlists.forms', WishListLineForm.__module__) self.assertTrue( isinstance( LineFormset(instance=self.wishlist).forms[0], WishListLineForm))
def setUp(self): super().setUp() self.wishlist = WishListFactory(owner=self.user) self.wishlist.add(self.product) self.line = self.wishlist.lines.get(product=self.product)
def setUp(self): super().setUp() self.wishlist1 = WishListFactory(owner=self.user) self.wishlist2 = WishListFactory(owner=self.user)