def _edit_enterprise_impl(self): enterprise_id = self.request.matchdict.get('enterprise_id') the_enterprise = None if enterprise_id: the_enterprise = Enterprise.load(enterprise_id) else: the_enterprise = Enterprise() return {'the_enterprise': the_enterprise, 'billing_methods' : Enterprise.get_billing_methods()}
def _create_new(self, set_enterprise_id=False): ent = Enterprise.find_by_name('Healthy U Store') R = self.get('/crm/users/new') assert R.status_int == 200 R.mustcontain('Edit User') f = R.forms['frm_users'] self.assertEqual(f['user_id'].value, '') f.set('username', '*****@*****.**') f.set('email', '*****@*****.**') f.set('fname', 'Test') f.set('lname', 'User') f.set('password', 'fishsticks') f.set('confirm', 'fishsticks') if set_enterprise_id: f.set('enterprise_id', str(ent.enterprise_id)) R = f.submit('submit') self.assertEqual(R.status_int, 302) R = R.follow() assert R.status_int == 200 f = R.forms['frm_users'] R.mustcontain('Edit User') user_id = f['user_id'].value self.assertEqual(f['username'].value, '*****@*****.**') self.assertEqual(f['email'].value, '*****@*****.**') usr = Users.load(user_id) if set_enterprise_id: assert str(usr.enterprise_id) == str(ent.enterprise_id) assert usr is not None assert usr.get_email_info() is not None return user_id
def test_site_alternate_campaign(self): ent = Enterprise.find_by_name('Healthy U Store') cmpns = Campaign.find_all(ent.enterprise_id) other_campaign = cmpns[1] R = self.get('/?__cid=%s' % other_campaign.campaign_id) assert R.status_int == 200 R.mustcontain("campaign_id = %s" % other_campaign.campaign_id)
def test_save_existing(self): ent = Enterprise.find_by_name('Healthy U Store') category_id = self._create_new() R = self.get('/crm/product/category/list') assert R.status_int == 200 R.mustcontain('Test Category') R.mustcontain('Product Search') R = self.get('/crm/product/category/edit/%s' % category_id) R.mustcontain('Edit Product Category') f = R.forms['frm_category'] self.assertEqual(f['category_id'].value, category_id) self.assertEqual(f['name'].value, 'Test Category') self.assertEqual(f['seo_keywords'].value, 'SEO Test') self.assertEqual(f['description'].value, 'Test Description') f.set('name', 'Test Category New') f.set('seo_keywords', 'SEO Test New') for prd in Product.find_all(ent.enterprise_id)[:3]: f.set('child_incl_%s' % prd.product_id, prd.product_id) R = f.submit('submit') self.assertEqual(R.status_int, 302) R = R.follow() assert R.status_int == 200 f = R.forms['frm_category'] R.mustcontain('Edit Product Category') self.assertEqual(f['category_id'].value, category_id) self.assertEqual(f['name'].value, 'Test Category New') self.assertEqual(f['seo_keywords'].value, 'SEO Test New') for prd in Product.find_all(ent.enterprise_id)[:3]: self.assertEqual(f['child_incl_%s' % prd.product_id].checked, True) self._delete_new(category_id)
def test_send_customer_comm(self): ent = Enterprise.find_by_name("Healthy U Store") cust = self.get_customer() comms = Communication.find_all(ent.enterprise_id) R = self.get("/crm/communication/send_customer_comm/%s/%s" % (cust.customer_id, comms[0].comm_id)) assert R.status_int == 200 assert R.body == "True"
def _create_new_attribute(self, parent_product_id): ent = Enterprise.find_by_name('Healthy U Store') comp = Company.find_all(ent.enterprise_id)[0] R = self.get('/crm/product/new?is_attribute&parent_id=%s' % parent_product_id) assert R.status_int == 200 R.mustcontain('Edit Attribute for') f = R.forms['frm_product'] self.assertEqual(f['product_id'].value, '') f.set('parent_id', parent_product_id) f.set('is_attribute', 'True') f.set('type', 'Attr') f.set('name', 'Test Product') f.set('unit_cost', '10.00') f.set('sku', 'TEST-SKU-123') f.set('manufacturer', 'Test Manufacturer') f.set('attr_name[0]', 'attr0key') f.set('attr_value[0]', 'attr0val') f.set('attr_name[1]', 'attr1key') f.set('attr_value[1]', 'attr1val') for camp in Campaign.find_by_company(comp): f.set('campaign_price[%s]' % camp.campaign_id, 20.0) f.set('campaign_discount[%s]' % camp.campaign_id, 10.0) R = f.submit('submit') self.assertEqual(R.status_int, 302) R = R.follow() assert R.status_int == 200 f = R.forms['frm_product'] R.mustcontain('Edit Attribute for') product_id = f['product_id'].value self.assertNotEqual(f['product_id'].value, '') return product_id
def test_misc(self): ent = Enterprise.find_by_name('Healthy U Store') comps = Company.find_all(ent.enterprise_id) assert len(comps) > 0 comp = comps[0] comp_ = Company.find_by_name(ent.enterprise_id, comp.name) assert comp_ is not None assert comp.company_id == comp_.company_id assert str(ent.enterprise_id) in str(ent) assert ent.get_email_info() is not None assert comp.get_email_info() is not None assert Enterprise.find_by_name(ent.name).name == ent.name camps = Campaign.find_by_company(comp) assert len(camps) > 1 ids = sorted([camp.campaign_id for camp in camps]) ids2 = sorted([camp.campaign_id for camp in Campaign.load_ids(ids)]) assert ids == ids2
def test_send_with_attachment(self): ent = Enterprise.find_all()[0] comp = Company.find_all(ent.enterprise_id)[0] mail = UserMail(comp.default_campaign) rand_subj = random.random() mail.send('*****@*****.**', 'test %s' % rand_subj, 'This is generated by pvscore/tests/functional/test_mail:test_send_with_attachment', 'README.md')
def test_save_status(self): ent = Enterprise.find_by_name('Healthy U Store') evt = StatusEvent.find(ent.enterprise_id, 'PurchaseOrder', 'TESTEVENT_PO') purchase_order_id = self._create_new() R = self.post(str('/crm/purchase/save_status/%s' % purchase_order_id), {'event_id' : evt.event_id, 'note' : 'Note Note'}) assert R.status_int == 200 self._delete_new(purchase_order_id)
def test_category(self): ent = Enterprise.find_by_name('Healthy U Store') campaign = ent.companies[0].default_campaign categories = ProductCategory.find_by_campaign(campaign) assert len(categories) > 0 category = categories[0] products = category.get_web_products(campaign) R = self.get('/category/%s/%s/catalog_category' % (category.name, category.category_id)) assert R.status_int == 200 for prod in products: assert str(prod.product_id) in R.body
def test_view_comm_dialog(self): ent = Enterprise.find_by_name("Healthy U Store") cust = self.get_customer() comm = Communication.find_all(ent.enterprise_id)[0] order = cust.get_active_orders()[0] R = self.get( "/crm/communication/view_comm_dialog/%s/%s?order_id=%s&dialog=1" % (cust.customer_id, comm.comm_id, order.order_id) ) assert R.status_int == 200 R.mustcontain("%s %s" % (cust.fname, cust.lname))
def test_full_checkout_with_automatic_cart_discount(self): ent = Enterprise.find_by_name('Healthy U Store') api = StripeBillingApi(ent) # set up the discount for the products self.login_crm(PVS_ROOT_UID, PVS_ROOT_PWD) discount_id = create_new_cart_discount(self, True) discount = Discount.load(discount_id) assert discount is not None assert int(discount.percent_off) == 10 self.logout_crm_soft() self.login_customer() self._clear_cart() prod = self.get_prod() self._add_product(prod, 100) R = self.get('/cart/catalog_cart') R.mustcontain('total=2500.0') R.mustcontain('product_base_total=2500.0') R.mustcontain('product_total=2500.0') R.mustcontain('product_discounts=0.0') R = self.get('/ecom/cart/update/%s/10' % prod.product_id) assert R.status_int == 200 assert R.body == 'True' R = self.get('/cart/catalog_cart') R.mustcontain('total=250.0') R.mustcontain('product_base_total=250.0') R.mustcontain('product_total=250.0') R.mustcontain('product_discounts=0.0') self._select_shipping() R = self.post("/crm/customer/purchase_cart", {'redir' : '/ecom/page/catalog_thanks', 'accept_terms' : '1', 'bill_cc_token' : api.create_token('4242424242424242', '12', '2019', '123')}) R.mustcontain('order total_discounts_applied = 0') R.mustcontain('order total_payments_due = 0.0') R.mustcontain('order total_item_price = 250.0') #R.mustcontain('order total_payments_applied = 418.53') #R.mustcontain('order total_price = 418.53') #R.mustcontain('order total_shipping_price = 18.53') self.logout_customer(False) self.login_crm(PVS_ROOT_UID, PVS_ROOT_PWD) #delete_new_cart_discount(self, discount_id) self.logout_crm_soft()
def test_quickstart(self): R = self.get('/crm/company/quickstart') R.mustcontain('Quickstart') f = R.forms['frm_quick'] f.set('ent_name', 'Test Enterprise') f.set('cmp_name', 'Test Company') f.set('st_domain', 'test.com') f.set('u_username', '*****@*****.**') f.set('u_fname', 'Ken') f.set('u_lname', 'Bedwell') f.set('u_email', '*****@*****.**') R = f.submit('submit') assert R.status_int == 200 f = R.forms['frm_quick'] enterprise_id = f['enterprise_id'].value Enterprise.full_delete(enterprise_id) Users.full_delete('*****@*****.**') self.commit()
def test_send_with_bad_attachment(self): ent = Enterprise.find_all()[0] comp = Company.find_all(ent.enterprise_id)[0] mail = UserMail(comp.default_campaign) rand_subj = random.random() excepted = False try: mail.send('*****@*****.**', 'test %s' % rand_subj, 'this should never make it. bogus attachment.', 'BOGUS.txt') except IOError as ioe: excepted = True assert excepted
def _edit_impl(self, user_id=None): user = priv = None if user_id: user = self.request.ctx.user if self.request.ctx.user.user_id == user_id else Users.load(user_id) priv = user.priv if user.priv else UserPriv() else: user = Users() priv = UserPriv() return { 'enterprises' : util.select_list(Enterprise.find_all(), 'enterprise_id', 'name', True), 'user_types': Users.get_user_types(), 'vendors' : util.select_list(Vendor.find_all(self.enterprise_id), 'vendor_id', 'name', True), 'timezones' : country_timezones('US'), 'user' : user, 'priv' : priv }
def provision(self): ent = Enterprise() ent.bind(self.request.POST, True, 'ent') ent.save() ent.flush() comp = Company() comp.bind(self.request.POST, True, 'cmp') comp.enterprise_id = ent.enterprise_id comp.save() comp.flush() campaign = Campaign() campaign.name = comp.name + ' Default' campaign.company_id = comp.company_id campaign.save() campaign.flush() comp.default_campaign_id = campaign.campaign_id comp.save() comp.flush() user = Users() user.bind(self.request.POST, True, 'u') user.password = Users.encode_password('password') user.enterprise_id = ent.enterprise_id user.type = 'Admin' user.save() user.flush() site = Site() site.bind(self.request.POST, True, 'st') site.company = comp site.description = comp.name + ' Site' site.creator = user #site.template = Template.find_by_name('default') site.save() site.flush() return { 'enterprise' : ent, 'company' : comp, 'campaign' : campaign, 'user' : user, 'site' : site, 'done' : True }
def _test_save_status(self): ent = Enterprise.find_by_name('Healthy U Store') product_id = self._create_new() product = Product.load(product_id) events = StatusEvent.find_all_applicable(ent.enterprise_id, product) R = self.post('/crm/product/save_status', {'product_id': product_id, 'note' : 'Test Note %s' % product_id, 'event_id' : events[0].event_id}) assert R.status_int == 200 R.mustcontain('Product Event History') R.mustcontain('Test Note %s' % product_id) # assert that the edit page has the name of the event in green # at the top. R = self.get('/crm/product/edit/%s' % product_id) assert R.status_int == 200 R.mustcontain('Edit Product') R.mustcontain(events[0].short_name) self._delete_new(product_id)
def exclog_tween(request, get_logger=logging.getLogger): # getLogger injected for testing purposes try: return handler(request) except ignored: raise except: logger = get_logger('exc_logger') ent = Enterprise.load(request.session['enterprise_id']) if 'enterprise_id' in request.session else None cust = Customer.load(request.session['customer_id']) if 'customer_id' in request.session else None user = Users.load(request.session['user_id']) if 'user_id' in request.session else None if extra_info: message = dedent("""\n %(url)s ENTERPRISE: %(ent)s CUSTOMER: %(cust)s USER: %(user)s SESSION %(sess)s ENVIRONMENT %(env)s PARAMETERS %(params)s """ % dict(url=request.url, sess=pformat(request.session.items()), ent ="%s : %s" % (ent.enterprise_id, ent.name) if ent else None, cust="%s : %s" % (cust.customer_id, cust.email) if cust else None, user="******" % (user.user_id, user.email) if user else None, env=pformat(request.environ), params=pformat(request.params))) else: message = request.url logger.exception(message) raise
def _test_save_inventory(self): ent = Enterprise.find_by_name('Healthy U Store') cmpns = Campaign.find_all(ent.enterprise_id) R = self.get('/crm/product/inventory_list') assert R.status_int == 200 prods = json.loads(R.body) self.assertGreater(prods['records'], 100) self.assertEqual(prods['records'], len(prods['rows'])) # get the first product ID prod = prods['rows'][1]['cell'] # ['', '1451', '5-HTP 100 mg- Pharmax', 'SUP-1003', 'Seroyal', '123', '8.0', '15.0', '25.00', '', '25.00', '25.00'] pid = prod[1] name = prod[2] #sku = prod[3] #manu = prod[4] inventory = int(prod[5]) inventory_par = prod[6] unitcost = prod[7] R = self.post('/crm/product/save_inventory', {'id' : pid, 'inventory' : inventory + 10, 'inventory_par' : inventory_par, 'name' : name + ' xxx', 'unit_cost' : unitcost, 'cmp_%s' % cmpns[0].campaign_id : '999', 'cmp_%s' % cmpns[1].campaign_id : ''}) self.assertEquals(R.body, 'True') prod = Product.load(pid) tot = InventoryJournal.total(prod) self.assertEqual(tot, inventory + 10) self.assertEqual(999, prod.campaign_prices[cmpns[0].campaign_id].retail_price) self.assertEqual(True, cmpns[1].campaign_id not in prod.campaign_prices.keys()) R = self.get('/crm/product/edit/%s' % pid) assert R.status_int == 200 f = R.forms['frm_product'] R.mustcontain('Edit Product') self.assertEqual(f['product_id'].value, pid) self.assertEqual(f['name'].value, name + ' xxx')
def test_complete_po(self): purchase_order_id = self._create_new() ent = Enterprise.find_by_name('Healthy U Store') prods = Product.find_all(ent.enterprise_id) product_id = prods[0].product_id # add a new one R = self.post('/crm/purchase/save_purchase_order_item/%s?product_id=%s' % (str(purchase_order_id), product_id), {'order_note' : 'Note Note', 'quantity' : 10, 'unit_cost' : 123}) json.loads(R.body) assert R.status_int == 200 R = self.get('/crm/purchase/complete/%s' % purchase_order_id) assert R.status_int == 200 R.mustcontain('True') R = self.get('/crm/purchase/edit/%s' % purchase_order_id) assert R.status_int == 200 R.mustcontain('Completed:') self._delete_new(purchase_order_id)
def test_order_item_add_delete(self): ent = Enterprise.find_by_name('Healthy U Store') purchase_order_id = self._create_new() prods = Product.find_all(ent.enterprise_id) product_id = prods[0].product_id # add a new one R = self.post('/crm/purchase/save_purchase_order_item/%s?product_id=%s' % (str(purchase_order_id), product_id), {'order_note' : 'Note Note', 'quantity' : 10, 'unit_cost' : 123}) oitem = json.loads(R.body) assert R.status_int == 200 order_item_id = oitem['id'] # get the json from it R = self.get('/crm/purchase/order_item_json/%s/%s' % (purchase_order_id, order_item_id)) assert R.status_int == 200 oitem = json.loads(R.body) self.assertEqual(oitem['order_item_id'], order_item_id) self.assertEqual(oitem['note'], 'Note Note') self.assertEqual(int(oitem['unit_cost']), 123) self.assertEqual(int(oitem['quantity']), 10) # complete the item R = self.get('/crm/purchase/complete_item/%s/%s' % (purchase_order_id, order_item_id)) assert R.status_int == 200 R.mustcontain('True') #R = self.get('/crm/purchase/show_history/%s' % purchase_order_id) #assert R.status_int == 200 #R.mustcontain('PurchaseOrder Completed') # delete the oi R = self.get('/crm/purchase/delete_purchase_order_item/%s/%s' % (purchase_order_id, order_item_id)) assert R.status_int == 200 R.mustcontain('True') self._delete_new(purchase_order_id)
def _create_new(self): ent = Enterprise.find_by_name('Healthy U Store') vendors = Vendor.find_all(ent.enterprise_id) ven = vendors[0] R = self.get('/crm/purchase/new') assert R.status_int == 200 R.mustcontain('Edit Supplier Order') f = R.forms['frm_purchase'] self.assertEqual(f['purchase_order_id'].value, '') f.set('vendor_id', ven.vendor_id) f.set('shipping_cost', 123.45) f.set('note', 'Test Purchase Order') R = f.submit() self.assertEqual(R.status_int, 302) R = R.follow() assert R.status_int == 200 f = R.forms['frm_purchase'] R.mustcontain('Edit Supplier Order') purchase_order_id = f['purchase_order_id'].value self.assertNotEqual(f['purchase_order_id'].value, '') return purchase_order_id
def test_purchase_cart(self): ent = Enterprise.find_by_name('Healthy U Store') api = StripeBillingApi(ent) self._clear_cart() prod = self.get_prod() self._add_product(prod, 2) R = self.get('/cart/catalog_cart') assert R.status_int == 200 assert 'product_id=%s' % prod.product_id in R.body assert 'quantity=%s/2.0' % prod.product_id in R.body R = self.get('/ecom/cart/update/%s/9' % prod.product_id) assert R.status_int == 200 assert R.body == 'True' R = self.get('/cart/catalog_cart') assert R.status_int == 200 assert 'product_id=%s' % prod.product_id in R.body assert 'quantity=%s/9.0' % prod.product_id in R.body R = self.post("/crm/customer/purchase_cart", {'redir' : '/ecom/page/catalog_thanks', 'accept_terms' : '1', 'bill_cc_token' : api.create_token('4242424242424242', '12', '2019', '123')}) assert R.status_int == 200 R.mustcontain('Thanks for your purchase')
def save_enterprise(self): ent = Enterprise.load(self.request.POST.get('enterprise_id')) if not ent: ent = Enterprise() ent.bind(self.request.POST) ent.save() ent.flush() ent.clear_attributes() for i in range(10): attr_name = self.request.POST.get('attr_name[%d]' % i) attr_value = self.request.POST.get('attr_value[%d]' % i) if attr_name and attr_value: ent.set_attr(attr_name, attr_value) self.request.session.flash('Successfully saved %s.' % ent.name) return HTTPFound('/crm/company/enterprise/edit/%s' % ent.enterprise_id)
def list_enterprises(self): return {'enterprises' : Enterprise.find_all()}
def get_prods(self): ent = Enterprise.find_all()[0] prods = Product.find_all(ent.enterprise_id) assert len(prods) > 0 return prods
def _delete_new_enterprise(self, enterprise_id): ent = Enterprise.load(enterprise_id) self.assertNotEqual(ent, None) ent.delete() self.commit()
def _test_save_existing(self): ent = Enterprise.find_by_name('Healthy U Store') cmpns = Campaign.find_all(ent.enterprise_id) product_id = self._create_new() R = self.get('/crm/product/list') assert R.status_int == 200 R.mustcontain('Test Product') R.mustcontain('Product Search') # make sure product search is in 2 places R = self.get('/crm/product/edit/%s' % product_id) R.mustcontain('Edit Product') f = R.forms['frm_product'] self.assertEqual(f['product_id'].value, product_id) self.assertEqual(f['name'].value, 'Test Product') self.assertEqual(f['seo_keywords'].value, 'SEO Test') f.set('name', 'Test Product New') f.set('seo_keywords', 'SEO Test New') for prod in Product.find_all_except(Product.load(product_id))[:3]: f.set('child_incl_%s' % prod.product_id, prod.product_id) f.set('child_quantity_%s' % prod.product_id, 2) f.set('campaign_price[%s]' % cmpns[0].campaign_id, "123") f.set('campaign_price[%s]' % cmpns[1].campaign_id, None) f.set('prod_inventory', 25) #cat = ProductCategory.find_all(ent.enterprise_id)[0] #f.set('category_id', cat.category_id) R = f.submit('submit') self.assertEqual(R.status_int, 302) R = R.follow() assert R.status_int == 200 f = R.forms['frm_product'] R.mustcontain('Edit Product') self.assertEqual(f['product_id'].value, product_id) self.assertEqual(f['name'].value, 'Test Product New') self.assertEqual(f['seo_keywords'].value, 'SEO Test New') self.assertEqual(f['campaign_price[%s]' % cmpns[0].campaign_id].value, "123.00") self.assertEqual(f['campaign_price[%s]' % cmpns[1].campaign_id].value, "") #self.assertEqual(f['category_id'].value, cat.category_id) prod = Product.load(product_id) self.assertEqual(25, InventoryJournal.total(prod)) for prod in Product.find_all_except(Product.load(product_id))[:3]: self.assertEqual(int(f['child_quantity_%s' % prod.product_id].value), 2) #put pricing back. R = self.get('/crm/product/edit/%s' % product_id) R.mustcontain('Edit Product') f = R.forms['frm_product'] self.assertEqual(f['product_id'].value, product_id) f.set('campaign_price[%s]' % cmpns[0].campaign_id, "123") f.set('campaign_price[%s]' % cmpns[1].campaign_id, "234") R = f.submit('submit') self.assertEqual(R.status_int, 302) R = R.follow() assert R.status_int == 200 f = R.forms['frm_product'] R.mustcontain('Edit Product') self.assertEqual(f['product_id'].value, product_id) self.assertEqual(f['campaign_price[%s]' % cmpns[1].campaign_id].value, "234.00") self._delete_new(product_id)
def _remember_enterprise(request): if 'enterprise_id' in request.session: request.ctx.enterprise = Enterprise.load(request.session['enterprise_id']) else: request.ctx.enterprise = request.ctx.site.company.enterprise request.session['enterprise_id'] = request.ctx.enterprise.enterprise_id