Exemple #1
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)
Exemple #2
0
    def testUpdatePiece(self):
        user = self.user1

        save_piece = Piece(title='title',
                           artist_name='artist_name',
                           date_created=self.date,
                           extra_data={'extra_data_string': 'something'},
                           num_editions=2,
                           user_registered=user,
                           digital_work=self.digitalwork_user1)
        save_piece.save()

        old_id = save_piece.id

        digital_work_2 = DigitalWork(user=user,
                                     key=FIX_KEY_PNG,
                                     digital_work_hash='hash2')
        digital_work_2.save()

        save_piece.digital_work = digital_work_2
        save_piece.title = 'updated_title'

        save_piece.save()

        find_piece = Piece.objects.get(title='updated_title')
        self.assertTrue(save_piece == find_piece)
        self.assertEqual(old_id, find_piece.id)
Exemple #3
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)
Exemple #4
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)
Exemple #5
0
    def test_create_digital_work(self):
        save_file = DigitalWork(
            user=self.user_test,
            digital_work_file=
            'local/testuser/ascribe_spiral/digitalwork/ascribe_spiral.png')
        save_file.save()
        self.assertEqual(save_file.hash, 'f702fe80edf519e8fd3a4242fbafef63')
        self.assertEqual(save_file.extension(), '.png')
        self.assertEqual(save_file.basename, 'ascribe_spiral.png')
        self.assertEqual(
            save_file.key,
            'local/testuser/ascribe_spiral/digitalwork/ascribe_spiral.png')
        self.assertEqual(
            urlparse(save_file.url).path,
            urlparse('https://ascribe0.s3.amazonaws.com/local/testuser/'
                     'ascribe_spiral/digitalwork/ascribe_spiral.png').path)
        self.assertEqual(
            urlparse(save_file.url_safe).path,
            urlparse('https://ascribe0.s3.amazonaws.com/local%2Ftestuser%2F'
                     'ascribe_spiral%2Fdigitalwork%2Fascribe_spiral.png').path)
        self.assertEqual(save_file.mime, "image")
        # self.assertEqual(save_file.associated_key(), 'local/testuser/ascribe_spiral/otherdata')

        find_file = DigitalWork.objects.get(digital_work_file=save_file.key)
        self.compare_file(save_file, find_file)
        self.assertEqual(save_file.hash, find_file.hash)
Exemple #6
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')
Exemple #7
0
 def create_digitalwork(
     user,
     amount=1,
     digital_work_file='test/testuser/ascribe_spiral/digitalwork/ascribe_spiral.png'
 ):
     if amount == 1:
         digital_work = DigitalWork(user=user,
                                    digital_work_file=digital_work_file)
         digital_work.save()
         return digital_work
     else:
         digital_works = [
             DigitalWork(user=user, digital_work_file=digital_work_file)
             for i in range(amount)
         ]
         [d.save() for d in digital_works]
         return digital_works
Exemple #8
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
Exemple #9
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)
Exemple #10
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')
Exemple #11
0
def create_key(request):
    body = json.loads(request.body)

    filename = body['filename']
    _, extension = os.path.splitext(filename)
    uuid = body['uuid'] + extension if 'uuid' in body else filename

    # TODO handle key error - use serializer perhaps
    category = body['category']
    if category == 'digitalwork':
        category = '/'.join([body['uuid'], category])
    elif 'piece_id' in body:
        category = DigitalWork.piece_to_category(body['piece_id'], category)

    return Response({'key': File.create_key(category, uuid, request.user)},
                    content_type='application/json')