This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/data/model/test/test_log.py

40 lines
1.5 KiB
Python
Raw Normal View History

2017-02-28 04:57:40 +00:00
import pytest
from data.model.log import log_action
from peewee import PeeweeException
from mock import Mock
@pytest.mark.parametrize( 'unlogged_pulls_ok,action_kind,db_exception,throws', [
(False, 'pull_repo', None, False),
(False, 'push_repo', None, False),
(False, 'pull_repo', PeeweeException, True),
(False, 'push_repo', PeeweeException, True),
(True, 'pull_repo', PeeweeException, False),
(True, 'push_repo', PeeweeException, True),
(True, 'pull_repo', Exception, True)
])
def test_log_action(unlogged_pulls_ok, action_kind, db_exception, throws, app_config, logentry):
log_args = {
'performer': Mock(id='TEST_PERFORMER_ID'),
'repository': Mock(id='TEST_REPO'),
'ip': 'TEST_IP',
'metadata': {'test_key': 'test_value'},
'timestamp': 'TEST_TIMESTAMP'
}
app_config['SERVICE_LOG_ACCOUNT_ID'] = 'TEST_ACCOUNT_ID'
app_config['ALLOW_PULLS_WITHOUT_STRICT_LOGGING'] = unlogged_pulls_ok
logentry.create.side_effect = db_exception
if throws:
with pytest.raises(db_exception):
log_action(action_kind, None, **log_args)
else:
log_action(action_kind, None, **log_args)
logentry.create.assert_called_once_with(kind=action_kind+'_kind', account='TEST_ACCOUNT_ID',
performer='TEST_PERFORMER_ID', repository='TEST_REPO',
ip='TEST_IP', metadata_json='{"test_key": "test_value"}',
datetime='TEST_TIMESTAMP')