Beispiel #1
0
def test_stock_create_new_stock():
    """
    Tests Stock.create_new_stock()
    """
    Stock.create_new_stock(ticker="ABC", name="DEF")
    with mock.patch.object(Fetcher, "__init__", side_effect=KeyError()):
        with pytest.raises(Exception):
            Stock.create_new_stock(ticker="ABC", name="DEF")
def test_investmentbucket_value_on():
    """
    Tests InvestmentBucket.value_on()
    """
    user = user_helper()

    value_of_stock1 = 3
    stock = Stock.create_new_stock(name="Name1X", ticker="TKRC")
    stock.daily_quote.create(value=value_of_stock1, date="2016-06-03")
    available = 3
    bucket = InvestmentBucket(name="Bucket Test",
                              public=True,
                              owner=user.profile,
                              available=available)
    bucket.save()

    InvestmentStockConfiguration(
        quantity=1,
        stock=stock,
        bucket=bucket,
        start="2016-06-08",
        end="2016-06-10",
    ).save()

    assert bucket.value_on() == available
    assert bucket.value_on(date="2016-06-08") == available + value_of_stock1
    assert bucket.value_on(date="2016-07-19") == available
def test_tradebucket_current_value():
    """
    Tests TradeBucket.current_value()
    """
    account = account_helper()

    value_of_stock1 = 3
    stock1 = Stock.create_new_stock(name="Name1X", ticker="TKRC")
    stock1.daily_quote.create(value=value_of_stock1, date="2016-06-03")

    invest_bucket = InvestmentBucket(name="Bucket Test",
                                     public=True,
                                     owner=account.profile,
                                     available=1)
    invest_bucket.save()
    InvestmentStockConfiguration(
        quantity=1,
        stock=stock1,
        bucket=invest_bucket,
        start="2016-07-11",
        end="2016-06-10",
    ).save()
    quantity = 4
    trade_bucket = TradeBucket(quantity=quantity,
                               account=account,
                               stock=invest_bucket)
    trade_bucket.save()
    assert trade_bucket.current_value() == -quantity
def test_trading_trading_balance():
    """
    Testing available_cash for a Trading Account
    """
    account = account_helper()

    value_of_stock1 = 3
    stock1 = Stock.create_new_stock(name="Name1X", ticker="TKRC")
    stock1.daily_quote.create(value=value_of_stock1, date="2016-06-03")

    value_of_stock2 = 4
    quantity2 = 3
    stock2 = Stock.create_new_stock(name="Name2X", ticker="TKF")
    stock2.daily_quote.create(value=value_of_stock2, date="2016-06-03")
    TradeStock(quantity=1, account=account, stock=stock1).save()

    value = account.trading_balance()
    assert value == -value_of_stock1

    TradeStock(quantity=quantity2, account=account, stock=stock2).save()
    value = account.trading_balance()
    assert value == -value_of_stock1 + -value_of_stock2 * quantity2
Beispiel #5
0
def test_stock_trades_for_profile():
    """
    Tests Stock.trades_for_profile()
    """
    user1 = User.objects.create(username='******', password="******")
    user2 = User.objects.create(username='******', password="******")
    t1_1 = user1.profile.trading_accounts.create(account_name="u1t1")
    t1_2 = user1.profile.trading_accounts.create(account_name="u1t2")
    t2_1 = user2.profile.trading_accounts.create(account_name="u2t")
    stock = Stock.create_new_stock(name="Name1X", ticker="TKRC")
    TradeStock(quantity=1, account=t1_1, stock=stock).save()
    TradeStock(quantity=1, account=t1_2, stock=stock).save()
    TradeStock(quantity=1, account=t2_1, stock=stock).save()
    assert stock.trades_for_profile(user1.profile).count() == 2
    assert stock.trades_for_profile(user2.profile).count() == 1
def test_tradestock_current_value():
    """
    Tests TradeStock.current_value()
    """
    account = account_helper()

    value_of_stock1 = 3
    stock1 = Stock.create_new_stock(name="Name1X", ticker="TKRC")
    stock1.daily_quote.create(value=value_of_stock1, date="2016-06-03")

    quantity = 3
    current_value = TradeStock(quantity=quantity,
                               account=account,
                               stock=stock1).current_value()
    assert current_value == -value_of_stock1 * quantity
def test_investmentbucket_descrip():
    """
    Tests InvestmentBucketDescription.change_description()
    """
    user = user_helper()

    value_of_stock1 = 3
    stock1 = Stock.create_new_stock(name="Name1X", ticker="TKRC")
    stock1.daily_quote.create(value=value_of_stock1, date="2016-06-03")
    available = 3
    bucket = InvestmentBucket(name="Bucket Test",
                              public=True,
                              owner=user.profile,
                              available=available)
    bucket.save()
    description = InvestmentBucketDescription(text="fladshjfdsa",
                                              is_good=True,
                                              bucket=bucket)
    description.save()
    description.change_description(text="changed")
    assert description.text == "changed"