Commit a1fce5b9 authored by Priscila Manhaes's avatar Priscila Manhaes

refactor for using cloudoootestcase

parent ad8a6afb
...@@ -26,51 +26,42 @@ ...@@ -26,51 +26,42 @@
# #
############################################################################## ##############################################################################
from cloudooo.tests.handlerTestCase import HandlerTestCase, make_suite
from xmlrpclib import ServerProxy
from os.path import join from os.path import join
from base64 import encodestring, decodestring from cloudooo.tests.cloudoooTestCase import TestCase, make_suite
from magic import Magic
DAEMON = True
class TestServer(TestCase):
class TestServer(HandlerTestCase):
"""Test XmlRpc Server. Needs cloudooo server started""" """Test XmlRpc Server. Needs cloudooo server started"""
def afterSetUp(self): def ConversionScenarioList(self):
"""Creates a connection with cloudooo server""" return [
self.proxy = ServerProxy("http://%s:%s/RPC2" % \ (join('data', 'test.pdf'), "pdf", "txt", "text/plain"),
(self.hostname, self.cloudooo_port), allow_none=True) ]
def testConvertPDFtoTxt(self): def testConvertPDFtoTxt(self):
"""Converts pdf to txt""" """Converts pdf to txt"""
data = open(join('data', 'test.pdf'), 'r').read() self.runConversionList(self.ConversionScenarioList())
document = self.proxy.convertFile(encodestring(data),
"pdf", def GetMetadataScenarioList(self):
"txt") return [
mime = Magic(mime=True) (join('data', 'test.pdf'), "pdf", dict(title='Free Cloud Alliance'+
mimetype = mime.from_buffer(decodestring(document)) ' Presentation')),
self.assertEquals(mimetype, "text/plain") ]
def testGetMetadataFromPdf(self): def testGetMetadataFromPdf(self):
"""test if metadata are extracted correctly""" """test if metadata are extracted correctly"""
data = open(join('data', 'test.pdf'), 'r').read() self.runGetMetadataList(self.GetMetadataScenarioList())
metadata = self.proxy.getFileMetadataItemList(encodestring(data), "pdf")
self.assertEquals(metadata["title"], def UpdateMetadataScenarioList(self):
'Free Cloud Alliance Presentation') return [
(join('data', 'test.pdf'), "pdf", dict(producer='Cloudooo'),
dict(title='Free Cloud Alliance Presentation', producer='Cloudooo')
),
]
def testSetMetadata(self): def testSetMetadata(self):
"""Test if metadata is inserted correctly in document""" """Test if metadata is inserted correctly in document"""
data = open(join('data', 'test.pdf'), 'r').read() self.runUpdateMetadataList(self.UpdateMetadataScenarioList())
new_data = self.proxy.updateFileMetadata(encodestring(data),
"pdf",
{"producer": "Cloudooo"})
metadata = self.proxy.getFileMetadataItemList(new_data, "pdf")
self.assertEquals(metadata["title"],
'Free Cloud Alliance Presentation')
self.assertEquals(metadata["producer"], 'Cloudooo')
def test_suite(): def test_suite():
return make_suite(TestServer) return make_suite(TestServer)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment