示例#1
0
    def test_saveSubsOnDisk(self):
        self.testRegisterStuff()
        subContent = u"Test Content\nFor a pseudo subtitle file\n\nYo!\n"
        self.underTest._saveSubOnDisk(testChannelId, testInfohash, "eng", subContent)
        expectedFilename = getSubtitleFileRelativeName(testChannelId, testInfohash, "eng")
        expectedPath = os.path.join(self.underTest.subs_dir, expectedFilename)
        self.assertTrue(os.path.isfile(expectedPath))

        # check the contents
        with codecs.open(expectedPath, "rb", "utf-8") as file:
            cont = file.read()

        self.assertEquals(subContent, cont)

        ##now the file exists. If a new subtitle is saved for the same
        # channel, infohash, lang but with a different content
        # the old one should be overwritten
        newContent = u"I'm the new content! I shall win over the old one!"
        self.underTest._saveSubOnDisk(testChannelId, testInfohash, "eng", newContent)
        self.assertTrue(os.path.isfile(expectedPath))
        # check the contents
        with codecs.open(expectedPath, "rb", "utf-8") as file:
            cont = file.read()

        self.assertEquals(newContent, cont)
示例#2
0
    def testGetSubtitlesFileRelativeName(self):
        # subtitles filenames are build from the sha1 hash
        # of the triple (channel_id, infohash, langCode)
        name = getSubtitleFileRelativeName(testChannelId, testInfohash, "rus")
        hasher = sha()
        for value in (testChannelId, testInfohash, "rus"):
            hasher.update(value)

        self.assertEquals(hasher.hexdigest() + ".srt", name)
示例#3
0
    def testReceivedSUBSMessage(self):
        self.testRegisterStuff()
        languages = ["eng", "rus"]
        zho = u"Subtitle Content 1"
        kor = u"Subtitle Content 2"
        contentsDict = {"eng": zho, "rus": kor}

        msg = (testChannelId, testInfohash, contentsDict)

        simpleCallback = lambda x: x

        bitmask = LanguagesProvider.getLanguagesInstance().langCodesToMask(["eng", "rus"])
        self.underTest.receivedSubsResponse(testDestPermId, msg, [(simpleCallback, bitmask)], OLPROTO_VER_FOURTEENTH)

        # self.assertEquals(languages,callbackParams)
        expectedFilename1 = getSubtitleFileRelativeName(testChannelId, testInfohash, "eng")
        expectedFilename2 = getSubtitleFileRelativeName(testChannelId, testInfohash, "rus")
        expectedPath1 = os.path.join(self._session.get_state_dir(), self.underTest.subs_dir, expectedFilename1)
        expectedPath2 = os.path.join(self._session.get_state_dir(), self.underTest.subs_dir, expectedFilename2)
        self.assertTrue(os.path.isfile(expectedPath1))
        self.assertTrue(os.path.isfile(expectedPath2))

        with codecs.open(expectedPath1, "rb", "utf-8") as file1:
            content1 = file1.read()

        self.assertEquals(zho, content1)

        with codecs.open(expectedPath2, "rb", "utf-8") as file2:
            content2 = file2.read()

        self.assertEquals(kor, content2)

        self.assertEquals(1, self.ol_bridge.add_task_count)
        params = self.ol_bridge.add_taskParametersHistory[0]
        # calling the lambda
        val = params[0]()
        self.assertEquals(languages, val)