def test_new_stack(monkeypatch): test_dir = os.path.dirname(__file__) yaml_path = os.path.join(test_dir, 'test_config.yaml') # we can use any file for this test with open(yaml_path) as yaml_file: senza_yaml = yaml_file.read() mock_post = MagicMock() mock_post.return_value = FakeResponse(200, '{"stack_id":"574CC1D"}') monkeypatch.setattr('requests.post', mock_post) lizzy = Lizzy('https://lizzy.example', '7E5770K3N') stack_id = lizzy.new_stack('10', 2, 42, yaml_path, None, []) header = make_header('7E5770K3N') data = {'image_version': "10", 'keep_stacks': 2, 'new_traffic': 42, 'parameters': [], 'senza_yaml': senza_yaml} mock_post.assert_called_once_with('https://lizzy.example/stacks', headers=header, data=json.dumps(data), json=None, verify=False) assert stack_id == "574CC1D" mock_post.reset_mock() data_with_ver = {'image_version': "10", 'keep_stacks': 2, 'new_traffic': 42, 'parameters': [], 'senza_yaml': senza_yaml, "application_version": "420", } lizzy.new_stack('10', 2, 42, yaml_path, "420", []) mock_post.assert_called_once_with('https://lizzy.example/stacks', headers=header, data=json.dumps(data_with_ver), json=None, verify=False) mock_post.reset_mock() data_with_params = {'image_version': "10", 'keep_stacks': 2, 'new_traffic': 42, 'parameters': ['abc', 'def'], 'senza_yaml': senza_yaml, "application_version": "420", } lizzy.new_stack('10', 2, 42, yaml_path, "420", ['abc', 'def']) mock_post.assert_called_once_with('https://lizzy.example/stacks', headers=header, data=json.dumps(data_with_params), json=None, verify=False)
def test_new_stack(monkeypatch, version, parameters, region, disable_rollback, dry_run, force, tags, keep_stacks, new_traffic): mock_post = MagicMock() mock_post.return_value = FakeResponse(200, STACK1) monkeypatch.setattr('requests.post', mock_post) lizzy = Lizzy('https://lizzy.example', '7E5770K3N') stack, output = lizzy.new_stack(keep_stacks=keep_stacks, new_traffic=new_traffic, senza_yaml={'MyDefinition': 'Values'}, stack_version=version, disable_rollback=disable_rollback, parameters=parameters, dry_run=dry_run, region=region, tags=tags) stack_name = stack['stack_name'] assert stack_name == 'lizzy-bus' header = make_header('7E5770K3N') data = { 'keep_stacks': keep_stacks, 'new_traffic': new_traffic, 'parameters': parameters, 'disable_rollback': disable_rollback, 'dry_run': dry_run, 'senza_yaml': "{MyDefinition: Values}\n", 'stack_version': version, 'tags': tags } # only pass region when it is not None if region: data['region'] = region mock_post.assert_called_once_with('https://lizzy.example/api/stacks', headers=header, json=data, data=None, verify=False)
def test_new_stack(monkeypatch, version, parameters, region, disable_rollback, dry_run, force, tags, keep_stacks, new_traffic): mock_post = MagicMock() mock_post.return_value = FakeResponse(200, STACK1) monkeypatch.setattr('requests.post', mock_post) lizzy = Lizzy('https://lizzy.example', '7E5770K3N') stack, output = lizzy.new_stack(keep_stacks=keep_stacks, new_traffic=new_traffic, senza_yaml={'MyDefinition': 'Values'}, stack_version=version, disable_rollback=disable_rollback, parameters=parameters, dry_run=dry_run, region=region, tags=tags) stack_name = stack['stack_name'] assert stack_name == 'lizzy-bus' header = make_header('7E5770K3N') data = {'keep_stacks': keep_stacks, 'new_traffic': new_traffic, 'parameters': parameters, 'disable_rollback': disable_rollback, 'dry_run': dry_run, 'senza_yaml': "{MyDefinition: Values}\n", 'stack_version': version, 'tags': tags} # only pass region when it is not None if region: data['region'] = region mock_post.assert_called_once_with('https://lizzy.example/api/stacks', headers=header, json=data, data=None, verify=False)
def test_new_stack(monkeypatch): test_dir = os.path.dirname(__file__) yaml_path = os.path.join(test_dir, 'test_config.yaml') # we can use any file for this test with open(yaml_path) as yaml_file: senza_yaml = yaml_file.read() mock_post = MagicMock() mock_post.return_value = FakeResponse(200, '{"stack_id":"574CC1D"}') monkeypatch.setattr('requests.post', mock_post) lizzy = Lizzy('https://lizzy.example', '7E5770K3N') stack_id = lizzy.new_stack(image_version='10', keep_stacks=2, new_traffic=42, senza_yaml_path=yaml_path, application_version=None, stack_version=None, disable_rollback=True, parameters=[]) header = make_header('7E5770K3N') data = {'image_version': "10", 'keep_stacks': 2, 'new_traffic': 42, 'parameters': [], 'disable_rollback': True, 'senza_yaml': senza_yaml} mock_post.assert_called_once_with('https://lizzy.example/stacks', headers=header, data=json.dumps(data, sort_keys=True), json=None, verify=False) mock_post.reset_mock() lizzy = Lizzy('https://lizzy.example', '7E5770K3N') stack_id = lizzy.new_stack(image_version='10', keep_stacks=2, new_traffic=42, senza_yaml_path=yaml_path, application_version=None, stack_version=None, disable_rollback=False, parameters=[]) header = make_header('7E5770K3N') data = {'image_version': "10", 'keep_stacks': 2, 'new_traffic': 42, 'parameters': [], 'disable_rollback': False, 'senza_yaml': senza_yaml} mock_post.assert_called_once_with('https://lizzy.example/stacks', headers=header, data=json.dumps(data, sort_keys=True), json=None, verify=False) assert stack_id == "574CC1D" mock_post.reset_mock() data_with_ver = {'image_version': "10", 'keep_stacks': 2, 'new_traffic': 42, 'parameters': [], 'senza_yaml': senza_yaml, 'disable_rollback': False, "application_version": "420"} lizzy.new_stack('10', 2, 42, yaml_path, None, "420", False, []) mock_post.assert_called_once_with('https://lizzy.example/stacks', headers=header, data=json.dumps(data_with_ver, sort_keys=True), json=None, verify=False) mock_post.reset_mock() data_with_params = {'image_version': "10", 'keep_stacks': 2, 'new_traffic': 42, 'parameters': ['abc', 'def'], 'senza_yaml': senza_yaml, 'disable_rollback': True, "application_version": "420", } lizzy.new_stack('10', 2, 42, yaml_path, None, "420", True, ['abc', 'def']) mock_post.assert_called_once_with('https://lizzy.example/stacks', headers=header, data=json.dumps(data_with_params, sort_keys=True), json=None, verify=False) mock_post.reset_mock() data_with_stack_version = {'image_version': "10", 'keep_stacks': 2, 'new_traffic': 42, 'parameters': ['abc', 'def'], 'senza_yaml': senza_yaml, 'disable_rollback': True, "application_version": "420", "stack_version": "7", } lizzy.new_stack('10', 2, 42, yaml_path, "7", "420", True, ['abc', 'def']) mock_post.assert_called_once_with('https://lizzy.example/stacks', headers=header, data=json.dumps(data_with_stack_version, sort_keys=True), json=None, verify=False)