Skip to content

Commit

Permalink
attempt to fix windows failures and add test for failure to get orders
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgolec committed May 14, 2024
1 parent c133e80 commit c6056f6
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions tests/scripts/orders_codegen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,42 @@ def test_success_account_hash(
call('# Order ID', 401),
call(mock_code_for_builder.return_value)])


@no_duplicates
@patch('builtins.print')
@patch('schwab.scripts.orders_codegen.client_from_token_file')
@patch('schwab.scripts.orders_codegen.construct_repeat_order')
@patch('schwab.scripts.orders_codegen.code_for_builder')
def test_order_fetching_fails(
self,
mock_code_for_builder,
mock_construct_repeat_order,
mock_client_from_token_file,
mock_print):
self.add_arg('--token_file')
self.add_arg('filename.json')
self.add_arg('--api_key')
self.add_arg('api-key')
self.add_arg('--app_secret')
self.add_arg('app-secret')

mock_client = MagicMock()
mock_client_from_token_file.return_value = mock_client
mock_client.get_orders_for_all_linked_accounts.return_value \
= httpx.Response(400)

self.assertEqual(self.main(), -1)

mock_print.assert_called_once_with(
AnyStringWith('Returned HTTP status code 400'))



class ScriptInvocationTest(unittest.TestCase):

def test_get_help(self):
res = subprocess.run(
output = subprocess.check_output(
'schwab-order-codegen.py --help',
shell=True, check=True, text=True, capture_output=True)
print(res.stdout)
shell=True, text=True)
self.assertIn('Utilities for generating code from historical orders',
res.stdout)
output)

0 comments on commit c6056f6

Please sign in to comment.