Exemple #1
0
    def testpopulate_dir(self):
        fspath = self.root + '/'
        entry = GopherEntry('/', self.config)
        entry.populatefromfs('/')

        conditions = {
            'selector': '/',
            'config': self.config,
            'fspath': '/',
            'type': '1',
            'name': '',
            'host': None,
            'port': None,
            'mimetype': 'application/gopher-menu',
            'encodedmimetype': None,
            'encoding': None,
            'populated': 1,
            'language': None,
            'gopherpsupport': 1
        }

        self.assertEntryMatches(conditions, entry, "testpopulate_dir")
        self.assertEqual(
            entry.geteadict(),
            {'ABSTRACT': 'This is the abstract for the testdata directory.'})
Exemple #2
0
    def testpopulate_dir(self):
        entry = GopherEntry("/", self.config)
        entry.populatefromfs("/")

        conditions = {
            "selector": "/",
            "config": self.config,
            "fspath": "/",
            "type": "1",
            "name": "",
            "host": None,
            "port": None,
            "mimetype": "application/gopher-menu",
            "encodedmimetype": None,
            "encoding": None,
            "populated": 1,
            "language": None,
            "gopherpsupport": 1,
        }

        self.assertEntryMatches(conditions, entry, "testpopulate_dir")
        self.assertEqual(
            entry.geteadict(),
            {"ABSTRACT": "This is the abstract for the testdata directory."},
        )
Exemple #3
0
    def testpopulate_encoded(self):
        fspath = '/testfile.txt.gz'
        entry = GopherEntry('/testfile.txt.gz', self.config)
        entry.populatefromfs(fspath)

        self.assertEqual(entry.gettype(), '9')
        self.assertEqual(entry.getmimetype(), 'application/octet-stream')
        self.assertEqual(entry.getencoding(), 'gzip')
        self.assertEqual(entry.getencodedmimetype(), 'text/plain')
        self.assertEqual(entry.geteadict(),
                          {'ABSTRACT': "This is the abstract\nfor testfile.txt.gz"})
Exemple #4
0
    def testpopulate_encoded(self):
        fspath = "/testfile.txt.gz"
        entry = GopherEntry("/testfile.txt.gz", self.config)
        entry.populatefromfs(fspath)

        self.assertEqual(entry.gettype(), "9")
        self.assertEqual(entry.getmimetype(), "application/octet-stream")
        self.assertEqual(entry.getencoding(), "gzip")
        self.assertEqual(entry.getencodedmimetype(), "text/plain")
        self.assertEqual(
            entry.geteadict(),
            {"ABSTRACT": "This is the abstract\nfor testfile.txt.gz"},
        )
Exemple #5
0
    def testpopulate_remote(self):
        """Asserts that population is not done on remote objects."""
        selector = '/testfile.txt'
        fspath = self.root + selector
        entry = GopherEntry(selector, self.config)
        entry.host = 'gopher.nowhere'
        entry.populatefromfs(fspath)
        assert entry.gettype() == None

        entry.populated = 0
        entry.host = None
        entry.port = 70
        entry.populatefromfs(fspath)
        assert entry.gettype() == None

        entry.populated = 0
        entry.host = 'gopher.nowhere'
        entry.populatefromfs(fspath)
        assert entry.gettype() == None
Exemple #6
0
    def testpopulate_basic(self):
        fspath = '/testfile.txt'
        statval = os.stat(self.root + fspath)
        conditions = {
            'selector': '/testfile.txt',
            'config': self.config,
            'fspath': fspath,
            'type': '0',
            'name': 'testfile.txt',
            'host': None,
            'port': None,
            'mimetype': 'text/plain',
            'encodedmimetype': None,
            'encoding': None,
            'populated': 1,
            'language': None,
            'gopherpsupport': 1,
            'ctime': statval[9],
            'mtime': statval[8],
            'size': 5,
            'num': 0
        }

        entry = GopherEntry('/testfile.txt', self.config)
        entry.populatefromfs(fspath)
        self.assertEntryMatches(conditions, entry, 'testpopulate_basic')

        # Also try it with passed statval.

        entry = GopherEntry('/testfile.txt', self.config)
        entry.populatefromfs(fspath, statval)
        self.assertEntryMatches(conditions, entry,
                                'testpopulate_basic with cached stat')

        # Make sure it's a no-op if it's already populated.

        entry = GopherEntry('/NONEXISTANT', self.config)
        entry.populated = 1
        entry.populatefromfs(fspath)

        assert entry.gettype() == None
Exemple #7
0
    def testpopulate_basic(self):
        fspath = "/testfile.txt"
        statval = os.stat(self.root + fspath)
        conditions = {
            "selector": "/testfile.txt",
            "config": self.config,
            "fspath": fspath,
            "type": "0",
            "name": "testfile.txt",
            "host": None,
            "port": None,
            "mimetype": "text/plain",
            "encodedmimetype": None,
            "encoding": None,
            "populated": 1,
            "language": None,
            "gopherpsupport": 1,
            "ctime": statval[9],
            "mtime": statval[8],
            "size": 5,
            "num": 0,
        }

        entry = GopherEntry("/testfile.txt", self.config)
        entry.populatefromfs(fspath)
        self.assertEntryMatches(conditions, entry, "testpopulate_basic")

        # Also try it with passed statval.

        entry = GopherEntry("/testfile.txt", self.config)
        entry.populatefromfs(fspath, statval)
        self.assertEntryMatches(conditions, entry,
                                "testpopulate_basic with cached stat")

        # Make sure it's a no-op if it's already populated.

        entry = GopherEntry("/NONEXISTANT", self.config)
        entry.populated = 1
        entry.populatefromfs(fspath)

        assert entry.gettype() is None
Exemple #8
0
    def testpopulate_untouched(self):
        """Asserts that populatefromfs does not touch data that has already
        been set."""

        selector = '/testfile.txt'
        fspath = selector

        entry = GopherEntry(selector, self.config)
        entry.name = 'FAKE NAME'
        entry.ctime = 1
        entry.mtime = 2
        entry.populatefromfs(fspath)
        self.assertEntryMatches({
            'name': 'FAKE NAME',
            'ctime': 1,
            'mtime': 2
        }, entry, 'testpopulate_untouched')

        # Reset for the next batch.
        entry = GopherEntry('/', self.config)

        # Test type for a dir.
        entry.type = '2'
        entry.mimetype = 'FAKEMIMETYPE'
        entry.populatefromfs(self.root)
        self.assertEquals(entry.gettype(), '2')
        self.assertEquals(entry.getmimetype(), 'FAKEMIMETYPE')

        # Test mime type handling.  First, regular file.

        entry = GopherEntry(selector, self.config)
        entry.mimetype = 'fakemimetype'
        entry.populatefromfs(fspath)
        self.assertEquals(entry.getmimetype(), 'fakemimetype')
        # The guesstype will not find fakemimetype and so it'll set it to 0
        self.assertEquals(entry.gettype(), '0')

        # Now, an encoded file.

        entry = GopherEntry(selector + '.gz', self.config)
        entry.mimetype = 'fakemime'
        entry.populatefromfs(fspath + '.gz')
        self.assertEquals(entry.getmimetype(), 'fakemime')
        self.assertEquals(entry.getencoding(), 'gzip')
        self.assertEquals(entry.getencodedmimetype(), 'text/plain')
        self.assertEquals(entry.gettype(), '0')  # again from fakemime

        # More details.

        selector = '/testarchive.tgz'
        fspath = selector
        entry = GopherEntry(selector, self.config)
        entry.mimetype = 'foo1234'
        entry.encoding = 'bar'
        entry.populatefromfs(fspath)
        self.assertEquals(entry.getmimetype(), 'foo1234')
        self.assertEquals(entry.getencoding(), 'bar')
        self.assertEquals(entry.getencodedmimetype(), 'application/x-tar')
        self.assertEquals(entry.gettype(), '0')

        # And overriding only the encoding.

        entry = GopherEntry(selector, self.config)
        entry.encoding = 'fakeencoding'
        entry.populatefromfs(fspath)
        self.assertEquals(entry.getencoding(), 'fakeencoding')
        self.assertEquals(entry.gettype(), '9')
        self.assertEquals(entry.getmimetype(), 'application/octet-stream')

        # And finally -- overriding the encoded mime type.

        entry = GopherEntry(selector, self.config)
        entry.encodedmimetype = 'fakeencoded'
        entry.populatefromfs(fspath)
        self.assertEquals(entry.getencodedmimetype(), 'fakeencoded')
        self.assertEquals(entry.getmimetype(), 'application/octet-stream')
Exemple #9
0
    def testpopulate_untouched(self):
        """Asserts that populatefromfs does not touch data that has already
        been set."""

        selector = "/testfile.txt"
        fspath = selector

        entry = GopherEntry(selector, self.config)
        entry.name = "FAKE NAME"
        entry.ctime = 1
        entry.mtime = 2
        entry.populatefromfs(fspath)
        self.assertEntryMatches(
            {
                "name": "FAKE NAME",
                "ctime": 1,
                "mtime": 2
            },
            entry,
            "testpopulate_untouched",
        )

        # Reset for the next batch.
        entry = GopherEntry("/", self.config)

        # Test type for a dir.
        entry.type = "2"
        entry.mimetype = "FAKEMIMETYPE"
        entry.populatefromfs(self.root)
        self.assertEqual(entry.gettype(), "2")
        self.assertEqual(entry.getmimetype(), "FAKEMIMETYPE")

        # Test mime type handling.  First, regular file.

        entry = GopherEntry(selector, self.config)
        entry.mimetype = "fakemimetype"
        entry.populatefromfs(fspath)
        self.assertEqual(entry.getmimetype(), "fakemimetype")
        # The guesstype will not find fakemimetype and so it'll set it to 0
        self.assertEqual(entry.gettype(), "0")

        # Now, an encoded file.

        entry = GopherEntry(selector + ".gz", self.config)
        entry.mimetype = "fakemime"
        entry.populatefromfs(fspath + ".gz")
        self.assertEqual(entry.getmimetype(), "fakemime")
        self.assertEqual(entry.getencoding(), "gzip")
        self.assertEqual(entry.getencodedmimetype(), "text/plain")
        self.assertEqual(entry.gettype(), "0")  # again from fakemime

        # More details.

        selector = "/testarchive.tgz"
        fspath = selector
        entry = GopherEntry(selector, self.config)
        entry.mimetype = "foo1234"
        entry.encoding = "bar"
        entry.populatefromfs(fspath)
        self.assertEqual(entry.getmimetype(), "foo1234")
        self.assertEqual(entry.getencoding(), "bar")
        self.assertEqual(entry.getencodedmimetype(), "application/x-tar")
        self.assertEqual(entry.gettype(), "0")

        # And overriding only the encoding.

        entry = GopherEntry(selector, self.config)
        entry.encoding = "fakeencoding"
        entry.populatefromfs(fspath)
        self.assertEqual(entry.getencoding(), "fakeencoding")
        self.assertEqual(entry.gettype(), "9")
        self.assertEqual(entry.getmimetype(), "application/octet-stream")

        # And finally -- overriding the encoded mime type.

        entry = GopherEntry(selector, self.config)
        entry.encodedmimetype = "fakeencoded"
        entry.populatefromfs(fspath)
        self.assertEqual(entry.getencodedmimetype(), "fakeencoded")
        self.assertEqual(entry.getmimetype(), "application/octet-stream")