Ejemplo n.º 1
0
    def test_parse_config_data(self):
        """Test parse_config_data function."""

        aerostat_server.CONFIG_REPO_PATH = fake_global = '/path/to/repo/'
        fake_config = 'test/config.conf'
        fake_file_contents = 'config data!'
        fake_meta_data = {
                'path': '/path/to/config.conf',
                'owner': 'somebody',
                'group': 'somepeople',
                'mode': '0664'}
        self.mox.StubOutWithMock(aerostat_server, 'get_config_meta_data')
        aerostat_server.get_config_meta_data(fake_config).AndReturn(fake_meta_data)
        fake_file = StringIO.StringIO(fake_file_contents)

        self.mox.StubOutWithMock(sys.modules['__builtin__'], 'open')
        sys.modules['__builtin__'].open(fake_global + fake_config).AndReturn(
                fake_file)

        expected_output = (
                'test', 'config.conf', fake_file_contents, fake_meta_data)

        self.mox.ReplayAll()

        self.assertEqual(aerostat_server.parse_config_data(fake_config),
               expected_output)
Ejemplo n.º 2
0
    def test_do_config_update(self):
        """Test do_config_update function."""

        aerostat_server.CONFIG_REPO_PATH = fake_global = '/path/to/repo/'
        fake_db = self.mox.CreateMockAnything()
        fake_repo_path = 'test/config.conf'
        fake_repo_url = 'ssh://server/repo'
        fake_repo = self.mox.CreateMockAnything()
        fake_repo_files = 'test/config.conf'
        fake_git = self.mox.CreateMockAnything()
        fake_repo.git = fake_git
        fake_git.ls_files().AndReturn(fake_repo_files)
        fake_meta_data = {
                'path': '/path/to/config.conf',
                'owner': 'somebody',
                'group': 'somepeople',
                'mode': '0664'}
        fake_col_name = 'test'
        fake_file_name = 'config.conf'

        self.mox.StubOutWithMock(aerostat_server, 'update_or_clone_repo')
        aerostat_server.update_or_clone_repo(
                fake_global, fake_repo_url).AndReturn(fake_repo)

        self.mox.StubOutWithMock(aerostat_server, 'parse_config_data')
        aerostat_server.parse_config_data('test/config.conf').AndReturn((
                fake_col_name, fake_file_name, '', fake_meta_data))

        self.mox.StubOutWithMock(aerostat_server, 'save_mongo_configs')
        aerostat_server.save_mongo_configs(fake_db, fake_col_name,
                fake_file_name, '', fake_meta_data).AndReturn(12)

        self.mox.ReplayAll()

        self.assertTrue(aerostat_server.do_config_update(
            fake_db, fake_global, fake_repo_url))