Esempio n. 1
0
    def test_with_custom_driver(self):
        # Prepare
        time = now()
        command_output = self.faker.sentence()
        store_path = '/tmp/rireki_testing/store'
        project = self._create_project(
            driver='custom',
            driver_config={'command': 'echo "%s"' % command_output},
            store='local',
            store_config={'path': store_path},
        )

        set_testing_now(time)

        # Execute
        result = Cli.run('backup')

        # Assert
        assert result.exit_code == 0
        assert ('Backing up %s...' % project.name) in result.output
        assert 'Done' in result.output

        backup_path = os.path.join(
            store_path,
            '{}-backup-{}-{}'.format(project.slug, format_time(time, 'date'),
                                     time),
            'logs.json',
        )
        assert os.path.exists(backup_path)

        logs = json.loads(file_get_contents(backup_path))
        assert command_output in logs.get('stdout')
Esempio n. 2
0
    def test_without_installed_projects(self):
        # Execute
        result = Cli.run('backup')

        # Assert
        assert result.exit_code == 0
        assert 'No projects installed!' in result.output
Esempio n. 3
0
    def test_new_project_with_custom_driver(self):
        # Prepare
        project_name = self.faker.name()
        driver_name = 'custom'
        driver_frequency_name = 'custom'
        driver_frequency_minutes = 42
        driver_command = self.faker.word()

        # Execute
        result = Cli.run(
            'add',
            project_name,
            '--driver=' + driver_name,
            '--store=local',
            input=(driver_frequency_name, str(driver_frequency_minutes),
                   driver_command, '/tmp'),
        )

        # Assert
        assert result.exit_code == 0

        config = toml.load('%s/projects/%s.conf' %
                           (self.home_path, project_name))

        assert 'driver' in config
        assert config['driver']['name'] == driver_name
        assert config['driver']['frequency'] == driver_frequency_minutes
        assert config['driver']['command'] == driver_command
Esempio n. 4
0
    def test_new_project_with_files_driver(self):
        # Prepare
        project_name = self.faker.name()
        driver_name = 'files'
        driver_frequency_name = 'daily'
        driver_frequency_minutes = 1440
        driver_paths = [
            '/tmp',
            os.path.join('tmp', str_slug(self.faker.word())),
        ]

        # Execute
        result = Cli.run(
            'add',
            project_name,
            '--driver=' + driver_name,
            '--store=local',
            input=self.__get_new_project_with_files_driver_input(
                driver_frequency_name,
                driver_paths,
            ),
        )

        # Assert
        assert result.exit_code == 0

        config = toml.load('%s/projects/%s.conf' %
                           (self.home_path, project_name))

        assert 'driver' in config
        assert config['driver']['name'] == driver_name
        assert config['driver']['frequency'] == driver_frequency_minutes
        assert config['driver']['paths'] == driver_paths
Esempio n. 5
0
    def test_new_project(self):
        # Prepare
        project_name = self.faker.name()

        # Execute
        result = Cli.run(
            'add',
            project_name,
            '--driver=custom',
            '--store=local',
            input=('daily', '-', '/tmp'),
        )

        # Assert
        assert result.exit_code == 0
        assert ('Project "%s" has been installed!' %
                project_name) in result.output

        assert os.path.exists('%s/projects/%s.conf' %
                              (self.home_path, project_name))

        config = toml.load('%s/projects/%s.conf' %
                           (self.home_path, project_name))

        assert 'name' in config
        assert config['name'] == project_name
Esempio n. 6
0
    def test_without_installed_projects(self):
        # Execute
        result = Cli.run('status')

        # Assert
        assert result.exit_code == 0
        assert 'No projects installed!' in result.output

        assert not os.path.exists(self.home_path)
Esempio n. 7
0
    def test_existing_project(self):
        # Prepare
        project = self._create_project()

        # Execute
        result = Cli.run('add', project.name)

        # Assert
        assert result.exit_code == 0
        assert ('Project with name "%s" already installed!' %
                project.name) in result.output
Esempio n. 8
0
    def test_with_one_project_with_backups_pending(self):
        # Prepare
        project = self._create_project(driver='files', store='local')

        # Execute
        result = Cli.run('status')

        # Assert
        assert result.exit_code == 0

        output_lines = result.output.splitlines()
        assert len(output_lines) == 2
        assert project.name in output_lines[1]
        assert 'files' in output_lines[1]
        assert 'local' in output_lines[1]
        assert 'backup-pending' in output_lines[1]
Esempio n. 9
0
    def test_without_pending_backups(self):
        # Prepare
        project = self._create_project(
            store='local',
            store_config={'path': '/tmp/rireki_testing/store'},
        )

        touch('/tmp/rireki_testing/store/%s/backup' % now())

        # Execute
        result = Cli.run('backup')

        # Assert
        assert result.exit_code == 0
        assert ('Project "%s" does not have any pending backups' %
                project.name) in result.output
        assert 'Done' in result.output
Esempio n. 10
0
    def test_with_one_project_backed_up(self):
        # Prepare
        project = self._create_project(
            store='local',
            store_config={'path': '/tmp/rireki_testing/store'},
        )

        touch('/tmp/rireki_testing/store/%s/backup' % now())

        # Execute
        result = Cli.run('status')

        # Assert
        assert result.exit_code == 0

        output_lines = result.output.splitlines()
        assert len(output_lines) == 2
        assert project.name in output_lines[1]
        assert re.search('Backed up \\d seconds ago', output_lines[1])
Esempio n. 11
0
    def test_new_project_with_local_store(self):
        # Prepare
        project_name = self.faker.name()
        store_name = 'local'
        store_path = '/tmp'

        # Execute
        result = Cli.run(
            'add',
            project_name,
            '--driver=custom',
            '--store=' + store_name,
            input=('daily', '-', store_path),
        )

        # Assert
        assert result.exit_code == 0

        config = toml.load('%s/projects/%s.conf' %
                           (self.home_path, project_name))

        assert 'store' in config
        assert config['store']['name'] == store_name
        assert config['store']['path'] == store_path
Esempio n. 12
0
 def setUp(self):
     Cli.reset()
     Cli.set_environment_variable('RIREKI_HOME', self.home_path)