예제 #1
0
    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)
예제 #2
0
    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
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
 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)
예제 #6
0
 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])
예제 #7
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')
예제 #8
0
 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
예제 #9
0
    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')
예제 #10
0
    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)
예제 #11
0
 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')
예제 #12
0
    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')