Ejemplo n.º 1
0
 def test_no_env_name(self):
     # A ValueError is raised if the env name is not included in the
     # environment context.
     expected = "Unable to retrieve the current environment name."
     with self.mock_environment_file(""):
         with self.assert_error(expected):
             get_env_attr("attr-name")
Ejemplo n.º 2
0
 def test_attribute_not_found(self):
     # A ValueError is raised if the requested attribute is not included in
     # the environment info.
     contents = yaml.safe_dump({"environments": {"ec2": {}}})
     with self.mock_environment_file(contents, juju_env="ec2"):
         with self.assert_error("Attribute attr-name not found"):
             get_env_attr("attr-name")
Ejemplo n.º 3
0
 def test_attribute_not_found(self):
     # A ValueError is raised if the requested attribute is not included in
     # the environment info.
     contents = yaml.safe_dump({'environments': {'ec2': {}}})
     with self.mock_environment_file(contents, juju_env='ec2'):
         with self.assert_error('Attribute attr-name not found'):
             get_env_attr('attr-name')
Ejemplo n.º 4
0
 def test_no_env_name(self):
     # A ValueError is raised if the env name is not included in the
     # environment context.
     expected = 'Unable to retrieve the current environment name.'
     with self.mock_environment_file(''):
         with self.assert_error(expected):
             get_env_attr('attr-name')
Ejemplo n.º 5
0
 def test_no_file(self):
     # A ValueError is raised if the environments file is not found.
     home = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, home)
     expected = "Unable to open environments file: [Errno 2] No such file"
     with mock.patch("os.environ", {"HOME": home, "JUJU_ENV": "ec2"}):
         with self.assert_error(expected):
             get_env_attr("attr-name")
Ejemplo n.º 6
0
 def test_no_file(self):
     # A ValueError is raised if the environments file is not found.
     home = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, home)
     expected = 'Unable to open environments file: [Errno 2] No such file'
     with mock.patch('os.environ', {'HOME': home, 'JUJU_ENV': 'ec2'}):
         with self.assert_error(expected):
             get_env_attr('attr-name')
Ejemplo n.º 7
0
 def test_ok(self):
     # The environment attribute value is correctly returned.
     contents = yaml.safe_dump({
         'environments': {
             'ec2': {
                 'attr-name': 'Value!'
             }
         },
     })
     with self.mock_environment_file(contents, juju_env='ec2'):
         self.assertEqual('Value!', get_env_attr('attr-name'))
Ejemplo n.º 8
0
 def test_ok(self):
     # The environment attribute value is correctly returned.
     contents = yaml.safe_dump({"environments": {"ec2": {"attr-name": "Value!"}}})
     with self.mock_environment_file(contents, juju_env="ec2"):
         self.assertEqual("Value!", get_env_attr("attr-name"))
Ejemplo n.º 9
0
 def test_no_env(self):
     # A ValueError is raised if the environment is not found in the YAML.
     contents = yaml.safe_dump({"environments": {"local": {}}})
     with self.mock_environment_file(contents, juju_env="ec2"):
         with self.assert_error("Environment ec2 not found"):
             get_env_attr("attr-name")
Ejemplo n.º 10
0
 def test_invalid_yaml_contents(self):
     # A ValueError is raised if the environments file is not well formed.
     with self.mock_environment_file("a-string", juju_env="ec2"):
         with self.assert_error("Invalid YAML contents: a-string"):
             get_env_attr("attr-name")
Ejemplo n.º 11
0
 def test_invalid_yaml(self):
     # A ValueError is raised if the environments file is not well formed.
     with self.mock_environment_file(":", juju_env="ec2"):
         with self.assert_error("Unable to parse environments file:"):
             get_env_attr("attr-name")
Ejemplo n.º 12
0
 def test_no_env(self):
     # A ValueError is raised if the environment is not found in the YAML.
     contents = yaml.safe_dump({'environments': {'local': {}}})
     with self.mock_environment_file(contents, juju_env='ec2'):
         with self.assert_error('Environment ec2 not found'):
             get_env_attr('attr-name')
Ejemplo n.º 13
0
 def test_invalid_yaml_contents(self):
     # A ValueError is raised if the environments file is not well formed.
     with self.mock_environment_file('a-string', juju_env='ec2'):
         with self.assert_error('Invalid YAML contents: a-string'):
             get_env_attr('attr-name')
Ejemplo n.º 14
0
 def test_invalid_yaml(self):
     # A ValueError is raised if the environments file is not well formed.
     with self.mock_environment_file(':', juju_env='ec2'):
         with self.assert_error('Unable to parse environments file:'):
             get_env_attr('attr-name')