From 4b669f500da7e64694841ea4e46ce8fda72fd076 Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Thu, 31 May 2018 17:24:18 +0200 Subject: [PATCH] tests: improve remote invoices notification code coverage (#24191) --- tests/test_notification.py | 15 +++++++++++++-- tox.ini | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/test_notification.py b/tests/test_notification.py index f7b111f..899fd05 100644 --- a/tests/test_notification.py +++ b/tests/test_notification.py @@ -276,7 +276,7 @@ def test_notification_id_and_origin(user): @mock.patch('combo.utils.requests_wrapper.RequestsSession.request') -def test_notify_remote_items(mock_get, app, user, user2, regie): +def test_notify_remote_items(mock_get, app, user, user2, regie, monkeypatch): invoice_now = now() creation_date = (invoice_now - timedelta(days=1)).date().isoformat() pay_limit_date = (invoice_now + timedelta(days=20)).date().isoformat() @@ -348,12 +348,23 @@ def test_notify_remote_items(mock_get, app, user, user2, regie): mock_response = mock.Mock(status_code=200, content=json.dumps(FAKE_PENDING_INVOICES)) mock_response.json.return_value = FAKE_PENDING_INVOICES mock_get.return_value = mock_response + + # make sure the regie is not remote + regie.webservice_url = '' + regie.save() + regie.notify_new_remote_invoices() assert mock_get.call_count == 0 regie.webservice_url = 'http://example.org/regie' # is_remote regie.save() regie.notify_new_remote_invoices() - mock_get.assert_not_called() + mock_get.assert_called_once() + + from combo.apps.lingo import models + monkeypatch.setattr(models, 'UserSAMLIdentifier', None) + regie.notify_new_remote_invoices() + # make sure no other requests calls are made + assert mock_get.call_count == 1 with mock.patch('combo.apps.lingo.models.UserSAMLIdentifier') as user_saml: # simulate class exception diff --git a/tox.ini b/tox.ini index 85e7510..287a7e0 100644 --- a/tox.ini +++ b/tox.ini @@ -23,7 +23,9 @@ deps = django-webtest<1.9.3 quixote<3.0 vobject + django-mellon commands = + ./getlasso.sh python manage.py compilemessages py.test {env:COVERAGE:} {posargs:tests/} pylint: ./pylint.sh combo/ -- 2.17.1