예제 #1
0
 def delete_picture(self):
     product_id = self.request.matchdict.get('product_id')
     product = Product.load(product_id)
     self.forbid_if(not product or product.company.enterprise_id != self.enterprise_id)
     asset_id = self.request.matchdict.get('asset_id')
     asset = Asset.load(asset_id)
     self.forbid_if(asset.fk_type != 'Product' or str(asset.fk_id) != str(product.product_id))
     asset.delete()
     return 'True'
예제 #2
0
 def _test_upload_picture(self):
     product_id = self._create_new()
     # http://stackoverflow.com/questions/2488978/nose-tests-file-uploads
     files = [("Filedata", "testimage.jpg", "not really a jpg")]
     R = self.app.post('/crm/product/upload_picture/%s' % str(product_id),
                       upload_files=files)
     assert R.status_int == 200
     asset_id = R.body
     ass = Asset.load(asset_id)
     assert ass is not None
     assert os.path.exists(ass.filesystem_path)
     ass.delete()
     assert not os.path.exists(ass.filesystem_path)
     self._delete_new(product_id)
예제 #3
0
 def _file_edit_impl(self):
     site = Site.load(self.request.matchdict.get('site_id'))
     self.forbid_if(site.company.enterprise_id != self.enterprise_id)
     asset_id = self.request.matchdict.get('asset_id')
     if asset_id:
         asset = Asset.load(asset_id)
         self.forbid_if(not asset
                        or str(asset.enterprise_id) != str(self.enterprise_id))
     else:
         asset = Asset()
     return {
         'site' : site,
         'asset' : asset
         }
예제 #4
0
 def test_upload_asset(self):
     listing_id = self._create_new()
     # http://stackoverflow.com/questions/2488978/nose-tests-file-uploads
     listing = Listing.load(listing_id)
     assert listing is not None
     files = [("Filedata", "testfile.txt", "testfile.txt contents")]
     R = self.app.post('/crm/listing/upload/%s/%s' % (listing_id, listing.hash),
                       upload_files=files)
     assert R.status_int == 200
     asset_id = R.body
     ass = Asset.load(asset_id)
     assert ass.web_path is not None
     assert str(ass.id) in ass.web_path
     assert ass.exists
     assert ass is not None
     assert ass.get_listing().listing_id == listing.listing_id
     listings = Listing.find_all_pending_approval(self.site.company.enterprise_id)
     assert len(listings) > 0
     assert listings[0].listing_id == listing.listing_id
     self._delete_new(listing_id)