def test_valid(self): """Result is successful when stack preview returns success.""" self.patch_treq( mock_treq(code=200, json_content={'stack': {}}, method='post')) d = validate_launch_stack_config(self.log, 'dfw', 'catalog', 'token', self.launch_config) self.successResultOf(d) self.treq.post.assert_called_with('https://service/stacks/preview', json.dumps(self.expected_args), headers=headers('token'), log=self.log)
def test_invalid(self): """ Certain 40x responses should be handled and result in InvalidLaunchConfiguration. """ for code in [400, 404, 409]: json_content = {"explanation": "some explanation %s" % code} self.patch_treq(mock_treq(code=code, json_content=json_content, content=json.dumps(json_content), method='post')) d = validate_launch_stack_config(self.log, 'dfw', 'catalog', 'token', self.launch_config) f = self.failureResultOf(d, InvalidLaunchConfiguration) self.assertEqual(f.value.message, json.dumps(json_content))