コード例 #1
0
    def setUpClass(cls):
        super(TestAddress, cls).setUpClass()
        testing_proxy.install_module('nereid')

        country_obj = testing_proxy.pool.get('country.country')

        with Transaction().start(testing_proxy.db_name, 1, None) as txn:
            company = testing_proxy.create_company('Test Company')
            testing_proxy.set_company_for_user(1, company)

            cls.guest_user = testing_proxy.create_guest_user(company=company)
            cls.regd_user_id = testing_proxy.create_user_party(
                'Registered User', '*****@*****.**', 'password', company
            )

            cls.available_countries = country_obj.search([], limit=5)
            cls.site = testing_proxy.create_site(
                'localhost',
                countries = [('set', cls.available_countries)],
                application_user = 1, guest_user = cls.guest_user
                )

            testing_proxy.create_template(
                'home.jinja',
                '{{get_flashed_messages()}}', cls.site)
            testing_proxy.create_template(
                'login.jinja',
                '{{ login_form.errors }} {{get_flashed_messages()}}', cls.site)
            testing_proxy.create_template(
                'registration.jinja',
                '{{ form.errors }} {{get_flashed_messages()}}', cls.site)

            testing_proxy.create_template(
                'reset-password.jinja', '', cls.site)
            testing_proxy.create_template(
                'change-password.jinja',
                '{{ change_password_form.errors }}', cls.site)
            testing_proxy.create_template(
                'address-edit.jinja',
                'Address Edit {{ form.errors }}', cls.site)
            testing_proxy.create_template(
                'address.jinja', '', cls.site)
            testing_proxy.create_template(
                'account.jinja', '', cls.site)
            # Create templates for activation emails
            testing_proxy.create_template(
                'emails/activation-text.jinja', '', cls.site
            )
            testing_proxy.create_template(
                'emails/activation-html.jinja', '', cls.site
            )
            testing_proxy.create_template(
                'emails/reset-text.jinja', '', cls.site
            )
            testing_proxy.create_template(
                'emails/reset-html.jinja', '', cls.site
            )
            txn.cursor.commit()
コード例 #2
0
    def test_0060_registered_with_address_of_some_other_user(self):
        """Sending full address to create with registered user"""
        with Transaction().start(testing_proxy.db_name, 
                testing_proxy.user, testing_proxy.context) as txn:
            regd_user2_id = testing_proxy.create_user_party('Registered User 3',
                '*****@*****.**', 'password3', company=self.company)
            regd_user_id = self.address_obj.search([('id', '!=', regd_user2_id)])[0]
            regd_user2 = self.address_obj.browse(regd_user_id)
            party_id = regd_user2.party.id
            country = self.country_obj.browse(self.available_countries[0])
            subdivision = country.subdivisions[0]

            txn.cursor.commit()

        app = self.get_app(DEBUG=True)
        with app.test_client() as c:
            rv = c.post('/en_US/login', data={
                'email': '*****@*****.**',
                'password': '******',
                })
            c.post('/en_US/cart/add', data={
                'product': self.product, 'quantity': 5
                })
            rv = c.get('/en_US/checkout')
            self.assertEqual(rv.status_code, 200)

            # Totally invalid data
            rv = c.post('/en_US/checkout', data={})
            errors = rv.data
            self.assertTrue('payment_method' in errors)
            self.assertTrue('shipment_method' in errors)
            self.assertTrue('billing_address' in errors)
            self.assertTrue('shipping_address' in errors)

            # Invalid but providing that new_address is to be validated
            rv = c.post('/en_US/checkout', data={
                'billing_address': 0,
                'shipping_same_as_billing': True
                })
            errors = rv.data
            self.assertTrue('payment_method' in errors)
            self.assertTrue('shipment_method' in errors)
            self.assertTrue('new_billing_address' in errors)
            self.assertTrue('shipping_address' not in errors)

            # Providing complete information
            rv = c.post('/en_US/checkout', data={
                'billing_address'                   : regd_user_id,
                'shipping_same_as_billing'          : True,
                'shipment_method'                   : 1,
                'payment_method'                    : 1,
                })
            self.assertEqual(rv.status_code, 200)
コード例 #3
0
    def test_0050_address_as_loggedin(self):
        "When address lookup is invoked as logged in user must succeed"
        with Transaction().start(testing_proxy.db_name, testing_proxy.user, testing_proxy.context) as txn:
            website_id, = self.website_obj.search([])
            website = self.website_obj.browse(website_id)
            country_id = website.countries[0].id
            regd_user_id = testing_proxy.create_user_party(
                "Registered User", "*****@*****.**", "password", company=self.company
            )
            regd_user = self.nereid_user_obj.browse(regd_user_id)
            address_id = regd_user.addresses[0].id
            self.address_obj.write(address_id, {"country": country_id})
            txn.cursor.commit()

        app = self.get_app()
        with app.test_client() as c:
            rv = c.post("/en_US/login", data={"email": "*****@*****.**", "password": "******"})
            result = c.get("/en_US/_available_gateways?value=%s&type=address" % address_id)
            json_result = json.loads(result.data)["result"]
            self.assertEqual(len(json_result), 1)
コード例 #4
0
    def setUpClass(cls):
        super(TestLinkedInAuth, cls).setUpClass()
        # Install module
        testing_proxy.install_module('nereid_auth_linkedin')

        with Transaction().start(testing_proxy.db_name, 1, None) as txn:
            country_obj = Pool().get('country.country')
            currency_obj = Pool().get('currency.currency')

            company = testing_proxy.create_company('Test Company')
            testing_proxy.set_company_for_user(1, company)

            cls.guest_user = testing_proxy.create_guest_user(company=company)
            cls.regd_user_id = testing_proxy.create_user_party(
                'Registered User', '*****@*****.**', 'password', company
            )

            cls.available_countries = country_obj.search([], limit=5)
            cls.available_currencies = currency_obj.search([
                ('code', '=', 'USD')
            ])

            cls.site = testing_proxy.create_site(
                'localhost',
                countries = [('set', cls.available_countries)],
                currencies = [('set', cls.available_currencies)],
                application_user = 1,
                guest_user = cls.guest_user,
            )

            testing_proxy.create_template(
                'home.jinja', '{{ get_flashed_messages() }}', cls.site
            )
            testing_proxy.create_template(
                'login.jinja',
                '{{ login_form.errors }} {{ get_flashed_messages() }}',
                cls.site
            )
            txn.cursor.commit()
コード例 #5
0
    def test_0050_registered_with_new_address(self):
        """Sending full address to create with registered user"""
        with Transaction().start(testing_proxy.db_name,
                testing_proxy.user, testing_proxy.context) as txn:
            regd_user_id = testing_proxy.create_user_party('Registered User 2', 
                '*****@*****.**', 'password2', company=self.company)
            regd_user = self.nereid_user_obj.browse(regd_user_id)
            party_id = regd_user.party.id
            country = self.country_obj.browse(self.available_countries[0])
            subdivision = country.subdivisions[0]

            txn.cursor.commit()

        app = self.get_app(DEBUG=True)
        with app.test_client() as c:
            rv = c.post('/en_US/login', data={
                'email': '*****@*****.**',
                'password': '******',
                })
            c.post('/en_US/cart/add', data={
                'product': self.product, 'quantity': 5
                })
            rv = c.get('/en_US/checkout')
            self.assertEqual(rv.status_code, 200)

            # Totally invalid data
            rv = c.post('/en_US/checkout', data={})
            errors = rv.data
            self.assertTrue('payment_method' in errors)
            self.assertTrue('shipment_method' in errors)
            self.assertTrue('billing_address' in errors)
            self.assertTrue('shipping_address' in errors)

            # Invalid but providing that new_address is to be validated
            rv = c.post('/en_US/checkout', data={
                'billing_address': 0,
                'shipping_same_as_billing': True
                })
            errors = rv.data
            self.assertTrue('payment_method' in errors)
            self.assertTrue('shipment_method' in errors)
            self.assertTrue('new_billing_address' in errors)
            self.assertTrue('shipping_address' not in errors)

            # Providing complete information
            rv = c.post('/en_US/checkout', data={
                'billing_address'                   : 0,
                'new_billing_address-name'          : 'Name',
                'new_billing_address-street'        : 'Street',
                'new_billing_address-streetbis'     : 'Streetbis',
                'new_billing_address-zip'           : 'ZIP',
                'new_billing_address-city'          : 'City',
                'new_billing_address-email'         : '*****@*****.**',
                'new_billing_address-phone'         : '1234567',
                'new_billing_address-country'       : country.id,
                'new_billing_address-subdivision'   : subdivision.id,
                'shipping_same_as_billing'          : True,
                'shipment_method'                   : 1,
                'payment_method'                    : 1,
                })
            self.assertEqual(rv.status_code, 302)

        with Transaction().start(testing_proxy.db_name, 
                testing_proxy.user, testing_proxy.context):
            sale_ids = self.sale_obj.search([('party', '=', party_id)])
            self.assertEqual(len(sale_ids), 1)
            sale = self.sale_obj.browse(sale_ids[0])
            self.assertEqual(sale.total_amount, Decimal('50'))
            self.assertEqual(sale.tax_amount, Decimal('0'))
            self.assertEqual(len(sale.lines), 1)
            self.assertEqual(sale.state, 'confirmed')
コード例 #6
0
    def test_0040_registered(self):
        """Invalid but with existing address chosen"""
        with Transaction().start(testing_proxy.db_name, 
                testing_proxy.user, testing_proxy.context) as txn:
            regd_user_id = testing_proxy.create_user_party('Registered User', 
                '*****@*****.**', 'password', company=self.company)
            regd_user = self.nereid_user_obj.browse(regd_user_id)
            address_id = regd_user.addresses[0].id
            party_id = regd_user.party.id

            txn.cursor.commit()

        app = self.get_app(DEBUG=True)
        with app.test_client() as c:
            rv = c.post('/en_US/login', data={
                'email': '*****@*****.**',
                'password': '******',
                })
            c.post('/en_US/cart/add', data={
                'product': self.product, 'quantity': 5
                })
            rv = c.get('/en_US/checkout')
            self.assertEqual(rv.status_code, 200)

            # Totally invalid data
            rv = c.post('/en_US/checkout', data={})
            errors = rv.data
            self.assertTrue('payment_method' in errors)
            self.assertTrue('shipment_method' in errors)
            self.assertTrue('billing_address' in errors)
            self.assertTrue('shipping_address' in errors)

            # Invalid but providing that new_address is to be validated
            rv = c.post('/en_US/checkout', data={
                'billing_address': 0,
                'shipping_same_as_billing': True
                })
            errors = rv.data
            self.assertTrue('payment_method' in errors)
            self.assertTrue('shipment_method' in errors)
            self.assertTrue('new_billing_address' in errors)
            self.assertTrue('shipping_address' not in errors)

            # Providing complete information
            rv = c.post('/en_US/checkout', data={
                'billing_address'                   : address_id,
                'shipping_same_as_billing'          : True,
                'shipment_method'                   : 1,
                'payment_method'                    : 1,
                })
            self.assertEqual(rv.status_code, 302)

        with Transaction().start(testing_proxy.db_name, 
                testing_proxy.user, testing_proxy.context):
            sale_ids = self.sale_obj.search([('party', '=', party_id)])
            self.assertEqual(len(sale_ids), 1)
            sale = self.sale_obj.browse(sale_ids[0])
            self.assertEqual(sale.total_amount, Decimal('50'))
            self.assertEqual(sale.tax_amount, Decimal('0'))
            self.assertEqual(len(sale.lines), 1)
            self.assertEqual(sale.state, 'confirmed')