Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unit tests #14

Open
dwallach1 opened this issue Apr 14, 2024 · 0 comments
Open

add unit tests #14

dwallach1 opened this issue Apr 14, 2024 · 0 comments

Comments

@dwallach1
Copy link
Owner

You can write a unit test using a testing framework like pytest to validate the buy functionality of the DecisionMaker class.

import unittest
from unittest.mock import MagicMock
from main import DecisionMaker, DecisionContext, Asset, Enviorment, RESTClient, MongoClient
from decisions import DecisionType

class TestDecisionMaker(unittest.TestCase):

    def test_buy_asset(self):
        # Mocking necessary dependencies
        cb_client = MagicMock(spec=RESTClient)
        mongo_client = MagicMock(spec=MongoClient)

        # Creating test data
        asset_config = Asset(name="TestAsset", symbol="TEST", account_id="123", amount_to_buy=100.0, buy_price_percentage_change_threshold=0.5, sell_price_percentage_change_threshold=1.0, max_open_buys=2)
        context = DecisionContext(enviorment=Enviorment.TEST, price=100.0, symbol="TEST", asset_balance=10.0, total_asset_value=1000.0, usdc_balance=1000.0, volume_24h=1000.0, volume_percentage_change_24h=0.5, price_percentage_change_24h=1.0, total_asset_holdings_value=1000.0, price_change_check=True, buy_buffer_check=True, open_buy_check=True, open_buy_count=0, open_buy_decisions=[])

        # Creating an instance of DecisionMaker
        decision_maker = DecisionMaker(Enviorment.TEST, cb_client, mongo_client, "test_db", "test_collection", asset_config, "usd_account_id")

        # Mocking the necessary methods for buying
        decision_maker.get_decision_context = MagicMock(return_value=context)
        decision_maker.get_buying_power = MagicMock(return_value=1000.0)
        decision_maker.place_buy_order = MagicMock(return_value={"mock": "buy_order_result"})

        # Running the buy decision
        decision_maker.compute_decisions()

        # Asserting that the buy order was placed
        decision_maker.place_buy_order.assert_called()

if __name__ == '__main__':
    unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant