Exemplo n.º 1
0
 def test_unzip(self):
     self.addFiles()
     for test_dir in self.test_dirs:
         upload_dir = os.path.join(P2B.UPLOAD_DIR, os.path.basename(test_dir)) + os.sep
         for i in range(len(self.zip_files[test_dir])):
             P2B.unzip(upload_dir, upload_dir + self.zip_files[test_dir][i])
             # Check that a new directory was made for the etd
             self.assertTrue(os.path.exists(upload_dir + self.etd_dirs[test_dir][i]))
             # Check that there are files present in the newly created directory
             self.assertTrue(glob.glob(P2B.UPLOAD_DIR + self.etd_dirs[test_dir][i] + "/*") is not None)
Exemplo n.º 2
0
    def test_transform_files(self):
        self.addFiles()

        for test_dir in self.test_dirs:
            # TODO: This logic really shouldn't have to be in the tests.
            bname = os.path.basename(os.path.normpath(test_dir))
            if (not P2B.config.has_option('email', bname)) or (P2B.config.get('email', bname) == ''):
                print "No email confiugred for %s option in [email]" % bname
                print "Skipping this folder until one is configured."
                continue
            P2B.RESULT_EMAIL = P2B.config.get('email', bname)

            upload_dir = os.path.join(P2B.UPLOAD_DIR, os.path.basename(test_dir)) + os.sep

            # Unzip each zip file
            for zipf in self.zip_files[test_dir]:
                P2B.unzip(upload_dir, upload_dir + zipf)

            # Test each zip
            for zipf in self.zip_files[test_dir]:
                # If the correct output for a zip is not present we should skip it
                if not os.path.exists("./TestFiles/" + os.path.splitext(zipf)[0] + "_Output.xml"):
                    print "Missing correct output for %s. Skipping." % zipf
                    continue

                print "Testing %s..." % zipf
                etd_name = os.path.splitext(zipf)[0]
                P2B.transform_files(upload_dir + etd_name + '/')

                output_fname = etd_name + "_Output.xml"
                self.assertTrue(os.path.exists(upload_dir + etd_name + "/" + output_fname))
                with open(upload_dir + etd_name + "/" + output_fname) as output_f:
                    with open("./TestFiles/" + output_fname) as correct_f:
                        print "Testing %s..." % output_fname
                        # The generated link will be different each time so we should replace it with something standard
                        output_text = [re.sub(fulltext_pattern, "<fulltext-url>LINK</fulltext-url>", line) for line in output_f.readlines()]
                        correct_text = [re.sub(fulltext_pattern, "<fulltext-url>LINK</fulltext-url>", line) for line in correct_f.readlines()]
                        # Do a diff of the generated file and the correct output
                        for line in context_diff(correct_text, output_text):
                            sys.stdout.write(line)
                        # Check if the generated output matches the correct output
                        self.assertEqual(output_text, correct_text)

            # Test Dropbox uploads
            print "Testing if everything is in Dropbox..."
            file_pattern = re.compile(r'\[F\]')
            for etd in self.etd_dirs[test_dir]:
                # If the correct output for a zip is not present we should skip it
                if not os.path.exists("./TestFiles/" + etd + "_Output.xml"):
                    continue

                dbu_listing = subprocess.check_output([P2B.DBUPLOADER_PATH, "list", P2B.DB_DIR + bname + "/" + etd +  "/"])
                self.assertEqual(re.search(file_pattern, dbu_listing) != None, True)
Exemplo n.º 3
0
 def test_unzip(self):
     self.addFiles()
     for test_dir in self.test_dirs:
         upload_dir = os.path.join(P2B.UPLOAD_DIR,
                                   os.path.basename(test_dir)) + os.sep
         for i in range(len(self.zip_files[test_dir])):
             P2B.unzip(upload_dir, upload_dir + self.zip_files[test_dir][i])
             # Check that a new directory was made for the etd
             self.assertTrue(
                 os.path.exists(upload_dir + self.etd_dirs[test_dir][i]))
             # Check that there are files present in the newly created directory
             self.assertTrue(
                 glob.glob(P2B.UPLOAD_DIR + self.etd_dirs[test_dir][i] +
                           "/*") is not None)
Exemplo n.º 4
0
    def test_transform_files(self):
        self.addFiles()

        for test_dir in self.test_dirs:
            # TODO: This logic really shouldn't have to be in the tests.
            bname = os.path.basename(os.path.normpath(test_dir))
            if (not P2B.config.has_option('email', bname)) or (P2B.config.get(
                    'email', bname) == ''):
                print "No email confiugred for %s option in [email]" % bname
                print "Skipping this folder until one is configured."
                continue
            P2B.RESULT_EMAIL = P2B.config.get('email', bname)

            upload_dir = os.path.join(P2B.UPLOAD_DIR,
                                      os.path.basename(test_dir)) + os.sep

            # Unzip each zip file
            for zipf in self.zip_files[test_dir]:
                P2B.unzip(upload_dir, upload_dir + zipf)

            # Test each zip
            for zipf in self.zip_files[test_dir]:
                # If the correct output for a zip is not present we should skip it
                if not os.path.exists("./TestFiles/" +
                                      os.path.splitext(zipf)[0] +
                                      "_Output.xml"):
                    print "Missing correct output for %s. Skipping." % zipf
                    continue

                print "Testing %s..." % zipf
                etd_name = os.path.splitext(zipf)[0]
                P2B.transform_files(upload_dir + etd_name + '/')

                output_fname = etd_name + "_Output.xml"
                self.assertTrue(
                    os.path.exists(upload_dir + etd_name + "/" + output_fname))
                with open(upload_dir + etd_name + "/" +
                          output_fname) as output_f:
                    with open("./TestFiles/" + output_fname) as correct_f:
                        print "Testing %s..." % output_fname
                        # The generated link will be different each time so we should replace it with something standard
                        output_text = [
                            re.sub(fulltext_pattern,
                                   "<fulltext-url>LINK</fulltext-url>", line)
                            for line in output_f.readlines()
                        ]
                        correct_text = [
                            re.sub(fulltext_pattern,
                                   "<fulltext-url>LINK</fulltext-url>", line)
                            for line in correct_f.readlines()
                        ]
                        # Do a diff of the generated file and the correct output
                        for line in context_diff(correct_text, output_text):
                            sys.stdout.write(line)
                        # Check if the generated output matches the correct output
                        self.assertEqual(output_text, correct_text)

            # Test Dropbox uploads
            print "Testing if everything is in Dropbox..."
            file_pattern = re.compile(r'\[F\]')
            for etd in self.etd_dirs[test_dir]:
                # If the correct output for a zip is not present we should skip it
                if not os.path.exists("./TestFiles/" + etd + "_Output.xml"):
                    continue

                dbu_listing = subprocess.check_output([
                    P2B.DBUPLOADER_PATH, "list",
                    P2B.DB_DIR + bname + "/" + etd + "/"
                ])
                self.assertEqual(
                    re.search(file_pattern, dbu_listing) != None, True)