def testCreateDirectory(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     testRoot.resolve('a2').resolve('NewDir').createDirectory()
     self.assertEqual(testRoot.resolve('a2').listElements(), ["NewDir"])
     mc.stop()
 def testRead(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     self.assertEqual(testRoot.resolve('/_A1').read(1, 10), b"234567890a")
     self.assertEqual(testRoot.resolve('/////_A1').read(30, 6), b"uvwxyz")
     self.assertEqual(testRoot.resolve('_A2').readAll(), b'0123456789')
     mc.stop()
 def testCreateFile(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     testRoot.resolve('NewFile').createFile()
     testRoot.resolve('a2/NewFile').createFile()
     self.assertEqual(
         testRoot.listElements(),
         ["NewFile", "_A1", "_A2", "a1", "a2", "a3", "a4", "a5"])
     self.assertEqual(testRoot.resolve('a2').listElements(), ["NewFile"])
     mc.stop()
 def testElementDelete(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     self.assertEqual(testRoot.listElements(),
                      ["_A1", "_A2", "a1", "a2", "a3", "a4", "a5"])
     testRoot.resolve('a1').delete()
     self.assertEqual(testRoot.listElements(),
                      ["_A1", "_A2", "a2", "a3", "a4", "a5"])
     testRoot.resolve('_A2').delete()
     self.assertEqual(testRoot.listElements(),
                      ["_A1", "a2", "a3", "a4", "a5"])
     mc.stop()
 def testWrite(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     A1 = testRoot.resolve('_A1')
     A1.write(b"ABCDE", 10)
     self.assertEqual(
         A1.metaData(), {
             "Name": "_A1",
             "Path": "{}_A1".format(StorageServiceTest.testSpacePath),
             "Type": "Content",
             "Size": 36
         })
     self.assertEqual(A1.readAsString(0, 16), "1234567890ABCDEf")
     self.assertEqual(A1.readAllAsString(),
                      "1234567890ABCDEfghijklmnopqrstuvwxyz")
     A1.write(b"defghi", 39)
     self.assertEqual(
         A1.metaData(), {
             "Name": "_A1",
             "Path": "{}_A1".format(StorageServiceTest.testSpacePath),
             "Type": "Content",
             "Size": 45
         })
     self.assertEqual(A1.readAsString(35, 10), "z\0\0\0defghi")
     self.assertEqual(A1.readAsString(0, 16), "1234567890ABCDEf")
     mc.stop()
 def testElementMetaData(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     self.assertEqual(
         testRoot.resolve("a1").metaData(), {
             "Name": "a1",
             "Path": "{}a1".format(StorageServiceTest.testSpacePath),
             "Type": "Collection"
         })
     mc.stop()