class Actions(unittest.TestCase):
    def setUp(self):
        # start a fake gallery service
        self.gallery = CLTool("gallery.py")
        self.assert_(self.gallery.expect("started"))

    def tearDown(self):
        self.gallery.kill()

    def testInvokeForImage(self):
        (status, output) = getstatusoutput("lca-tool --tracker --triggerdefault an.image")
        self.assert_(status == 0)
        # assert that the gallery was invoked
        self.assert_(self.gallery.expect("showImage ; an.image"))

    def testInvokeForTwoImages(self):
        (status, output) = getstatusoutput("lca-tool --tracker --triggerdefault an.image b.image")
        self.assert_(status == 0)
        # assert that the gallery was invoked
        self.assert_(self.gallery.expect("showImage ; an.image,b.image"))

    def testInvokeForInvalid(self):
        (status, output) = getstatusoutput("lca-tool --tracker --triggerdefault invalid.uri")
        self.assert_(status >> 8 == 4)

    def testInvokeForDifferentClasses(self):
        (status, output) = getstatusoutput("lca-tool --tracker --triggerdefault an.image a.contact")
        self.assert_(status >> 8 == 4)
    def testInvokeMimeOpen(self):
        program = CLTool("uberprogram.py")
        self.assert_(program.expect("started"))

        filename = "file://" + testfiles_dir + "/plaintext"
        (status, output) = getstatusoutput("lca-tool --file --trigger ubermimeopen " + filename)
        self.assert_(status == 0)

        self.assert_(program.expect("mime_open:"))
        program.kill()
class FixedParams(unittest.TestCase):
    def setUp(self):
        # start a fake gallery service
        self.gallery = CLTool("gallery.py")
        self.assert_(self.gallery.expect("started"))

    def tearDown(self):
        self.gallery.kill()

    def testInvokeWithFixedParams(self):
        filename = "file://" + testfiles_dir + "/plaintext"
        (status, output) = getstatusoutput("lca-tool --file --trigger fixedparams " + filename)
        self.assert_(status == 0)
        # assert that the gallery was invoked and the fixed params got prepended
        self.assert_(self.gallery.expect("showImage ; these,are,fixed," + filename))
Example #4
0
class Actions(unittest.TestCase):
    def setUp(self):
        # start a fake gallery service
        self.gallery = CLTool("gallery.py")
        self.assert_(self.gallery.expect("started"))

    def tearDown(self):
        self.gallery.kill()

    def testInvokeForImage(self):
        (status, output) = getstatusoutput("lca-tool --tracker --trigger gallerywithfilename an.image")
        self.assert_(status == 0)
        # assert that the gallery was invoked
        self.assert_(self.gallery.expect("showImage ; file:///tmp.aaa.jpg"))

    def testInvokeForTwoImages(self):
        (status, output) = getstatusoutput("lca-tool --tracker --trigger gallerywithfilename an.image b.image")
        self.assert_(status == 0)
        # assert that the gallery was invoked
        self.assert_(self.gallery.expect("showImage ; file:///tmp/aaa.jpg,file:///tmp/bbb.png"))

    def testInvokeForInvalid(self):
        (status, output) = getstatusoutput("lca-tool --tracker --triggerdefault invalid.uri")
        self.assert_(status >> 8 == 4)

    def testInvokeForDifferentClasses(self):
        (status, output) = getstatusoutput("lca-tool --tracker --triggerdefault an.image a.contact")
        self.assert_(status >> 8 == 4)

    def testInvokeEnclosure(self):
        # We have "<urn:test:encl1> mfo:localLink <an.image>", and
        # triggering it should go indirectly via <an.image>.
        (status, output) = getstatusoutput("lca-tool --tracker --trigger gallerywithfilename urn:test:encl1")
        self.assert_(status == 0)
        self.assert_(self.gallery.expect("showImage ; /tmp/aaa.jpg"))

    def testEnclosureDefaults(self):
        # We have "<urn:test:encl1> mfo:localLink <an.image>", and
        # <urn:test:encl1> and <an.image> should have the same
        # defaults.
        (status, encldef) = getstatusoutput("lca-tool --tracker --printdefault urn:test:encl1")
        self.assert_(status == 0)
        (status, imgdef) = getstatusoutput("lca-tool --file --printdefault /tmp/aaa.jpg")
        self.assert_(status == 0)
        # get the last line of the output
        encldef = encldef.split('\n')[-1]
        imgdef = imgdef.split('\n')[-1]
        self.assert_(encldef != "" and encldef == imgdef)
class ServiceFWSignals(unittest.TestCase):
    def setUp(self):
        # start 2 fake gallery services
        self.gallery = CLTool("gallery.py", "just.a.gallery")
        self.assert_(self.gallery.expect("started"))
        self.gallery2 = CLTool("gallery.py", "just.another.gallery")
        self.assert_(self.gallery2.expect("started"))

        # reset the mapping inside the service mapper
        p = Popen('qdbus com.nokia.MServiceFw / org.maemo.contentaction.testing.changeMapping "just.a.gallery" "com.nokia.galleryserviceinterface"', shell=True)
        sts = os.waitpid(p.pid, 0)[1]
        self.assert_(sts == 0)

    def tearDown(self):
        self.gallery.kill()
        self.gallery2.kill()

    def testImplementorChanges(self):
        invoker = CLTool("servicetest")

        # assert that the old implementor was invoked
        self.assert_(self.gallery.expect("showImage ; an.image"))

        # change the mapping inside our mock service mapper
        p = Popen('qdbus com.nokia.MServiceFw / org.maemo.contentaction.testing.changeMapping "just.another.gallery" "com.nokia.galleryserviceinterface"', shell=True)
        sts = os.waitpid(p.pid, 0)[1]
        self.assert_(sts == 0)

        # then command our mock service mapper to send a signal that the
        # implementor has changed
        p = Popen('qdbus com.nokia.MServiceFw / org.maemo.contentaction.testing.emitServiceAvailable "just.another.gallery" "com.nokia.galleryserviceinterface"', shell=True)
        sts = os.waitpid(p.pid, 0)[1]
        self.assert_(sts == 0)

        # and the new implementor as well
        self.assert_(self.gallery2.expect("showImage ; an.image", timeout=7))

    def testImplementorGone(self):
        invoker = CLTool("servicetest")

        # assert that the old implementor was invoked
        self.assert_(self.gallery.expect("showImage ; an.image"))

        # change the mapping inside our mock service mapper
        p = Popen('qdbus com.nokia.MServiceFw / org.maemo.contentaction.testing.changeMapping "just.another.gallery" "com.nokia.galleryserviceinterface"', shell=True)
        sts = os.waitpid(p.pid, 0)[1]
        self.assert_(sts == 0)

        # then command our mock service mapper to send a signal that the
        # implementor is no longer available
        p = Popen('qdbus com.nokia.MServiceFw / org.maemo.contentaction.testing.emitServiceUnavailable "just.a.gallery"', shell=True)
        sts = os.waitpid(p.pid, 0)[1]
        self.assert_(sts == 0)

        # now, the implementor should be "just.another.gallery", because the
        # mapping was changed and the previous preferred implementor is no
        # longer available

        # and the new implementor as well
        self.assert_(self.gallery2.expect("showImage ; an.image", timeout=7))
class SpecialChars(unittest.TestCase):
    def setUp(self):
        # start a fake gallery service
        self.gallery = CLTool("gallery.py")
        self.assert_(self.gallery.expect("started"))
        (status, output) = getstatusoutput("touch /tmp/some#file.mp3")
        (status, output) = getstatusoutput("ls /tmp/some#file.mp3")

    def tearDown(self):
        self.gallery.kill()
        (status, output) = getstatusoutput("rm /tmp/some#file.mp3")

    def testDBusWithSpecialChars(self):
        (status, output) = getstatusoutput("lca-tool --tracker --trigger gallerywithfilename specialchars.image")
        self.assert_(status == 0)
        # assert that the gallery was invoked
        self.assert_(self.gallery.expect("showImage ; file:///tmp/%5Bspecial%5B.png"))

    def testExecWithSpecialChars(self):
        (status, output) = getstatusoutput("lca-tool --tracker --trigger uriprinter specialchars.image")
        self.assert_(status == 0)
        f = open("./executedAction")
        content = f.read()
        f.close()
        os.remove("./executedAction")
        self.assert_(content.find("'/tmp/[special[.png'") != -1)

    def testActionsForFileWithSpecialChars(self):
        filename = "file:///tmp/some%23file.mp3"
        (status, output) = getstatusoutput("lca-tool --file --print " + filename)
        self.assert_(status == 0)
        self.assert_(output.find("plainmusicplayer") != -1)

    def testActionsForFileWithSpecialChars2(self):
        filename = "/tmp/some#file.mp3"
        (status, output) = getstatusoutput("lca-tool --file --print " + filename)
        self.assert_(status == 0)
        self.assert_(output.find("plainmusicplayer") != -1)