Ejemplo n.º 1
0
    def test_cluster_configuration_cache_initialization(self):
        configuration_json = '{ "c1" : { "foo-site" : { "foo" : "bar", "foobar" : "baz" } } }'
        open_mock = mock_open(read_data=configuration_json)

        with patch("__builtin__.open", open_mock):
            cluster_configuration = ClusterConfiguration("/foo/bar/baz")

        open_mock.assert_called_with("/foo/bar/baz/configurations.json", 'r')

        self.assertEqual(
            'bar',
            cluster_configuration.get_configuration_value(
                'c1', 'foo-site/foo'))
        self.assertEqual(
            'baz',
            cluster_configuration.get_configuration_value(
                'c1', 'foo-site/foobar'))
        self.assertEqual(
            None,
            cluster_configuration.get_configuration_value('c1', 'INVALID'))
        self.assertEqual(
            None,
            cluster_configuration.get_configuration_value(
                'c1', 'INVALID/INVALID'))
        self.assertEqual(
            None,
            cluster_configuration.get_configuration_value(
                'INVALID', 'foo-site/foo'))
        self.assertEqual(
            None,
            cluster_configuration.get_configuration_value(
                'INVALID', 'foo-site/foobar'))
Ejemplo n.º 2
0
 def __get_cluster_configuration(self):
     """
 Gets an instance of the cluster cache where the file read and write
 operations have been mocked out
 :return:
 """
     with patch("__builtin__.open") as open_mock:
         open_mock.side_effect = self.open_side_effect
         cluster_configuration = ClusterConfiguration("/foo/bar/baz")
         return cluster_configuration
  def test_cluster_configuration_cache_initialization(self):
    configuration_json = '{ "c1" : { "foo-site" : { "foo" : "bar", "foobar" : "baz" } } }'
    open_mock = mock_open(read_data=configuration_json)

    with patch("__builtin__.open", open_mock):
      cluster_configuration = ClusterConfiguration(os.path.join(os.sep, "foo", "bar", "baz"))

    open_mock.assert_called_with(os.sep + "foo" + os.sep + "bar" + os.sep + "baz" + os.sep + "configurations.json", 'r')

    self.assertEqual('bar', cluster_configuration.get_configuration_value('c1', 'foo-site/foo') )
    self.assertEqual('baz', cluster_configuration.get_configuration_value('c1', 'foo-site/foobar') )
    self.assertEqual(None, cluster_configuration.get_configuration_value('c1', 'INVALID') )
    self.assertEqual(None, cluster_configuration.get_configuration_value('c1', 'INVALID/INVALID') )
    self.assertEqual(None, cluster_configuration.get_configuration_value('INVALID', 'foo-site/foo') )
    self.assertEqual(None, cluster_configuration.get_configuration_value('INVALID', 'foo-site/foobar') )
    pass