def test_03_public_user_address_and_company(self):
        ''' Same as test_02 but with public user '''
        self._setUp_multicompany_env()
        so = self._create_so(self.website.user_id.partner_id.id)

        env = api.Environment(self.env.cr, self.website.user_id.id, {})
        # change also website env for `sale_get_order` to not change order partner_id
        with MockRequest(env,
                         website=self.website.with_env(env),
                         sale_order_id=so.id):
            # 1. Public user, new billing
            self.default_address_values['partner_id'] = -1
            self.WebsiteSaleController.address(**self.default_address_values)
            new_partner = so.partner_id
            self.assertNotEqual(
                new_partner, self.website.user_id.partner_id,
                "New billing should have created a new partner and assign it on the SO"
            )
            self.assertEqual(
                new_partner.company_id, self.website.company_id,
                "The new partner should get the company of the website")

            # 2. Public user, edit billing
            self.default_address_values['partner_id'] = new_partner.id
            self.WebsiteSaleController.address(**self.default_address_values)
            self.assertEqual(
                new_partner.company_id, self.website.company_id,
                "Public user edited billing (the partner itself) should not get its company modified."
            )
Example #2
0
 def test_process_att_monolang_route(self):
     with MockRequest(self.env, website=self.website, multilang=False):
         # lang not changed in URL but CDN enabled
         self._test_att('/a', {'href': 'http://test.cdn/a'})
         self._test_att('/en/a', {'href': 'http://test.cdn/en/a'})
         self._test_att('/b', {'href': 'http://test.cdn/b'})
         self._test_att('/en/b', {'href': '/en/b'})
    def test_02_demo_address_and_company(self):
        ''' This test ensure that the company_id of the address (partner) is
            correctly set and also, is not wrongly changed.
            eg: new shipping should use the company of the website and not the
                one from the admin, and editing a billing should not change its
                company.
        '''
        self._setUp_multicompany_env()
        so = self._create_so(self.demo_partner.id)

        env = api.Environment(self.env.cr, self.demo_user.id, {})
        # change also website env for `sale_get_order` to not change order partner_id
        with MockRequest(env,
                         website=self.website.with_env(env),
                         sale_order_id=so.id):
            # 1. Logged in user, new shipping
            self.WebsiteSaleController.address(**self.default_address_values)
            new_shipping = self._get_last_address(self.demo_partner)
            self.assertTrue(
                new_shipping.company_id != self.env.user.company_id,
                "Logged in user new shipping should not get the company of the sudo() neither the one from it's partner.."
            )
            self.assertEqual(new_shipping.company_id, self.website.company_id,
                             ".. but the one from the website.")

            # 2. Logged in user, edit billing
            self.default_address_values['partner_id'] = self.demo_partner.id
            self.WebsiteSaleController.address(**self.default_address_values)
            self.assertEqual(
                self.demo_partner.company_id, self.company_c,
                "Logged in user edited billing (the partner itself) should not get its company modified."
            )
    def test_create_visitor_on_tracked_product(self):
        self.WebsiteSaleController = WebsiteSale()
        Visitor = self.env['website.visitor']
        Track = self.env['website.track']

        self.assertEqual(len(Visitor.search([])), 0,
                         "No visitor at the moment")
        self.assertEqual(len(Track.search([])), 0, "No track at the moment")

        product = self.env.ref('product.product_product_7')

        with MockRequest(self.env, website=self.website):
            self.cookies = self.WebsiteSaleController.products_recently_viewed_update(
                product.id)

        self.assertEqual(
            len(Visitor.search([])), 1,
            "A visitor should be created after visiting a tracked product")
        self.assertEqual(
            len(Track.search([])), 1,
            "A track should be created after visiting a tracked product")

        with MockRequest(self.env, website=self.website, cookies=self.cookies):
            self.WebsiteSaleController.products_recently_viewed_update(
                product.id)

        self.assertEqual(
            len(Visitor.search([])), 1,
            "No visitor should be created after visiting another tracked product"
        )
        self.assertEqual(
            len(Track.search([])), 1,
            "No track should be created after visiting the same tracked product before 30 min"
        )

        product = self.env.ref('product.product_product_6')
        with MockRequest(self.env, website=self.website, cookies=self.cookies):
            self.WebsiteSaleController.products_recently_viewed_update(
                product.id)

        self.assertEqual(
            len(Visitor.search([])), 1,
            "No visitor should be created after visiting another tracked product"
        )
        self.assertEqual(
            len(Track.search([])), 2,
            "A track should be created after visiting another tracked product")
Example #5
0
 def test_process_att_no_website(self):
     with MockRequest(self.env):
         # no website so URL rewriting
         self._test_att('/', {'href': '/'})
         self._test_att('/en/', {'href': '/en/'})
         self._test_att('/fr/', {'href': '/fr/'})
         # no URL rewritting for CDN
         self._test_att('/a', {'href': '/a'})
Example #6
0
 def test_process_att_matching_cdn_and_lang(self):
     with MockRequest(self.env, website=self.website):
         # lang prefix is added before CDN
         self._test_att('/a', {'href': 'http://test.cdn/a'})
         self._test_att('/en/a', {'href': 'http://test.cdn/a'})
         self._test_att('/fr/a', {'href': 'http://test.cdn/fr/a'})
         self._test_att('/b', {'href': 'http://test.cdn/b'})
         self._test_att('/en/b', {'href': 'http://test.cdn/b'})
         self._test_att('/fr/b', {'href': '/fr/b'})
Example #7
0
    def test_01_create_shipping_address_specific_user_account(self):
        ''' Ensure `website_id` is correctly set (specific_user_account) '''
        p = self.env.user.partner_id
        so = self._create_so(p.id)

        with MockRequest(self.env, website=self.website, sale_order_id=so.id):
            self.WebsiteSaleController.address(**self.default_address_values)
            self.assertFalse(self._get_last_address(p).website_id, "New shipping address should not have a website set on it (no specific_user_account).")

            self.website.specific_user_account = True

            self.WebsiteSaleController.address(**self.default_address_values)
            self.assertEqual(self._get_last_address(p).website_id, self.website, "New shipping address should have a website set on it (specific_user_account).")
Example #8
0
 def test_process_att_url_crap(self):
     with MockRequest(self.env, website=self.website) as request:
         # #{fragment} is stripped from URL when testing route
         self._test_att('/x#y?z', {'href': '/x#y?z'})
         self.assertEqual(
             request.httprequest.app._log_call[-1],
             (('/x',), {'method': 'POST', 'query_args': None})
         )
         self._test_att('/x?y#z', {'href': '/x?y#z'})
         self.assertEqual(
             request.httprequest.app._log_call[-1],
             (('/x',), {'method': 'POST', 'query_args': 'y'})
         )
Example #9
0
    def test_04_apply_empty_pl(self):
        ''' Ensure empty pl code reset the applied pl '''
        so = self._create_so(self.env.user.partner_id.id)
        eur_pl = self.env['product.pricelist'].create({
            'name': 'EUR_test',
            'website_id': self.website.id,
            'code': 'EUR_test',
        })

        with MockRequest(self.env, website=self.website, sale_order_id=so.id):
            self.WebsiteSaleController.pricelist('EUR_test')
            self.assertEqual(so.pricelist_id, eur_pl, "Ensure EUR_test is applied")

            self.WebsiteSaleController.pricelist('')
            self.assertNotEqual(so.pricelist_id, eur_pl, "Pricelist should be removed when sending an empty pl code")
    def test_case_1_app_controller(self):
        self.core_app_controller = app_main.OpenEagleEduAppController()

        with MockRequest(self.env):
            self.core_app = self.core_app_controller.compute_app_dashboard_data()
            self.core_app = self.core_app_controller.compute_faculty_dashboard_data()
Example #11
0
 def test_01_url_lang(self):
     with MockRequest(self.env, website=self.website):
         self.assertEqual(url_lang('', '[lang]'), '/[lang]/hello/', "`[lang]` is used to be replaced in the url_return after installing a language, it should not be replaced or removed.")
Example #12
0
 def test_process_att_no_route(self):
     with MockRequest(self.env, website=self.website, context={'lang': 'fr_FR'}, routing=False):
         # default on multilang=True if route is not /{module}/static/
         self._test_att('/web/static/hi', {'href': '/web/static/hi'})
         self._test_att('/my-page', {'href': '/fr/my-page'})
Example #13
0
 def test_process_att_with_request_lang(self):
     with MockRequest(self.env, website=self.website, context={'lang': 'fr_FR'}):
         self._test_att('/', {'href': '/fr/'})
         self._test_att('/en/', {'href': '/'})
         self._test_att('/fr/', {'href': '/fr/'})
Example #14
0
 def test_process_att_no_request_lang(self):
     with MockRequest(self.env, website=self.website):
         self._test_att('/', {'href': '/'})
         self._test_att('/en/', {'href': '/'})
         self._test_att('/fr/', {'href': '/fr/'})