Fix journald unittests

d7df072b96 changed how we call
journal.send() from positional arguments to keyword arguments.  So we
need to update the test to check for the arguments it was called with in
the keyword args, not in the positional args.
pull/43268/head
Toshio Kuratomi 6 years ago
parent dbff49dee0
commit 5b4a7cc283

@ -120,7 +120,7 @@ class TestAnsibleModuleLogJournal:
assert journal_send.called == 1 assert journal_send.called == 1
# Message # Message
# call_args is a 2-tuple of (arg_list, kwarg_dict) # call_args is a 2-tuple of (arg_list, kwarg_dict)
assert journal_send.call_args[0][0].endswith('unittest no_log'), 'Message was not sent to log' assert journal_send.call_args[1]['MESSAGE'].endswith('unittest no_log'), 'Message was not sent to log'
# log adds this journal field # log adds this journal field
assert 'MODULE' in journal_send.call_args[1] assert 'MODULE' in journal_send.call_args[1]
assert 'basic.py' in journal_send.call_args[1]['MODULE'] assert 'basic.py' in journal_send.call_args[1]['MODULE']
@ -133,14 +133,14 @@ class TestAnsibleModuleLogJournal:
journal_send = mocker.patch('systemd.journal.send') journal_send = mocker.patch('systemd.journal.send')
am.log(msg) am.log(msg)
assert journal_send.call_count == 1, 'journal.send not called exactly once' assert journal_send.call_count == 1, 'journal.send not called exactly once'
assert journal_send.call_args[0][0].endswith(param) assert journal_send.call_args[1]['MESSAGE'].endswith(param)
@pytest.mark.parametrize('stdin', ({},), indirect=['stdin']) @pytest.mark.parametrize('stdin', ({},), indirect=['stdin'])
def test_log_args(self, am, mocker): def test_log_args(self, am, mocker):
journal_send = mocker.patch('systemd.journal.send') journal_send = mocker.patch('systemd.journal.send')
am.log('unittest log_args', log_args=dict(TEST='log unittest')) am.log('unittest log_args', log_args=dict(TEST='log unittest'))
assert journal_send.called == 1 assert journal_send.called == 1
assert journal_send.call_args[0][0].endswith('unittest log_args'), 'Message was not sent to log' assert journal_send.call_args[1]['MESSAGE'].endswith('unittest log_args'), 'Message was not sent to log'
# log adds this journal field # log adds this journal field
assert 'MODULE' in journal_send.call_args[1] assert 'MODULE' in journal_send.call_args[1]

Loading…
Cancel
Save