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 _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_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(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_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_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_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 _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 _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)