def test_adjust_sell_should_only_work_when_sell(self): follower = XueQiuFollower() follower._adjust_sell = True test_transaction = { "weight": 10, "prev_weight": 0, "price": 10, "stock_symbol": "162411", "created_at": int(time.time() * 1000), } test_assets = 1000 mock_adjust_sell_amount = mock.MagicMock() follower._adjust_sell_amount = mock_adjust_sell_amount follower.project_transactions( transactions=[test_transaction], assets=test_assets ) mock_adjust_sell_amount.assert_not_called() mock_adjust_sell_amount.reset_mock() test_transaction["prev_weight"] = test_transaction["weight"] + 1 follower.project_transactions( transactions=[test_transaction], assets=test_assets ) mock_adjust_sell_amount.assert_called()
def test_adjust_sell_amount_without_enable(self): follower = XueQiuFollower() mock_user = mock.MagicMock() follower._users = [mock_user] follower._adjust_sell = False amount = follower._adjust_sell_amount("169101", 1000) self.assertEqual(amount, amount)
def test_adjust_sell_amount_without_enable(self): follower = XueQiuFollower() mock_user = mock.MagicMock() follower._users = [mock_user] follower._adjust_sell = False amount = follower._adjust_sell_amount("169101", 1000) self.assertEqual(amount, amount)
def test_adjust_sell_amount(self): follower = XueQiuFollower() mock_user = mock.MagicMock() follower._users = [mock_user] mock_user.position = TEST_POSITION follower._adjust_sell = True test_cases = [ ("169101", 600, 600), ("169101", 700, 600), ("000000", 100, 100), ("sh169101", 700, 600), ] for stock_code, sell_amount, excepted_amount in test_cases: amount = follower._adjust_sell_amount(stock_code, sell_amount) self.assertEqual(amount, excepted_amount)
def test_adjust_sell_amount(self): follower = XueQiuFollower() mock_user = mock.MagicMock() follower._users = [mock_user] mock_user.position = TEST_POSITION follower._adjust_sell = True test_cases = [ ("169101", 600, 600), ("169101", 700, 600), ("000000", 100, 100), ("sh169101", 700, 600), ] for stock_code, sell_amount, excepted_amount in test_cases: amount = follower._adjust_sell_amount(stock_code, sell_amount) self.assertEqual(amount, excepted_amount)
def test_adjust_sell_should_only_work_when_sell(self): follower = XueQiuFollower() follower._adjust_sell = True test_transaction = { "weight": 10, "prev_weight": 0, "price": 10, "stock_symbol": "162411", "created_at": int(time.time() * 1000), } test_assets = 1000 mock_adjust_sell_amount = mock.MagicMock() follower._adjust_sell_amount = mock_adjust_sell_amount follower.project_transactions(transactions=[test_transaction], assets=test_assets) mock_adjust_sell_amount.assert_not_called() mock_adjust_sell_amount.reset_mock() test_transaction["prev_weight"] = test_transaction["weight"] + 1 follower.project_transactions(transactions=[test_transaction], assets=test_assets) mock_adjust_sell_amount.assert_called()