Exemple #1
0
 def test_getdumpdirfromlist_notfound(self):
     """Get dumpdir from list but filename not found
     """
     input_data = [ [ Dumpdir("Ytestname"), Dumpdir("Nsome file"),
                      Dumpdir("NSome File"), Dumpdir("Ytestname~") ]
                  ]
     for _data in input_data:
         self.assertRaises(SBException, get_dumpdir_from_list, _data, "test")
Exemple #2
0
 def test_createcontent(self):
     _dumpdirs = [ Dumpdir("Yhere is another new file\0"),
                   Dumpdir("Yhere is another new file~\0"),
                   Dumpdir("Yoo-maxwell.odt\0"),
                   Dumpdir("Yoo-payment-schedule.ods\0")
                 ]
     snpf = SnapshotFile(self.snarf_new, writeFlag = True)
     _res = snpf.createContent(_dumpdirs)
     print "CONTENT: '%s'" % (_res)
Exemple #3
0
    def test_addrecord(self):
        dumpdir1_name = "/home/peer/backups/testdocs/docs/new folder"
        dumpdir1 = ["Y here is another new file",
                    "Y here is another new file~",
                    "Y oo-maxwell.odt",
                    "Y oo-payment-schedule.ods"
                    ]

        _dumpdirs = [ Dumpdir("Yhere is another new file\0"),
                      Dumpdir("Yhere is another new file~"),
                      Dumpdir("Yoo-maxwell.odt"),
                      Dumpdir("Yoo-payment-schedule.ods")
                    ]

        _rec = ['0', '1232387286', '0', '2055', '90478',
                '/home/peer/backups/testdocs/docs/new folder',
                _dumpdirs
               ]

        datet = datetime.datetime(2007, 1, 19, 15, 29, 27)

        snpf = SnapshotFile(self.snarf_new, writeFlag = True)
        snpf.setHeader(datet)
        snpf.addRecord(_rec)

        del snpf
        # now re-read the created SNAR-file
#        print "\n\n\nnow re-read the created SNAR-file"

        dir_file = []
        snpf = SnapshotFile(self.snarf_new)
        for entr in snpf.parseFormat2():
            dir_file.append(entr)
        self.assertTrue(len(dir_file) == 1)

        entry1 = dir_file[0]

#        print "ENTRY after addrecord:\n%s" % entry1

        # evaluate the results
        self.assertEqual(dumpdir1_name, entry1[SnapshotFile.REC_DIRNAME])
        self.assertEqual(len(dumpdir1), len(entry1[SnapshotFile.REC_CONTENT]))

        dmpd_lst = entry1[SnapshotFile.REC_CONTENT]
        self.assertTrue(isinstance(dmpd_lst, list))

        for _idx in range(0, len(dumpdir1)):
            dmpd = dmpd_lst[_idx]
            self.assertTrue(isinstance(dmpd, Dumpdir))
            dmpd_str = "%s %s" % (dmpd.getControl(), dmpd.getFilename())
            self.assertEqual(dmpd_str, dumpdir1[_idx])
Exemple #4
0
    def testWriteSNARfile(self):
        " Test the writng of SNARfile functionalities "
        if os.path.exists("test-datas" + os.sep + "test-files.snar"):
            os.remove("test-datas" + os.sep + "test-files.snar")
        snpf = SnapshotFile("test-datas" + os.sep + "test-files.snar", True)
        import datetime
        snpf.setHeader(datetime.datetime.now())
        self.assertEqual(snpf.getFormatVersion(), 2)
        entry = ['0', '1195399253', '1195399253', '2049', '420738', "/home/wattazoum/Images",
            [Dumpdir('%scamescope' % Dumpdir.DIRECTORY),
             Dumpdir('%sarticle.html' % Dumpdir.INCLUDED)]
            ]
        snpf.addRecord(entry)

        snpf2 = ProcSnapshotFile(snpf)
        self.assertTrue(snpf2.hasFile("/home/wattazoum/Images/article.html"))
        self.assertTrue(snpf2.hasPath("/home/wattazoum/Images"))
Exemple #5
0
    def test_getter(self):
        """Getting control and filename that should partially fail.
        
        @todo: More checks need to be implemented in class!
        """
        line = "testline"
        dmpd = Dumpdir(line)
        self.assertEqual("t", dmpd.getControl())
        self.assertEqual("estline", dmpd.getFilename())

        line = "testline\0"
        dmpd = Dumpdir(line)
        self.assertEqual("t", dmpd.getControl())
        self.assertEqual("estline", dmpd.getFilename())

        line = "Y/home/username/doc/filename"
        dmpd = Dumpdir(line)
        self.assertEqual("Y", dmpd.getControl())
        self.assertEqual("/home/username/doc/filename", dmpd.getFilename())
Exemple #6
0
 def test_constructor(self):
     line = "testline"
     Dumpdir(line)
Exemple #7
0
 def test_get_dumpdir_from_list(self):
     """Test get dumpdir from list with valid parameters
     """
     input_data = [ { "list" : [ Dumpdir("Ytestname"),
                                 Dumpdir("Nsome file"),
                                 Dumpdir("NSome File"),
                                 Dumpdir("Ytestname~") ],
                      "name" : "testname",
                      "result" : 0
                    },
                    { "list" : [ Dumpdir("Ytestname"),
                                 Dumpdir("Nsome file"),
                                 Dumpdir("NSome File"),
                                 Dumpdir("Ytestname~") ],
                      "name" : "some file",
                      "result" : 1
                    },
                    { "list" : [ Dumpdir("Ytestname"),
                                 Dumpdir("Nsome file"),
                                 Dumpdir("NSome File"),
                                 Dumpdir("Ytestname~") ],
                      "name" : "Some File",
                      "result" : 2
                    },
                    { "list" : [ Dumpdir("Ytestname"),
                                 Dumpdir("Nsome file"),
                                 Dumpdir("NSome File"),
                                 Dumpdir("Ytestname~") ],
                      "name" : "testname~",
                      "result" : 3
                    }
                  ]
     for _data in input_data:
         _res = get_dumpdir_from_list(_data["list"], _data["name"])
         self.assertTrue(_res is _data["list"][_data["result"]])