Ejemplo n.º 1
0
def __add_headers_to_kwargs(kwargs):
    """
    Add authorization key to the headers in keyword arguments.

    :param kwargs: dict
    """
    auth = Authorization()
    if 'headers' in kwargs:
        for key, value in auth.header.items():
            kwargs['headers'][key] = value
    else:
        kwargs['headers'] = auth.header
Ejemplo n.º 2
0
    def test_search(self):
        try:
            _ = Authorization().key
        except LCError:
            pytest.skip("skip test: cannot find authorization key")

        listing = loan.Listing()
        listing.search()
        assert isinstance(listing.loans, collections.Iterable)

        grade = random.choice('ABCDEFG')
        loans = listing.filter(filter.FilterByGrade(grade))
        assert isinstance(loans, collections.Iterable)
        assert len(loans) >= 0
        for selected_loan in loans:
            assert selected_loan.grade == grade

        term = 36
        percentage = 75.0
        loans = listing.filter(filter.FilterByTerm(value=term),
                               filter.FilterByFunded(percentage))
        assert len(loans) >= 0
        for selected_loan in loans:
            assert selected_loan.term == term
            assert selected_loan.percent_funded >= percentage

        traits = (filter.BorrowerEmployedTrait(), )
        loans = listing.filter(filter.FilterByBorrowerTraits(traits))
        assert len(loans) >= 0
        for selected_loan in loans:
            assert selected_loan.borrower.employed

        # Chain the filters
        loans = listing.filter(filter.FilterByGrade(grade),
                               filter.FilterByTerm(value=term),
                               filter.FilterByApproved())
        new_loans = listing.filter(filter.FilterByGrade(grade)).filter(
            filter.FilterByTerm(value=term)).filter(filter.FilterByApproved())
        assert loans == new_loans
Ejemplo n.º 3
0
    def test_order(self):
        try:
            _ = Authorization().key
        except LCError:
            pytest.skip("skip test: cannot find authorization key")

        # Search loans matching our criteria
        listing = loan.Listing()
        listing.search()

        loans = listing.filter(
            FilterByTerm(value=36),
            FilterByGrade(grades='AB'),
            FilterByFunded(percentage=80),
            FilterByApproved(),
        )

        # Now narrow it down to borrowers with specific traits
        traits = (BorrowerEmployedTrait(), )
        loans = loans.filter(FilterByBorrowerTraits(traits))

        account = InvestorAccount()
        balance = account.available_balance

        # Diversify
        notes = list()
        for selected_loan in loans:
            if balance >= 25:
                note = OrderNote(selected_loan.id, 25)
                balance -= 25
                notes.append(note)
            else:
                break

        if notes:
            order = Order(account.id(), *notes)
            assert order.successful
Ejemplo n.º 4
0
 def test_api_config_env(self):
     auth = Authorization()
     assert auth.key == TestAuthAPIConfigEnv.key
Ejemplo n.º 5
0
 def test_api_key_env(self):
     auth = Authorization()
     assert auth.key == os.getenv(API_KEY_ENV)
Ejemplo n.º 6
0
 def test_header(self):
     auth = Authorization()
     assert auth.header == {'Authorization': auth.key}