def test_cart_articles(self):
        shopping_site = IShoppingSite(self.portal)
        self.assertIsNone(shopping_site.cart_articles())

        session = shopping_site.getSessionData(create=True)
        session.set('collective.cart.core', {})
        self.assertIsNone(shopping_site.cart_articles())

        session.set('collective.cart.core', {'articles': 'ARTICLES'})
        self.assertEqual(shopping_site.cart_articles(), 'ARTICLES')
    def test_remove_cart_articles(self):
        shopping_site = IShoppingSite(self.portal)
        session = shopping_site.getSessionData(create=True)
        session.set('collective.cart.core', {'articles': {'1': 'ARTICLE1', '2': 'ARTICLE2', '3': 'ARTICLE3'}})

        self.assertEqual(shopping_site.remove_cart_articles('4'), [])
        self.assertEqual(shopping_site.cart_articles(), {'1': 'ARTICLE1', '2': 'ARTICLE2', '3': 'ARTICLE3'})

        self.assertEqual(shopping_site.remove_cart_articles(['2', '3']), ['ARTICLE2', 'ARTICLE3'])
        self.assertEqual(shopping_site.cart_articles(), {'1': 'ARTICLE1'})

        self.assertEqual(shopping_site.remove_cart_articles('1'), ['ARTICLE1'])
        self.assertEqual(shopping_site.cart_articles(), {})
    def test_create_order(self):
        adapter = IShoppingSite(self.portal)
        self.assertIsNone(adapter.create_order())

        order_container = self.create_content('collective.cart.core.OrderContainer')
        adapter.order_container = mock.Mock(return_value=order_container)

        article1 = {
            'id': '1',
            'title': 'Ärticle1',
            'description': 'Description of Ärticle1',
        }
        cart_articles = {'1': article1}
        adapter.cart_articles = mock.Mock(return_value=cart_articles)

        adapter.update_next_order_id = mock.Mock()
        order1 = adapter.create_order()
        self.assertEqual(order1.id, '1')

        order_article1 = order1['1']
        self.assertEqual(order_article1.title, article1['title'])
        self.assertEqual(order_article1.description, article1['description'])

        order3 = adapter.create_order('3')
        self.assertEqual(order3.id, '3')
    def update(self):
        form = self.request.form
        uuid = form.get("form.buttons.RemoveArticle", None)

        if uuid is not None:

            authenticator = self.context.restrictedTraverse("@@authenticator")
            if not authenticator.verify():
                raise Forbidden()

            shopping_site = IShoppingSite(self.context)
            shopping_site.remove_cart_articles(uuid)
            if not shopping_site.cart_articles():
                current_base_url = self.context.restrictedTraverse("plone_context_state").current_base_url()
                return self.request.response.redirect(current_base_url)