Created
November 9, 2017 17:09
-
-
Save mrzechonek/fa21ec764539a32ea2b4dd036a32ed9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@pytest.mark.asyncio | |
@pytest.mark.django_db | |
async def test_refresh_existing_cash(zmq_context, event_loop, | |
update_task, broker_task, | |
admin_user, test_month): | |
stocks, sessions, quotes = test_month | |
portfolio = Portfolio.objects.create(user=admin_user, name='Test Portfolio') | |
transaction = Transaction.objects.create(portfolio=portfolio, session=sessions[0]) | |
TransactionItemCash.objects.create(transaction=transaction, cash=10000, commission=30) | |
sub_socket = zmq_context.socket(zmq.SUB) | |
sub_socket.connect(reverse_msg('balance')) | |
sub_socket.setsockopt(zmq.SUBSCRIBE, str(portfolio.id).encode('ascii')) | |
reply, body = await event_loop.run_in_executor( | |
None, | |
functools.partial( | |
update_task.refresh, | |
portfolio | |
) | |
) | |
assert reply | |
assert body == portfolio.id | |
for date in (datetime(2017, 1, 1), datetime(2017, 1, 2)): | |
*_, balance = await asyncio.wait_for(pop(sub_socket, schema=BalanceSchema()), timeout=5.0) | |
assert balance == {'session.date': date.date(), 'value': 0, 'cash': Decimal('9970.00')} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment