<s> from collections import OrderedDict <EOL> import copy <EOL> import json <EOL> import pkg_resources as pkg <EOL> from six . moves . urllib import parse <EOL> from six . moves . urllib import request <EOL> from mistralclient . api . v2 import environments <EOL> from mistralclient . tests . unit . v2 import base <EOL> from mistralclient import utils <EOL> ENVIRONMENT = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT:localhost>' <EOL> } <EOL> } <EOL> URL_TEMPLATE = '<STR_LIT>' <EOL> URL_TEMPLATE_NAME = '<STR_LIT>' <EOL> class TestEnvironmentsV2 ( base . BaseClientV2Test ) : <EOL> def test_create ( self ) : <EOL> data = copy . deepcopy ( ENVIRONMENT ) <EOL> mock = self . mock_http_post ( content = data ) <EOL> env = self . environments . create ( ** data ) <EOL> self . assertIsNotNone ( env ) <EOL> expected_data = copy . deepcopy ( data ) <EOL> expected_data [ '<STR_LIT>' ] = json . dumps ( expected_data [ '<STR_LIT>' ] ) <EOL> mock . assert_called_once_with ( URL_TEMPLATE , json . dumps ( expected_data ) ) <EOL> def test_create_with_json_file_uri ( self ) : <EOL> path = pkg . resource_filename ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> uri = parse . urljoin ( '<STR_LIT>' , request . pathname2url ( path ) ) <EOL> data = OrderedDict ( <EOL> utils . load_content ( <EOL> utils . get_contents_if_file ( uri ) <EOL> ) <EOL> ) <EOL> mock = self . mock_http_post ( content = data ) <EOL> file_input = { '<STR_LIT:file>' : uri } <EOL> env = self . environments . create ( ** file_input ) <EOL> self . assertIsNotNone ( env ) <EOL> expected_data = copy . deepcopy ( data ) <EOL> expected_data [ '<STR_LIT>' ] = json . dumps ( expected_data [ '<STR_LIT>' ] ) <EOL> mock . assert_called_once_with ( URL_TEMPLATE , json . dumps ( expected_data ) ) <EOL> def test_update ( self ) : <EOL> data = copy . deepcopy ( ENVIRONMENT ) <EOL> mock = self . mock_http_put ( content = data ) <EOL> env = self . environments . update ( ** data ) <EOL> self . assertIsNotNone ( env ) <EOL> expected_data = copy . deepcopy ( data ) <EOL> expected_data [ '<STR_LIT>' ] = json . dumps ( expected_data [ '<STR_LIT>' ] ) <EOL> mock . assert_called_once_with ( URL_TEMPLATE , json . dumps ( expected_data ) ) <EOL> def test_update_with_yaml_file ( self ) : <EOL> path = pkg . resource_filename ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> data = OrderedDict ( <EOL> utils . load_content ( <EOL> utils . get_contents_if_file ( path ) <EOL> ) <EOL> ) <EOL> mock = self . mock_http_put ( content = data ) <EOL> file_input = { '<STR_LIT:file>' : path } <EOL> env = self . environments . update ( ** file_input ) <EOL> self . assertIsNotNone ( env ) <EOL> expected_data = copy . deepcopy ( data ) <EOL> expected_data [ '<STR_LIT>' ] = json . dumps ( expected_data [ '<STR_LIT>' ] ) <EOL> mock . assert_called_once_with ( URL_TEMPLATE , json . dumps ( expected_data ) ) <EOL> def test_list ( self ) : <EOL> mock = self . mock_http_get ( content = { '<STR_LIT>' : [ ENVIRONMENT ] } ) <EOL> environment_list = self . environments . list ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( environment_list ) ) <EOL> env = environment_list [ <NUM_LIT:0> ] <EOL> self . assertDictEqual ( <EOL> environments . Environment ( self . environments , ENVIRONMENT ) . to_dict ( ) , <EOL> env . to_dict ( ) <EOL> ) <EOL> mock . assert_called_once_with ( URL_TEMPLATE ) <EOL> def test_get ( self ) : <EOL> mock = self . mock_http_get ( content = ENVIRONMENT ) <EOL> env = self . environments . get ( '<STR_LIT>' ) <EOL> self . assertIsNotNone ( env ) <EOL> self . assertDictEqual ( <EOL> environments . Environment ( self . environments , ENVIRONMENT ) . to_dict ( ) , <EOL> env . to_dict ( ) <EOL> ) <EOL> mock . assert_called_once_with ( URL_TEMPLATE_NAME % '<STR_LIT>' ) <EOL> def test_delete ( self ) : <EOL> mock = self . mock_http_delete ( status_code = <NUM_LIT> ) <EOL> self . environments . delete ( '<STR_LIT>' ) <EOL> mock . assert_called_once_with ( URL_TEMPLATE_NAME % '<STR_LIT>' ) </s>
