0001-cook-add-stdin-reading-ability-33631.patch
hobo/environment/management/commands/cook.py | ||
---|---|---|
64 | 64 |
print 'All steps executed successfully. Your environment should now be ready.' |
65 | 65 | |
66 | 66 |
def run_cook(self, filename): |
67 |
recipe = json.load(open(filename)) |
|
67 |
if filename == '-': |
|
68 |
recipe = json.loads(sys.stdin) |
|
69 |
else: |
|
70 |
recipe = json.load(open(filename)) |
|
68 | 71 |
variables = {} |
69 | 72 |
steps = [] |
70 | 73 |
if 'load-variables-from' in recipe: |
tests/test_cook.py | ||
---|---|---|
1 | 1 |
import os |
2 | 2 |
import json |
3 | 3 |
import StringIO |
4 |
import sys |
|
5 |
from functools import partial |
|
4 | 6 | |
5 | 7 |
import pytest |
6 | 8 |
from mock import call, mock_open, patch, Mock |
... | ... | |
98 | 100 |
assert mocked_notify_agents.mock_calls == [] |
99 | 101 |
assert command.wait_operationals.mock_calls == [call(timeout=42)] |
100 | 102 | |
103 |
@patch('hobo.environment.management.commands.cook.notify_agents') |
|
104 |
def test_run_cook_piped(mocked_notify_agents, tmpdir): |
|
105 |
command = Command() |
|
106 |
command.permissive = False |
|
107 |
command.must_notify = True |
|
108 |
command.timeout = 42 |
|
109 |
command.check_action = Mock() |
|
110 |
command.create_hobo = Mock() |
|
111 |
mocked_notify_agents = Mock() |
|
112 |
command.wait_operationals = Mock() |
|
113 | ||
114 |
recipe = {'steps': [{'create-hobo': {'url': 'https://entrouvert.org/'}}]} |
|
115 |
recipe_path = os.path.join(str(tmpdir), 'recipe.json') |
|
116 |
with open(recipe_path, 'w') as handler: |
|
117 |
handler.write(json.dumps(recipe)) |
|
118 | ||
119 |
old_stdin = sys.stdin |
|
120 |
sys.stdin = open(recipe_path).read() |
|
121 |
command.run_cook('-') |
|
122 |
sys.stdin = old_stdin |
|
123 |
assert command.check_action.mock_calls == [ |
|
124 |
call(u'create-hobo', {u'url': u'https://entrouvert.org/'})] |
|
125 |
assert command.create_hobo.mock_calls == [call(url=u'https://entrouvert.org/')] |
|
126 |
assert mocked_notify_agents.mock_calls == [] |
|
127 |
assert command.wait_operationals.mock_calls == [call(timeout=42)] |
|
128 | ||
101 | 129 |
def test_having_several_action_args(tmpdir): |
102 | 130 |
command = Command() |
103 | 131 |
command.permissive = True |
104 |
- |