Beispiel #1
0
    def test_revert07(self):
        """ Test backup when no archive file is set """
        backup = ChangeSet(self.todolist, None, ['add One'])
        backup.timestamp = '1'
        command1 = AddCommand(["One"], self.todolist, self.out, self.error, None)
        command1.execute()
        backup.save(self.todolist)

        changesets = list(backup.backup_dict.keys())
        changesets.remove('index')

        self.assertEqual(len(changesets), 1)
        self.assertEqual(self.errors, "")
Beispiel #2
0
    def test_revert07(self):
        """ Test backup when no archive file is set """
        backup = ChangeSet(self.todolist, None, ['add One'])
        backup.timestamp = '1'
        command1 = AddCommand(["One"], self.todolist, self.out, self.error,
                              None)
        command1.execute()
        backup.save(self.todolist)

        changesets = list(backup.backup_dict.keys())
        changesets.remove('index')

        self.assertEqual(len(changesets), 1)
        self.assertEqual(self.errors, "")
Beispiel #3
0
    def test_revert06(self):
        """ Test attempt of deletion with non-existing backup key"""
        backup = ChangeSet(self.todolist, self.archive, ['add One'])
        backup.timestamp = '1'
        command1 = AddCommand(["One"], self.todolist, self.out, self.error,
                              None)
        command1.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Two'])
        backup.timestamp = '2'
        command2 = AddCommand(["Two"], self.todolist, self.out, self.error,
                              None)
        command2.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Three'])
        backup.timestamp = '3'
        command3 = AddCommand(["Three"], self.todolist, self.out, self.error,
                              None)
        command3.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['delete Three'])
        backup.timestamp = '4'
        command4 = DeleteCommand(["Three"], self.todolist, self.out,
                                 self.error, None)
        command4.execute()
        backup.save(self.todolist)

        backup = ChangeSet()
        backup.delete('Foo')

        changesets = list(backup.backup_dict.keys())
        changesets.remove('index')
        index_timestamps = [change[0] for change in backup._get_index()]
        result = list(set(index_timestamps) - set(changesets))

        self.assertEqual(len(changesets), 4)
        self.assertEqual(result, [])
        self.assertEqual(self.errors, "")
Beispiel #4
0
    def test_revert06(self):
        """ Test attempt of deletion with non-existing backup key"""
        backup = ChangeSet(self.todolist, self.archive, ['add One'])
        backup.timestamp = '1'
        command1 = AddCommand(["One"], self.todolist, self.out, self.error, None)
        command1.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Two'])
        backup.timestamp = '2'
        command2 = AddCommand(["Two"], self.todolist, self.out, self.error, None)
        command2.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Three'])
        backup.timestamp = '3'
        command3 = AddCommand(["Three"], self.todolist, self.out, self.error, None)
        command3.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['delete Three'])
        backup.timestamp = '4'
        command4 = DeleteCommand(["Three"], self.todolist, self.out, self.error, None)
        command4.execute()
        backup.save(self.todolist)

        backup = ChangeSet()
        backup.delete('Foo')

        changesets = list(backup.backup_dict.keys())
        changesets.remove('index')
        index_timestamps = [change[0] for change in backup._get_index()]
        result = list(set(index_timestamps) - set(changesets))

        self.assertEqual(len(changesets), 4)
        self.assertEqual(result, [])
        self.assertEqual(self.errors, "")
Beispiel #5
0
    def test_revert05(self):
        """ Test for possible backup collisions """
        backup = ChangeSet(self.todolist, self.archive, ['add One'])
        backup.timestamp = '1'
        command1 = AddCommand(["One"], self.todolist, self.out, self.error, None)
        command1.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Two'])
        backup.timestamp = '2'
        command2 = AddCommand(["Two"], self.todolist, self.out, self.error, None)
        command2.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Three'])
        backup.timestamp = '3'
        command3 = AddCommand(["Three"], self.todolist, self.out, self.error, None)
        command3.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['delete Three'])
        backup.timestamp = '4'
        command4 = DeleteCommand(["Three"], self.todolist, self.out, self.error, None)
        command4.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Four'])
        backup.timestamp = '5'
        command4 = AddCommand(["Four"], self.todolist, self.out, self.error, None)
        command4.execute()
        backup.save(self.todolist)

        revert_command = RevertCommand([], self.todolist, self.out, self.error, None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(self.output.endswith("Successfully reverted: add Four\n"))
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz\n{t} One\n{t} Two".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error, None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(self.output.endswith("Successfully reverted: delete Three\n"))
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz\n{t} One\n{t} Two\n{t} Three".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error, None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(self.output.endswith("Successfully reverted: add Three\n"))
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz\n{t} One\n{t} Two".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error, None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(self.output.endswith("Successfully reverted: add Two\n"))
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz\n{t} One".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error, None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(self.output.endswith("Successfully reverted: add One\n"))
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz")
Beispiel #6
0
    def test_revert04(self):
        """ Test trimming of the backup_file """
        backup = ChangeSet(self.todolist, self.archive, ['add One'])
        backup.timestamp = '1'
        command1 = AddCommand(["One"], self.todolist, self.out, self.error, None)
        command1.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Two'])
        backup.timestamp = '2'
        command2 = AddCommand(["Two"], self.todolist, self.out, self.error, None)
        command2.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Three'])
        backup.timestamp = '3'
        command3 = AddCommand(["Three"], self.todolist, self.out, self.error, None)
        command3.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Four'])
        backup.timestamp = '4'
        command4 = AddCommand(["Four"], self.todolist, self.out, self.error, None)
        command4.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Five'])
        backup.timestamp = '5'
        command5 = AddCommand(["Five"], self.todolist, self.out, self.error, None)
        command5.execute()
        backup.save(self.todolist)

        result = len(ChangeSet().backup_dict.keys())
        self.assertEqual(result, 6)

        backup = ChangeSet(self.todolist, self.archive, ['add Six'])
        backup.timestamp = '6'
        command6 = AddCommand(["Six"], self.todolist, self.out, self.error, None)
        command6.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Seven'])
        backup.timestamp = '7'
        command7 = AddCommand(["Seven"], self.todolist, self.out, self.error, None)
        command7.execute()
        backup.save(self.todolist)

        result = len(ChangeSet().backup_dict.keys())
        self.assertEqual(result, 6)

        revert_command = RevertCommand([], self.todolist, self.out, self.error, None)
        revert_command.execute()

        backup = ChangeSet()
        changesets = list(backup.backup_dict.keys())
        changesets.remove('index')
        index_timestamps = [change[0] for change in backup._get_index()]
        result = list(set(index_timestamps) - set(changesets))

        self.assertEqual(len(changesets), 4)
        self.assertEqual(result, [])
        self.assertEqual(self.errors, "")
        self.assertTrue(self.output.endswith("Successfully reverted: add Seven\n"))
Beispiel #7
0
    def test_revert05(self):
        """ Test for possible backup collisions """
        backup = ChangeSet(self.todolist, self.archive, ['add One'])
        backup.timestamp = '1'
        command1 = AddCommand(["One"], self.todolist, self.out, self.error,
                              None)
        command1.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Two'])
        backup.timestamp = '2'
        command2 = AddCommand(["Two"], self.todolist, self.out, self.error,
                              None)
        command2.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Three'])
        backup.timestamp = '3'
        command3 = AddCommand(["Three"], self.todolist, self.out, self.error,
                              None)
        command3.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['delete Three'])
        backup.timestamp = '4'
        command4 = DeleteCommand(["Three"], self.todolist, self.out,
                                 self.error, None)
        command4.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Four'])
        backup.timestamp = '5'
        command4 = AddCommand(["Four"], self.todolist, self.out, self.error,
                              None)
        command4.execute()
        backup.save(self.todolist)

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Successfully reverted: add Four\n"))
        self.assertEqual(
            self.todolist.print_todos(),
            "Foo\nBar\nBaz\n{t} One\n{t} Two".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Successfully reverted: delete Three\n"))
        self.assertEqual(
            self.todolist.print_todos(),
            "Foo\nBar\nBaz\n{t} One\n{t} Two\n{t} Three".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Successfully reverted: add Three\n"))
        self.assertEqual(
            self.todolist.print_todos(),
            "Foo\nBar\nBaz\n{t} One\n{t} Two".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Successfully reverted: add Two\n"))
        self.assertEqual(self.todolist.print_todos(),
                         "Foo\nBar\nBaz\n{t} One".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Successfully reverted: add One\n"))
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz")
Beispiel #8
0
    def test_revert04(self):
        """ Test trimming of the backup_file """
        backup = ChangeSet(self.todolist, self.archive, ['add One'])
        backup.timestamp = '1'
        command1 = AddCommand(["One"], self.todolist, self.out, self.error,
                              None)
        command1.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Two'])
        backup.timestamp = '2'
        command2 = AddCommand(["Two"], self.todolist, self.out, self.error,
                              None)
        command2.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Three'])
        backup.timestamp = '3'
        command3 = AddCommand(["Three"], self.todolist, self.out, self.error,
                              None)
        command3.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Four'])
        backup.timestamp = '4'
        command4 = AddCommand(["Four"], self.todolist, self.out, self.error,
                              None)
        command4.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Five'])
        backup.timestamp = '5'
        command5 = AddCommand(["Five"], self.todolist, self.out, self.error,
                              None)
        command5.execute()
        backup.save(self.todolist)

        result = len(ChangeSet().backup_dict.keys())
        self.assertEqual(result, 6)

        backup = ChangeSet(self.todolist, self.archive, ['add Six'])
        backup.timestamp = '6'
        command6 = AddCommand(["Six"], self.todolist, self.out, self.error,
                              None)
        command6.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Seven'])
        backup.timestamp = '7'
        command7 = AddCommand(["Seven"], self.todolist, self.out, self.error,
                              None)
        command7.execute()
        backup.save(self.todolist)

        result = len(ChangeSet().backup_dict.keys())
        self.assertEqual(result, 6)

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()

        backup = ChangeSet()
        changesets = list(backup.backup_dict.keys())
        changesets.remove('index')
        index_timestamps = [change[0] for change in backup._get_index()]
        result = list(set(index_timestamps) - set(changesets))

        self.assertEqual(len(changesets), 4)
        self.assertEqual(result, [])
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Successfully reverted: add Seven\n"))