コード例 #1
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')
コード例 #2
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")