def test_create_with_json_file_uri(self): # The contents of env_v2.json must be equivalent to ENVIRONMENT path = pkg.resource_filename( 'mistralclient', 'tests/unit/resources/env_v2.json' ) # Convert the file path to file URI uri = parse.urljoin('file:', request.pathname2url(path)) data = OrderedDict( utils.load_content( utils.get_contents_if_file(uri) ) ) mock = self.mock_http_post(content=data) file_input = {'file': uri} env = self.environments.create(**file_input) self.assertIsNotNone(env) expected_data = copy.deepcopy(data) expected_data['variables'] = json.dumps(expected_data['variables']) mock.assert_called_once_with(URL_TEMPLATE, json.dumps(expected_data))
def test_create_with_json_file_uri(self): # The contents of env_v2.json must be equivalent to ENVIRONMENT path = pkg.resource_filename( 'mistralclient', 'tests/unit/resources/env_v2.json' ) # Convert the file path to file URI uri = parse.urljoin('file:', request.pathname2url(path)) data = collections.OrderedDict( utils.load_content( utils.get_contents_if_file(uri) ) ) self.requests_mock.post(self.TEST_URL + URL_TEMPLATE, status_code=201, json=data) file_input = {'file': uri} env = self.environments.create(**file_input) self.assertIsNotNone(env) expected_data = copy.deepcopy(data) expected_data['variables'] = json.dumps(expected_data['variables']) self.assertEqual(expected_data, self.requests_mock.last_request.json())
def update(self, definition, namespace='', scope='private', id=None): self._ensure_not_empty(definition=definition) url_pre = ('/workflows/%s' % id) if id else '/workflows' # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) try: resp = self.http_client.put( '%s?namespace=%s&scope=%s' % (url_pre, namespace, scope), definition, headers={'content-type': 'text/plain'} ) except exceptions.HttpError as ex: self._raise_api_exception(ex.response) if resp.status_code != 200: self._raise_api_exception(resp) if id: return self.resource_class(self, base.extract_json(resp, None)) return [self.resource_class(self, resource_data) for resource_data in base.extract_json(resp, 'workflows')]
def update(self, definition, namespace='', scope='private', id=None): self._ensure_not_empty(definition=definition) url_pre = ('/workflows/%s' % id) if id else '/workflows' # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) try: resp = self.http_client.put('%s?namespace=%s&scope=%s' % (url_pre, namespace, scope), definition, headers={'content-type': 'text/plain'}) except exceptions.HttpError as ex: self._raise_api_exception(ex.response) if resp.status_code != 200: self._raise_api_exception(resp) if id: return self.resource_class(self, base.extract_json(resp, None)) return [ self.resource_class(self, resource_data) for resource_data in base.extract_json(resp, 'workflows') ]
def create(self, name, content, namespace='', scope='private'): self._ensure_not_empty(name=name, content=content) # If the specified content is actually a file, read from it. content = utils.get_contents_if_file(content) return self._create('/code_sources?name=%s&scope=%s&namespace=%s' % (name, scope, namespace), content, dump_json=False, headers={'content-type': 'text/plain'})
def update(self, definition, namespace='', scope='private'): self._ensure_not_empty(definition=definition) # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) return self._update(self._get_workbooks_url(None, namespace, scope), definition, dump_json=False, headers={'content-type': 'text/plain'})
def validate(self, definition): self._ensure_not_empty(definition=definition) # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) return self._validate('/actions/validate', definition, dump_json=False, headers={'content-type': 'text/plain'})
def create(self, definition, scope='private'): self._ensure_not_empty(definition=definition) # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) return self._create('/actions?scope=%s' % scope, definition, response_key='actions', dump_json=False, headers={'content-type': 'text/plain'}, is_iter_resp=True)
def update(self, **kwargs): # Check to see if the file name or URI is being passed in. If so, # read it's contents first. if 'file' in kwargs: file = kwargs['file'] kwargs = utils.load_content(utils.get_contents_if_file(file)) name = kwargs.get('name', None) self._ensure_not_empty(name=name) # Convert dict to text for the variables attribute. if kwargs.get('variables') and isinstance(kwargs['variables'], dict): kwargs['variables'] = jsonutils.dumps(kwargs['variables']) return self._update('/environments', kwargs)
def validate(self, definition): self._ensure_not_empty(definition=definition) # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) resp = self.http_client.post('/workflows/validate', definition, headers={'content-type': 'text/plain'}) if resp.status_code != 200: self._raise_api_exception(resp) return base.extract_json(resp, None)
def update(self, definition, scope='private', id=None): self._ensure_not_empty(definition=definition) url_pre = ('/actions/%s' % id) if id else '/actions' # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) return self._update('%s?scope=%s' % (url_pre, scope), definition, response_key='actions', dump_json=False, headers={'content-type': 'text/plain'}, is_iter_resp=True)
def validate(self, definition): self._ensure_not_empty(definition=definition) # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) resp = self.http_client.post( '/workflows/validate', definition, headers={'content-type': 'text/plain'} ) if resp.status_code != 200: self._raise_api_exception(resp) return base.extract_json(resp, None)
def test_update_with_yaml_file(self): # The contents of env_v2.json must be equivalent to ENVIRONMENT path = pkg.resource_filename('mistralclient', 'tests/unit/resources/env_v2.json') data = collections.OrderedDict( utils.load_content(utils.get_contents_if_file(path))) self.requests_mock.put(self.TEST_URL + URL_TEMPLATE, json=data) file_input = {'file': path} env = self.environments.update(**file_input) self.assertIsNotNone(env) expected_data = copy.deepcopy(data) expected_data['variables'] = json.dumps(expected_data['variables']) self.assertEqual(expected_data, self.requests_mock.last_request.json())
def create(self, definition, namespace='', scope='private'): self._ensure_not_empty(definition=definition) # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) resp = self.http_client.post( '/workflows?scope=%s&namespace=%s' % (scope, namespace), definition, headers={'content-type': 'text/plain'} ) if resp.status_code != 201: self._raise_api_exception(resp) return [self.resource_class(self, resource_data) for resource_data in base.extract_json(resp, 'workflows')]
def update(self, definition, scope='private'): self._ensure_not_empty(definition=definition) # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) resp = self.client.http_client.put( '/actions?scope=%s' % scope, definition, headers={'content-type': 'text/plain'} ) if resp.status_code != 200: self._raise_api_exception(resp) return [self.resource_class(self, resource_data) for resource_data in base.extract_json(resp, 'actions')]
def create(self, definition, scope='private'): self._ensure_not_empty(definition=definition) # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) resp = self.http_client.post('/workflows?scope=%s' % scope, definition, headers={'content-type': 'text/plain'}) if resp.status_code != 201: self._raise_api_exception(resp) return [ self.resource_class(self, resource_data) for resource_data in base.extract_json(resp, 'workflows') ]
def update(self, definition, namespace='', scope='private'): self._ensure_not_empty(definition=definition) # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) try: resp = self.http_client.put(self._get_workbooks_url( None, namespace, scope), definition, headers={'content-type': 'text/plain'}) except exceptions.HttpError as ex: self._raise_api_exception(ex.response) if resp.status_code != 200: self._raise_api_exception(resp) return self.resource_class(self, base.extract_json(resp, None))
def update(self, definition, namespace='', scope='private'): self._ensure_not_empty(definition=definition) # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) try: resp = self.http_client.put( self._get_workbooks_url(None, namespace, scope), definition, headers={'content-type': 'text/plain'} ) except exceptions.HttpError as ex: self._raise_api_exception(ex.response) if resp.status_code != 200: self._raise_api_exception(resp) return self.resource_class(self, base.extract_json(resp, None))
def update(self, definition, scope='private', id=None): self._ensure_not_empty(definition=definition) url_pre = ('/actions/%s' % id) if id else '/actions' # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) resp = self.http_client.put('%s?scope=%s' % (url_pre, scope), definition, headers={'content-type': 'text/plain'}) if resp.status_code != 200: self._raise_api_exception(resp) return [ self.resource_class(self, resource_data) for resource_data in base.extract_json(resp, 'actions') ]
def update(self, definition, scope='private', id=None, namespace=''): self._ensure_not_empty(definition=definition) params = '?scope=%s' % scope if namespace: params += '&namespace=%s' % namespace url = ('/actions/%s' % id if id else '/actions') + params # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) return self._update(url, definition, response_key='actions', dump_json=False, headers={'content-type': 'text/plain'}, is_iter_resp=True)
def test_update_with_yaml_file(self): # The contents of env_v2.json must be equivalent to ENVIRONMENT path = pkg.resource_filename( 'mistralclient', 'tests/unit/resources/env_v2.json' ) data = collections.OrderedDict( utils.load_content( utils.get_contents_if_file(path) ) ) self.requests_mock.put(self.TEST_URL + URL_TEMPLATE, json=data) file_input = {'file': path} env = self.environments.update(**file_input) self.assertIsNotNone(env) expected_data = copy.deepcopy(data) expected_data['variables'] = json.dumps(expected_data['variables']) self.assertEqual(expected_data, self.requests_mock.last_request.json())
def test_update_with_yaml_file(self): # The contents of env_v2.json must be equivalent to ENVIRONMENT path = pkg.resource_filename( 'mistralclient', 'tests/unit/resources/env_v2.json' ) data = OrderedDict( utils.load_content( utils.get_contents_if_file(path) ) ) mock = self.mock_http_put(content=data) file_input = {'file': path} env = self.environments.update(**file_input) self.assertIsNotNone(env) expected_data = copy.deepcopy(data) expected_data['variables'] = json.dumps(expected_data['variables']) mock.assert_called_once_with(URL_TEMPLATE, json.dumps(expected_data))
def test_create_with_json_file_uri(self): # The contents of env_v2.json must be equivalent to ENVIRONMENT path = pkg.resource_filename('mistralclient', 'tests/unit/resources/env_v2.json') path = os.path.abspath(path) # Convert the file path to file URI uri = parse.urljoin('file:', request.pathname2url(path)) data = collections.OrderedDict( utils.load_content(utils.get_contents_if_file(uri))) self.requests_mock.post(self.TEST_URL + URL_TEMPLATE, status_code=201, json=data) file_input = {'file': uri} env = self.environments.create(**file_input) self.assertIsNotNone(env) expected_data = copy.deepcopy(data) expected_data['variables'] = json.dumps(expected_data['variables']) self.assertEqual(expected_data, self.requests_mock.last_request.json())
def update(self, definition, namespace='', scope='private', id=None): self._ensure_not_empty(definition=definition) url_pre = ('/workflows/%s' % id) if id else '/workflows' # If the specified definition is actually a file, read in the # definition file definition = utils.get_contents_if_file(definition) is_iter_resp = True response_key = 'workflows' if id: is_iter_resp = False response_key = None return self._update( '%s?namespace=%s&scope=%s' % (url_pre, namespace, scope), definition, response_key=response_key, dump_json=False, headers={'content-type': 'text/plain'}, is_iter_resp=is_iter_resp, )