Example #1
0
    def setUp(self):
        cfg = ConfigParser.SafeConfigParser()
        cfg.read((os.path.join(TEST_DIR, "tests.cfg")))
        cfg.set("FileMan", "testdir", TEST_DIR)
        self.fm = FileMan(cfg)

        self.workdir = os.path.abspath(
            os.path.join(TEST_DIR, "workdir", "data"))
Example #2
0
    def setUp(self):
        cfg = ConfigParser.SafeConfigParser()
        cfg.read((os.path.join(TEST_DIR,"tests.cfg")))
        cfg.set("FileMan","testdir",TEST_DIR)
        self.fm = FileMan(cfg)

        self.workdir = os.path.abspath(os.path.join(TEST_DIR,"workdir","data"))
Example #3
0
class FileManTestCase(unittest.TestCase):
    """Test of the file manager"""

    fm = None
    workdir = None

    def setUp(self):
        cfg = ConfigParser.SafeConfigParser()
        cfg.read((os.path.join(TEST_DIR, "tests.cfg")))
        cfg.set("FileMan", "testdir", TEST_DIR)
        self.fm = FileMan(cfg)

        self.workdir = os.path.abspath(
            os.path.join(TEST_DIR, "workdir", "data"))

    def test_getDir(self):
        """Test dir"""

        self.assertTrue(
            os.path.samefile(self.workdir,
                             self.fm.config.get("FileMan", "targetdir")),
            "Make sure, that configuration works and that the data dir was found"
        )

    def test_getFiles(self):
        """Test get files function"""

        # example of expected json response:
        # [
        #   {
        #       name: "file.shp",
        #       size: 1000000,
        #       date: "2012-04-05 05:43",
        #       mimetype: "application/x-esri-shp" || "application/octet-stream"
        #   },
        #   ...
        # ]

        # NOTE: mimetypes should be handled according to https://portal.opengeospatial.org/files/?artifact_id=47860

        (code, files_json) = self.fm.getFiles(self.workdir)
        import json
        files = json.loads(files_json)

        self.assertEquals(type(files), type([]), "List is not an array")
        self.assertEquals(
            len(files),
            len([
                a for a in os.listdir(self.workdir)
                if os.path.splitext(a)[1] not in [".shx", ".dbf", ".prj"]
            ]), "Number of files does not match")
        #self.assertEquals(len(files), 2, "Number of files does not match")
        self.assertListEqual(files[0].keys(),
                             ["date", "mimetype", "name", "size"],
                             "File attributes are not as expected")

    def test_postFile(self):
        """ Test post file function """

        file_path = self.workdir + "punk.sk"

        #make sure the testing file does not exist
        import os
        if os.path.exists(file_path):
            os.remove(file_path)
        """ Test the creation when the file does not exist """
        self.assertEquals(os.path.exists(file_path), False,
                          "The file already exists")
        self.fm.postFile(file_path, "Slobodna Europa")
        self.assertEquals(os.path.exists(file_path), True,
                          "The file was not created")
        f = open(file_path, "rb")
        self.assertEquals(f.read(), "Slobodna Europa",
                          "The file has different content")
        f.close
        """ Test that postFile() does not overwrite the file """
        self.assertEquals(os.path.exists(file_path), True,
                          "The file is not there for the second test")
        self.fm.postFile(file_path, "Zona A")
        f = open(file_path, "rb")
        self.assertEquals(f.read(), "Slobodna Europa",
                          "The file was overwritten by postFile()")

        # clean up
        os.remove(file_path)

    def test_putFile(self):
        """ Test put file function """

        file_path = self.workdir + "punk.sk"

        #make sure the testing file does not exist
        import os
        if os.path.exists(file_path):
            os.remove(file_path)
        """ Test the creation when the file does not exist """
        self.assertEquals(os.path.exists(file_path), False,
                          "The file already exists")
        self.fm.putFile(file_path, "Slobodna Europa")
        self.assertEquals(os.path.exists(file_path), True,
                          "The file was not created")
        f = open(file_path, "rb")
        self.assertEquals(f.read(), "Slobodna Europa",
                          "The file has different content")
        f.close
        """ Test that putFile() does overwrite the file """
        self.assertEquals(os.path.exists(file_path), True,
                          "The file is not there for the second test")
        self.fm.putFile(file_path, "Zona A")
        f = open(file_path, "rb")
        self.assertEquals(f.read(), "Zona A",
                          "The file was not overwritten by putFile()")

        # clean up
        os.remove(file_path)

    def test_deleteFile(self):
        """ Test delete file function """

        file_path = self.workdir + "punk.sk"
        open(file_path, "a").close()

        self.assertEquals(os.path.exists(file_path), True,
                          "The testing file does not exist")
        self.fm.deleteFile(file_path)
        self.assertEquals(os.path.exists(file_path), False,
                          "The file was not deleted")
Example #4
0
class FileManTestCase(unittest.TestCase):
    """Test of the file manager"""

    fm = None
    workdir = None

    def setUp(self):
        cfg = ConfigParser.SafeConfigParser()
        cfg.read((os.path.join(TEST_DIR,"tests.cfg")))
        cfg.set("FileMan","testdir",TEST_DIR)
        self.fm = FileMan(cfg)

        self.workdir = os.path.abspath(os.path.join(TEST_DIR,"workdir","data"))

    def test_getDir(self):
        """Test dir"""

        self.assertTrue(os.path.samefile(self.workdir, self.fm.config.get("FileMan","targetdir")),
            "Make sure, that configuration works and that the data dir was found")

    def test_getFiles(self):
        """Test get files function"""

        # example of expected json response:
        # [
        #   {
        #       name: "file.shp",
        #       size: 1000000,
        #       date: "2012-04-05 05:43",
        #       mimetype: "application/x-esri-shp" || "application/octet-stream"
        #   },
        #   ...
        # ]
        
        # NOTE: mimetypes should be handled according to https://portal.opengeospatial.org/files/?artifact_id=47860

        (code, files_json) = self.fm.getFiles(self.workdir)
        import json
        files = json.loads(files_json)

        self.assertEquals(type(files), type([]), "List is not an array")
        self.assertEquals(
            len(files),
            len([a for a in os.listdir(self.workdir) if os.path.splitext(a)[1] not in [".shx",".dbf",".prj"]]),
            "Number of files does not match")
        #self.assertEquals(len(files), 2, "Number of files does not match")
        self.assertListEqual(files[0].keys(),["date","mimetype", "name", "size"],"File attributes are not as expected")

    def test_postFile(self):
        """ Test post file function """

        file_path = self.workdir + "punk.sk"

        #make sure the testing file does not exist
        import os
        if os.path.exists(file_path):
            os.remove(file_path)

        """ Test the creation when the file does not exist """
        self.assertEquals(os.path.exists(file_path), False, "The file already exists")
        self.fm.postFile(file_path,"Slobodna Europa")
        self.assertEquals(os.path.exists(file_path), True, "The file was not created")
        f = open(file_path, "rb")
        self.assertEquals(f.read(), "Slobodna Europa", "The file has different content")
        f.close

        """ Test that postFile() does not overwrite the file """
        self.assertEquals(os.path.exists(file_path), True, "The file is not there for the second test")
        self.fm.postFile(file_path,"Zona A")
        f = open(file_path, "rb")
        self.assertEquals(f.read(), "Slobodna Europa", "The file was overwritten by postFile()")

        # clean up
        os.remove(file_path)

    def test_putFile(self):
        """ Test put file function """

        file_path = self.workdir + "punk.sk"

        #make sure the testing file does not exist
        import os
        if os.path.exists(file_path):
            os.remove(file_path)
        
        """ Test the creation when the file does not exist """
        self.assertEquals(os.path.exists(file_path), False, "The file already exists")
        self.fm.putFile(file_path, "Slobodna Europa")
        self.assertEquals(os.path.exists(file_path), True, "The file was not created")
        f = open(file_path, "rb")
        self.assertEquals(f.read(), "Slobodna Europa", "The file has different content")
        f.close

        """ Test that putFile() does overwrite the file """
        self.assertEquals(os.path.exists(file_path), True, "The file is not there for the second test")
        self.fm.putFile(file_path, "Zona A")
        f = open(file_path, "rb")
        self.assertEquals(f.read(), "Zona A", "The file was not overwritten by putFile()")

        # clean up
        os.remove(file_path)

    def test_deleteFile(self):
        """ Test delete file function """

        file_path = self.workdir + "punk.sk"
        open(file_path, "a").close()

        self.assertEquals(os.path.exists(file_path), True, "The testing file does not exist")
        self.fm.deleteFile(file_path)
        self.assertEquals(os.path.exists(file_path), False, "The file was not deleted")