def testCreateOwnershipTransfer(self): """ """ user = self.user_test digital_work = DigitalWork(user=self.user_test, digital_work_file=FIX_URL_JPG, digital_work_hash='hash') digital_work.save() thumbnail = Thumbnail(user=self.user_test, key=FIX_URL_JPG) thumbnail.save() root_piece, editions = APIUtilPiece.create_piece( user, title='title', artist_name='artist_name', num_editions=2, thumbnail=thumbnail, digital_work=digital_work) save_ownershiptransfer = OwnershipTransfer.create( editions[0], self.user_admin, prev_owner=editions[0].owner) save_ownershiptransfer.prev_btc_address = 'dsd' save_ownershiptransfer.new_btc_address = 'qsq' save_ownershiptransfer.save() find_ownershiptransfer = OwnershipTransfer.objects.get( id=save_ownershiptransfer.id) compare_ownerships(self, save_ownershiptransfer, find_ownershiptransfer)
def _createFiles(request, data): if hasattr(request.auth, 'token'): # API User: needs to generate digital work first from url url = data['digital_work_key'] filename = os.path.split(url)[1] key = File.create_key("/".join([filename, "digitalwork"]), filename, request.user) digital_work = DigitalWork(user=request.user, digital_work_file=key) digital_work.save() digital_work.upload(url) else: # WEB User: file created by fineuploader digital_work = DigitalWork.objects.filter( user=request.user, digital_work_file=data['digital_work_key']).order_by('-id')[0] if 'thumbnail_file' in data and data['thumbnail_file']: # Thumbnail already provided thumbnail = data['thumbnail_file'] else: # Create thumbnail from digital_work thumbnail = digital_work.create_thumbnail() if thumbnail is None: # Thumbnail fallback thumbnail = Thumbnail(user=request.user, thumbnail_file=settings.THUMBNAIL_DEFAULT) thumbnail.save() data['digital_work'] = digital_work data['thumbnail'] = thumbnail return data
def testCreateOwnershipRegistration(self): """ """ user = self.user_test digital_work = DigitalWork(user=self.user_test, digital_work_file=FIX_URL_JPG, digital_work_hash='hash') digital_work.save() thumbnail = Thumbnail(user=self.user_test, key=FIX_URL_JPG) thumbnail.save() root_piece, editions = APIUtilPiece.create_piece( user, title='title', artist_name='artist_name', num_editions=2, thumbnail=thumbnail, digital_work=digital_work) save_ownershipregistration = OwnershipRegistration.create( editions[0], self.user_admin) save_ownershipregistration.prev_btc_address = 'dsdfas' save_ownershipregistration.new_btc_address = 'asdsad' save_ownershipregistration.save() find_ownershipregistration = OwnershipRegistration.objects.get( id=save_ownershipregistration.id) compare_ownerships(self, save_ownershipregistration, find_ownershipregistration)
def testUpdateShare(self): """ """ user = self.user_test digital_work = DigitalWork(user=self.user_test, digital_work_file=FIX_URL_JPG, digital_work_hash='hash') digital_work.save() thumbnail = Thumbnail(user=self.user_test, key=FIX_URL_JPG) thumbnail.save() root_piece, editions = APIUtilPiece.create_piece( user, title='title', artist_name='artist_name', num_editions=2, thumbnail=thumbnail, digital_work=digital_work) save_share = Share.create(editions[0], self.user_admin) save_share.save() find_share = Share.objects.get(id=save_share.id) compare_ownerships(self, save_share, find_share) save_share.shared_user = user save_share.save() find_share = Share.objects.get(id=save_share.id) compare_ownerships(self, save_share, find_share) self.assertEqual(find_share.shared_user.username, user.username)
def test_create_thumbnail(self): save_file = Thumbnail(user=self.user_test, key=FIX_KEY_PNG) save_file.save() find_file = Thumbnail.objects.get(thumbnail_file=save_file.key) self.compare_file(save_file, find_file) find_file = Thumbnail.objects.get(id=save_file.id) self.compare_file(save_file, find_file)
def test_save_thumbnail_as_jpg(self): key = 'test/giftest/exifTest.jpg' url = 'https://s3-us-west-2.amazonaws.com/ascribe0/{}'.format(key) thumbnail = Thumbnail(user=self.user_test, thumbnail_file=settings.THUMBNAIL_DEFAULT, thumbnail_sizes={}) thumbnail.save() thumbnail = Thumbnail.thumbnail_from_url(url, key, thumbnail) test_cases = set(thumbnail.thumbnail_sizes.values()) for t in test_cases: Image.open(urllib.urlretrieve(t)[0])
def test_save_tif_as_jpeg_thumbnail(self): key = 'test/imagetests/lenna.tif' url = 'https://s3-us-west-2.amazonaws.com/ascribe0/{}'.format(key) thumbnail = Thumbnail(user=self.user_test, thumbnail_file=settings.THUMBNAIL_DEFAULT, thumbnail_sizes={}) thumbnail.save() thumbnail = Thumbnail.thumbnail_from_url(url, key, thumbnail) thumbnail_formats = [ Image.open(urllib.urlretrieve(thumbnail_url)[0]).format for thumbnail_url in thumbnail.thumbnail_sizes.values() ] self.assertTrue( all(f == 'JPEG' for f in thumbnail_formats), msg='All thumbnails of a TIF file must be of format JPEG')
def create_thumbnail( user, amount=1, thumbnail_file='test/testuser/ascribe_spiral/digitalwork/ascribe_spiral.png' ): if amount == 1: thumbnail = Thumbnail(user=user, thumbnail_file=thumbnail_file) thumbnail.save() return thumbnail else: thumbnails = [ Thumbnail(user=user, thumbnail_file=thumbnail_file) for i in range(amount) ] [t.save() for t in thumbnails] return thumbnails
def testUpdateUnConsignment(self): """ """ user = self.user_test digital_work = DigitalWork(user=self.user_test, digital_work_file=FIX_URL_JPG, digital_work_hash='hash') digital_work.save() thumbnail = Thumbnail(user=self.user_test, key=FIX_URL_JPG) thumbnail.save() root_piece, editions = APIUtilPiece.create_piece( user, title='title', artist_name='artist_name', num_editions=2, thumbnail=thumbnail, digital_work=digital_work) # we need to create a consignment before we can create an unconsignment save_consignment = Consignment.create(editions[0], self.user_admin, owner=editions[0].owner) save_consignment.prev_btc_address = 'dsdfas' save_consignment.new_btc_address = 'asdsad' save_consignment.save() save_unconsignment = UnConsignment.create(editions[0], consignee=self.user_admin, owner=editions[0].owner) save_unconsignment.prev_btc_address = 'dsdfas' save_unconsignment.new_btc_address = 'asdsad' save_unconsignment.save() find_unconsignment = UnConsignment.objects.get( id=save_unconsignment.id) compare_ownerships(self, save_unconsignment, find_unconsignment) save_unconsignment.new_btc_address = 'new_address' save_unconsignment.save() find_unconsignment = UnConsignment.objects.get( id=save_unconsignment.id) compare_ownerships(self, save_unconsignment, find_unconsignment) self.assertEqual(find_unconsignment.new_btc_address, 'new_address')
def testCreateLoan(self): from ..models import Contract user = self.user_test digital_work = DigitalWork(user=self.user_test, digital_work_file=FIX_URL_JPG, digital_work_hash='hash') digital_work.save() thumbnail = Thumbnail(user=self.user_test, key=FIX_URL_JPG) thumbnail.save() root_piece, editions = APIUtilPiece.create_piece( user, title='title', artist_name='artist_name', num_editions=2, thumbnail=thumbnail, digital_work=digital_work) save_loan = Loan.create(editions[0], self.user_admin, owner=editions[0].owner) save_loan.prev_btc_address = 'dsdfas' save_loan.new_btc_address = 'asdsad' save_loan.datetime_from = datetime.combine( self.date, datetime.min.time()).replace(tzinfo=pytz.UTC) save_loan.datetime_to = datetime.combine( self.date, datetime.min.time()).replace(tzinfo=pytz.UTC) save_loan.save() save_file = OtherData.objects.create(user=self.user_test, key=FIX_KEY_PNG) contract = Contract.objects.create(issuer=self.user_test, blob=save_file) loan_details = LoanDetail(loan=save_loan, gallery="gallery", contract_model=contract) loan_details.save() find_loan = Loan.objects.get(id=save_loan.id) compare_ownerships(self, save_loan, find_loan) compare_loan_details(self, save_loan.details, find_loan.details) self.assertEqual(save_loan.details.contract_model.blob.key, FIX_KEY_PNG)
def test_assemble_key_with_ascii_filename(self): from ..models import Thumbnail user_id = 'dummy_user_id' category = 'dummy_category' filename = 'bitcoin.jpg' key = Thumbnail._assemble_key(user_id, category, filename) self.assertEqual( key, '{}/{}/{}/{}'.format(settings.DEPLOYMENT, user_id, category, filename))
def test_assemble_key_with_unicode_filename(self): from ..models import Thumbnail user_id = 'dummy_user_id' category = 'dummy_category' filename = '比特币.jpg' key = Thumbnail._assemble_key(user_id, category, filename) self.assertEqual( key, u'{}/{}/{}/{}'.format(settings.DEPLOYMENT, user_id, category, filename.decode('utf-8')))
def test_resize_gif(self): key = 'test/giftest/ERuXtjY.gif' url = 'https://s3-us-west-2.amazonaws.com/ascribe0/{}'.format(key) thumbnail = Thumbnail(user=self.user_test, thumbnail_file=settings.THUMBNAIL_DEFAULT, thumbnail_sizes={}) thumbnail.save() thumbnail = Thumbnail.thumbnail_from_url(url, key, thumbnail) test_cases = set(thumbnail.thumbnail_sizes.values()) for t in test_cases: try: output_image = Image.open(urllib.urlretrieve(t)[0]) except Exception, e: # Lol print 'Exception ... ' raise AssertionError(e.args) try: output_image.seek(1) except: raise AssertionError('Gif is not animated')
def testUpdateLoan(self): """ """ user = self.user_test digital_work = DigitalWork(user=self.user_test, digital_work_file=FIX_URL_JPG, digital_work_hash='hash') digital_work.save() thumbnail = Thumbnail(user=self.user_test, key=FIX_URL_JPG) thumbnail.save() root_piece, editions = APIUtilPiece.create_piece( user, title='title', artist_name='artist_name', num_editions=2, thumbnail=thumbnail, digital_work=digital_work) save_loan = Loan.create(editions[0], self.user_admin, owner=editions[0].owner) save_loan.prev_btc_address = 'dsdfas' save_loan.new_btc_address = 'asdsad' save_loan.save() find_loan = Loan.objects.get(id=save_loan.id) compare_ownerships(self, save_loan, find_loan) save_loan.new_btc_address = 'new_address' save_loan.save() find_loan = Loan.objects.get(id=save_loan.id) compare_ownerships(self, save_loan, find_loan) self.assertEqual(find_loan.new_btc_address, 'new_address')
#thumbs = Thumbnail.objects.filter(user__isnull=False, thumbnail_file__contains='.gif').exclude(user__pk__in=test_users) thumb_ids = [t.id for t in thumbs] #pieces = [p.id for p in Piece.objects.filter(thumbnail__in=thumb_ids)] #Piece.objects.filter(id__in=pieces).update(thumbnail_id='NULL') Thumbnail.objects.filter(id__in=thumb_ids).delete() new_thumbnails = [] bad_thumbnails = [] for g in gifs: basename = g.associated_key('thumbnail', '', unique=False) try: new_thumbnails.append( Thumbnail.thumbnail_from_url(g.user, g.url, basename)) except Exception as e: print sys.exc_info() print traceback.print_exc() bad_thumbnails.append([sys.exc_info(), g]) print 'new thumbnails' print new_thumbnails print 'bad ones .. ' print bad_thumbnails #for n in new_thumbnails: # piece_name = n.thumbnail_file.split('/')[2] # for g in gifs: # if piece_name in g.digital_work_file: # Piece.objects.filter(digital_work_id=g.id).update(thumbnail_id=n.id)