コード例 #1
0
    def testSimple(self):
        """
        create a single transaction with PAYMENT_TYPE_AUTHORIZATION / ACTIVE with a $12.34 pledge and see whether the payment
        manager can query and get the right amount.
        """
        user = User.objects.create_user('payment_test', '*****@*****.**',
                                        'payment_test')

        w = Work()
        w.save()
        c = Campaign(target=D('1000.00'),
                     deadline=now() + timedelta(days=180),
                     work=w)
        c.save()

        t = Transaction()
        t.amount = D('12.34')
        t.type = PAYMENT_TYPE_AUTHORIZATION
        t.status = 'ACTIVE'
        t.approved = True
        t.campaign = c
        t.user = user
        t.save()

        #test pledge adders
        user.profile.reset_pledge_badge()
        self.assertEqual(user.profile.badges.all()[0].name, 'pledger')

        p = PaymentManager()
        results = p.query_campaign(c, campaign_total=True, summary=False)
        self.assertEqual(results[0].amount, D('12.34'))
        self.assertEqual(c.left, c.target - D('12.34'))
        self.assertEqual(c.supporters_count, 1)
コード例 #2
0
ファイル: tests.py プロジェクト: kznmft/regluit
class CampaignUiTests(TestCase):
    def setUp(self):
        self.user = User.objects.create_user('test', '*****@*****.**', 'test')
        self.client = Client()
        # load a Work and a Campaign to create a Pledge page
        self.work = Work(title="test Work")
        self.work.save()
        self.campaign = Campaign(target=D('1000.00'), deadline=now() + timedelta(days=180),
                                 work=self.work, description='dummy description')
        self.campaign.save()

        rh = RightsHolder(owner = self.user, rights_holder_name = 'rights holder name')
        rh.save()
        cl = Claim(rights_holder = rh, work = self.work, user = self.user, status = 'active')
        cl.save()

        self.campaign.activate()

    def test_login_required_for_pledge(self):
        """ Make sure that the user has to be logged in to be able to access a pledge page"""
        pledge_path = reverse("pledge", kwargs={'work_id': self.work.id})
        r = self.client.get(pledge_path)
        self.assertEqual(r.status_code, 302)

        # now login and see whether the pledge page is accessible
        self.client.login(username='******', password='******')
        r = self.client.get(pledge_path)
        self.assertEqual(r.status_code, 200)

    def tearDown(self):
        pass
コード例 #3
0
    def test_paymentmanager_charge(self):
        """
        test regluit.payment.manager.PaymentManager.charge
        
        trying to simulate the conditions of having a bare transaction setup before we try to do
        an instant charge.
        
        """
        user = User.objects.create_user('pm_charge', '*****@*****.**',
                                        'payment_test')
        # need to create an Account to associate with user
        from regluit.payment.stripelib import StripeClient, card, Processor

        sc = StripeClient()

        # valid card and Account
        card0 = card()
        stripe_processor = Processor()
        account = stripe_processor.make_account(user=user, token=card0)

        w = Work()
        w.save()

        c = Campaign(target=D('1000.00'),
                     deadline=now() + timedelta(days=180),
                     work=w)
        c.save()

        t = Transaction(host='stripelib')

        t.max_amount = D('12.34')
        t.type = PAYMENT_TYPE_NONE
        t.status = TRANSACTION_STATUS_NONE
        t.campaign = c
        t.approved = False
        t.user = user

        t.save()

        pm = PaymentManager()
        response = pm.charge(t)

        self.assertEqual(t.status, TRANSACTION_STATUS_COMPLETE)
        self.assertEqual(t.type, EXECUTE_TYPE_CHAINED_INSTANT)
        self.assertEqual(t.amount, D('12.34'))
コード例 #4
0
ファイル: tests.py プロジェクト: kznmft/regluit
    def test_downloads(self):
        if not (settings.TEST_INTEGRATION):
            return

        work = Work(title="online work")
        work.save()

        edition = Edition(work=work)
        edition.save()

        dropbox_url = 'https://www.dropbox.com/s/azaztyvgf6b98bc/stellar-consensus-protocol.pdf?dl=0'
        dropbox_ebook = Ebook.objects.create(format='online',
                                             url=dropbox_url,
                                             edition=edition)
        dropbox_ebf, new_ebf = dl_online(dropbox_ebook)
        self.assertTrue(dropbox_ebf.ebook.filesize)

        jbe_url = 'http://www.jbe-platform.com/content/books/9789027295958'
        jbe_ebook = Ebook.objects.create(format='online',
                                         url=jbe_url,
                                         edition=edition)
        jbe_ebf, new_ebf = dl_online(jbe_ebook)
        self.assertTrue(jbe_ebf.ebook.filesize)
コード例 #5
0
    def test_downloads(self):
        if not (settings.TEST_INTEGRATION):
            return

        work = Work(title="online work")
        work.save()

        edition = Edition(work=work)
        edition.save()

        dropbox_url = 'https://www.dropbox.com/s/h5jzpb4vknk8n7w/Jakobsson_The_Troll_Inside_You_EBook.pdf?dl=0'
        dropbox_ebook = Ebook.objects.create(format='online',
                                             url=dropbox_url,
                                             edition=edition)
        dropbox_ebf, new_ebf = dl_online(dropbox_ebook)
        self.assertTrue(dropbox_ebf.ebook.filesize)

        jbe_url = 'http://www.jbe-platform.com/content/books/9789027295958'
        jbe_ebook = Ebook.objects.create(format='online',
                                         url=jbe_url,
                                         edition=edition)
        jbe_ebf, new_ebf = dl_online(jbe_ebook)
        self.assertTrue(jbe_ebf.ebook.filesize)
コード例 #6
0
def load_from_books(books):
    ''' books is an iterator of book dicts.
        each book must have attributes
        (umich dialect)
        eISBN, ClothISBN, PaperISBN, Publisher, FullTitle, Title, Subtitle, AuthorsList, 
        Author1Last, Author1First, Author1Role, Author2Last, Author2First, Author2Role, Author3Last, 
        Author3First, Author3Role, AuthorBio, TableOfContents, Excerpt, DescriptionLong, 
        DescriptionBrief, BISACCode1, BISACCode2, BISACCode3, CopyrightYear, ePublicationDate, 
        eListPrice, ListPriceCurrencyType, List Price in USD (paper ISBN), eTerritoryRights, 
        SubjectListMARC, , Book-level DOI, URL,	License
        
        '''

    # Goal: get or create an Edition and Work for each given book

    results = []

    for (i, book) in enumerate(books):

        # try first to get an Edition already in DB with by one of the ISBNs in book
        (isbns, edition) = get_isbns(book)
        if len(isbns) == 0:
            continue
        title = get_title(book)
        authors = get_authors(book)

        # if matching by ISBN doesn't work, then create a Work and Edition
        # with a title and the first ISBN
        if not edition:
            work = Work(title=title)
            work.save()
            edition = Edition(title=title, work=work)
            edition.save()
            Identifier.set(type='isbn',
                           value=isbns[0],
                           edition=edition,
                           work=work)

        work = edition.work

        # at this point, work and edition exist
        url = get_url(book)
        if url:
            Identifier.set(type='http', value=url, edition=edition, work=work)

        # make sure each isbn is represented by an Edition
        # also associate authors, publication date, cover, publisher
        for isbn in isbns:
            edition = add_by_isbn_from_google(isbn, work=work)
            if edition and edition.work != work:
                work = merge_works(work, edition.work)
            if not edition:
                edition = Edition(title=title, work=work)
                edition.save()
                Identifier.set(type='isbn',
                               value=isbn,
                               edition=edition,
                               work=work)

            edition.authors.clear()
            for (author, role) in authors:
                edition.add_author(author,
                                   inv_relator_contrib.get(role, 'aut'))
            edition.publication_date = get_pubdate(book)
            edition.cover_image = get_cover(book)
            edition.save()
            edition.set_publisher(get_publisher(book))

        # possibly replace work.description
        description = get_description(book)
        if len(description) > len(work.description):
            work.description = description
            work.save()

        # set language
        lang = get_language(book)
        if lang:
            work.language = lang
            work.save()

        # add a bisac subject (and ancestors) to work
        for bisacsh in get_subjects(book):
            while bisacsh:
                add_subject(bisacsh.full_label, work, authority="bisacsh")
                bisacsh = bisacsh.parent

        logging.info(u'loaded work {}'.format(work.title))
        loading_ok = loaded_book_ok(book, work, edition)

        results.append((book, work, edition))

        try:
            logger.info(u"{} {} {}\n".format(i, title, loading_ok))
        except Exception as e:
            logger.info(u"{} {}\n".format(i, title, str(e)))

    return results