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
def test_gets_sets(self): """Tests a bunch of gets that operate on values that are None to start with, and take a default.""" entry = GopherEntry('/NONEXISTANT', self.config) # Initialize the rest of them to None. entry.selector = None entry.config = None entry.populated = None entry.num = None entry.gopherpsupport = None for field in fields: getfunc = getattr(entry, 'get' + field) setfunc = getattr(entry, 'set' + field) self.assertEquals(getfunc(), None) self.assertEquals(getfunc('DEFAULT' + field), 'DEFAULT' + field) setfunc('NewValue' + field) self.assertEquals(getfunc(), 'NewValue' + field) self.assertEquals(getfunc('DEFAULT'), 'NewValue' + field)
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
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