From 94b8cb1c374df75992a0217cbec588bb405316a5 Mon Sep 17 00:00:00 2001 From: Johan Lorenzo Date: Tue, 30 Jan 2018 19:07:42 +0100 Subject: [PATCH] Make "timeout_in_seconds" optional --- examples/config.example.json | 5 +++-- shipitscript/ship_actions.py | 2 +- shipitscript/test/test_ship_actions.py | 13 ++++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/examples/config.example.json b/examples/config.example.json index 49a2010..c595306 100644 --- a/examples/config.example.json +++ b/examples/config.example.json @@ -4,9 +4,10 @@ "ship_it_instances": { "project:releng:ship-it:dev": { + "api_root": "http://ship-it.tld/", + "timeout_in_seconds": 60, "username": "some@user.name", - "password": "50mep@ssword", - "api_root": "http://ship-it.tld/" + "password": "50mep@ssword" } }, diff --git a/shipitscript/ship_actions.py b/shipitscript/ship_actions.py index 29f8d2d..763d8d6 100644 --- a/shipitscript/ship_actions.py +++ b/shipitscript/ship_actions.py @@ -12,7 +12,7 @@ def mark_as_shipped(ship_it_instance_config, release_name): """ auth = (ship_it_instance_config['username'], ship_it_instance_config['password']) api_root = ship_it_instance_config['api_root'] - timeout_in_seconds = int(ship_it_instance_config['timeout_in_seconds']) + timeout_in_seconds = int(ship_it_instance_config.get('timeout_in_seconds', 60)) release_api = shipitapi.Release(auth, api_root=api_root, timeout=timeout_in_seconds) shipped_at = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') diff --git a/shipitscript/test/test_ship_actions.py b/shipitscript/test/test_ship_actions.py index 4a849bb..8c99504 100644 --- a/shipitscript/test/test_ship_actions.py +++ b/shipitscript/test/test_ship_actions.py @@ -1,3 +1,4 @@ +import pytest import shipitapi from freezegun import freeze_time @@ -7,7 +8,12 @@ @freeze_time('2018-01-19 12:59:59') -def test_mark_as_shipped(monkeypatch): +@pytest.mark.parametrize('timeout, expected_timeout', ( + (1, 1), + ('10', 10), + (None, 60), +)) +def test_mark_as_shipped(monkeypatch, timeout, expected_timeout): ReleaseClassMock = MagicMock() release_instance_mock = MagicMock() ReleaseClassMock.side_effect = lambda *args, **kwargs: release_instance_mock @@ -17,15 +23,16 @@ def test_mark_as_shipped(monkeypatch): 'username': 'some-username', 'password': 'some-password', 'api_root': 'http://some.ship-it.tld/api/root', - 'timeout_in_seconds': 1, } + if timeout is not None: + ship_it_instance_config['timeout_in_seconds'] = timeout release_name = 'Firefox-59.0b1-build1' mark_as_shipped(ship_it_instance_config, release_name) ReleaseClassMock.assert_called_with( ('some-username', 'some-password'), api_root='http://some.ship-it.tld/api/root', - timeout=1, + timeout=expected_timeout, ) release_instance_mock.update.assert_called_with( 'Firefox-59.0b1-build1', status='shipped', shippedAt='2018-01-19 12:59:59'