예제 #1
0
    def _napiFormatConversion(self, fromFormat, toFormat):
        media = None
        with napi.sandbox.Sandbox() as sandbox:
            # generate a media file
            media = self.videoAssets.prepareRandomMedia(sandbox)
            subs = self.subtitlesAssets.prepareRandomMedia(sandbox,
                    fromFormat)

            # program napiprojekt mock
            self.napiMock.programXmlRequest(
                    media,
                    napi.subtitles.CompressedSubtitles.fromFile(
                        media['asset'],
                        subs['path']))

            fs = napi.fs.Filesystem(media)

            # get the subs
            self.napiScan('-f', toFormat, media['path'])

            # check assertions
            req = self.napiMock.getRequest()
            self.assertEquals(req.method, "POST")
            self.assertEquals(req.url, '/api/api-napiprojekt3.php')
            self.assertTrue(self.output.stdoutContains(
                re.compile(r'napisy pobrano pomyslnie')))

            # confirm the format
            self.assertTrue(fs.subtitlesExists())
            for s in fs.getSubtitlesPaths():
                self.subotageExecute('-gi', '-i', s)
                self.assertTrue(self.output.stdoutContains(
                    re.compile(r'IN_FORMAT -> {}'.format(toFormat))))
예제 #2
0
    def test_ifDownloadsCoverFilesForSingleMedia(self):
        """
        Brief:
        This test verifies if napi is able to obtain the cover file for media

        Procedure:
        1. Prepare a sandbox with a media file
        2. Program napiprojekt mock to return some test cover data
        3. Call napi with -c parameter

        Expected Results:
        Napi should obtain both the subtitles and the cover file for the media
        file.

        """
        media = None
        with napi.sandbox.Sandbox() as sandbox:
            # obtain an media
            media = self.videoAssets.prepareRandomMedia(sandbox)

            # program napiprojekt mock
            self.napiMock.programXmlRequest(
                media,
                napi.subtitles.CompressedSubtitles.fromString(
                    media['asset'], "test subtitles"),
                napi.cover.Cover.fromString(media['asset'], "test cover data"))

            # call napi
            self.napiScan("-c", "--stats",
                          os.path.join(sandbox.path, media['name']))

            fs = napi.fs.Filesystem(media)

            # check assertions
            req = self.napiMock.getRequest()
            self.assertEquals(req.method, "POST")
            self.assertEquals(req.url, '/api/api-napiprojekt3.php')

            # check for subs success
            self.assertTrue(
                self.output.stdoutContains(
                    re.compile(r'napisy pobrano pomyslnie')))

            # check for cover success
            self.assertTrue(
                self.output.stdoutContains(
                    re.compile(r'okladka pobrana pomyslnie')))

            # check statistics
            stats = self.output.parseNapiStats()
            self.assertEquals(1, stats['ok'])
            self.assertEquals(1, stats['cover_ok'])
            self.assertEquals(1, stats['total'])

            self.assertTrue(fs.subtitlesExists())
            self.assertTrue(fs.coverExists())
            self.assertFalse(fs.xmlExists())
예제 #3
0
    def test_ifDownloadsCoverFilesForSingleMedia(self):
        """
        Brief:
        This test verifies if napi is able to obtain the cover file for media

        Procedure:
        1. Prepare a sandbox with a media file
        2. Program napiprojekt mock to return some test cover data
        3. Call napi with -c parameter

        Expected Results:
        Napi should obtain both the subtitles and the cover file for the media
        file.

        """
        media = None
        with napi.sandbox.Sandbox() as sandbox:
            # obtain an media
            media = self.videoAssets.prepareRandomMedia(sandbox)

            # program napiprojekt mock
            self.napiMock.programXmlRequest(
                    media,
                    napi.subtitles.CompressedSubtitles.fromString(
                        media['asset'], "test subtitles"),
                    napi.cover.Cover.fromString(
                        media['asset'], "test cover data"))

            # call napi
            self.napiScan("-c", "--stats",
                    os.path.join(sandbox.path, media['name']))

            fs = napi.fs.Filesystem(media)

            # check assertions
            req = self.napiMock.getRequest()
            self.assertEquals(req.method, "POST")
            self.assertEquals(req.url, '/api/api-napiprojekt3.php')

            # check for subs success
            self.assertTrue(self.output.stdoutContains(
                re.compile(r'napisy pobrano pomyslnie')))

            # check for cover success
            self.assertTrue(self.output.stdoutContains(
                re.compile(r'okladka pobrana pomyslnie')))

            # check statistics
            stats = self.output.parseNapiStats()
            self.assertEquals(1, stats['ok'])
            self.assertEquals(1, stats['cover_ok'])
            self.assertEquals(1, stats['total'])

            self.assertTrue(fs.subtitlesExists())
            self.assertTrue(fs.coverExists())
            self.assertFalse(fs.xmlExists())
예제 #4
0
    def test_ifFetchesSingleCompressedFile(self):
        """
        Brief:
        Verify if napi works for single media files in legacy mode (other)

        Procedure:
        1. Prepare subtitles media
        2. Prepare video media
        3. Program napi mock to respond with plain compressed subs HTTP
        response for GET request
        4. Call napi.sh in legacy mode with id = other

        Expected Results:
        napi.sh should perform a GET request to napi.sh using legacy API.
        Subtitles file should exist afterwards.
        """
        media = None
        subsMedia = None
        with napi.sandbox.Sandbox() as sandbox:
            # generate a media file
            media = self.videoAssets.prepareRandomMedia(sandbox)
            subsMedia = self.subtitlesAssets.prepareRandomMedia(sandbox)

            # program napiprojekt mock
            self.napiMock.programPlainRequest(
                    napi.subtitles.CompressedSubtitles.fromFile(
                        media['asset'], subsMedia['path']))

            # call napi
            self.napiScan('-i', 'other', media['path'])
            fs = napi.fs.Filesystem(media)

            # check assertions
            req = self.napiMock.getRequest()
            self.assertEquals(req.method, "GET")
            self.assertTrue(re.match(r'/unit_napisy/dl\.php\?', req.url))

            self.assertTrue(self.output.stdoutContains(
                re.compile(r'napisy pobrano pomyslnie')))

            self.assertTrue(fs.subtitlesExists())
예제 #5
0
    def test_ifFailsCorrectlyIfResponseIsTooShort(self):
        """
        Brief: Verify if napi fails responses which are awkwardly short.
        Procedure:
        1. Prepare a media file
        2. Program napi mock to respond with:
        4
        NPc0
        0

        This response most of the time indicates lack of requested subtitles.

        Expected Results:
        No processing errors should be detected. Normal error response handling
        should be done. No files should be produced afterwards.
        """
        media = None
        with napi.sandbox.Sandbox() as sandbox:
            # generate a media file
            media = self.videoAssets.prepareRandomMedia(sandbox)

            # program napiprojekt mock
            self.napiMock.programPlainRequest(
                    napi.subtitles.Subtitles.fromString(
                        media['asset'], '4\nNPc0\n0'))

            # call napi
            self.isStderrExpected = True
            self.napiScan('-i', 'pynapi', media['path'])
            fs = napi.fs.Filesystem(media)

            # check assertions
            req = self.napiMock.getRequest()
            self.assertEquals(req.method, "GET")
            self.assertTrue(re.match(r'/unit_napisy/dl\.php\?', req.url))

            self.assertTrue(self.output.hasErrors())
            self.assertTrue(self.output.stdoutContains(
                re.compile(r'plik uszkodzony. niepoprawna ilosc linii')))
            self.assertFalse(fs.subtitlesExists())
예제 #6
0
    def test_ifObtainsAvailableSubtitlesForSingleFile(self):
        """
        Brief:

        This test checks if napi is able to download subtitles for a single
        media files provided directly in the command line.

        Procedure:
        1. Prepare sandbox and media file
        2. Call napi with path to media file

        Expected Results:
        Subtitles file should exist after calling napi.
        """
        media = None
        with napi.sandbox.Sandbox() as sandbox:
            # generate a media file
            media = self.videoAssets.prepareRandomMedia(sandbox)

            # program napiprojekt mock
            self.napiMock.programXmlRequest(
                media,
                napi.subtitles.CompressedSubtitles.fromString(
                    media['asset'], "test subtitles"))

            fs = napi.fs.Filesystem(media)

            # call napi
            self.napiScan(os.path.join(sandbox.path, media['name']))

            # check assertions
            req = self.napiMock.getRequest()
            self.assertEquals(req.method, "POST")
            self.assertEquals(req.url, '/api/api-napiprojekt3.php')
            self.assertTrue(
                self.output.stdoutContains(
                    re.compile(r'napisy pobrano pomyslnie')))

            self.assertTrue(fs.subtitlesExists())
            self.assertFalse(fs.xmlExists())
예제 #7
0
    def test_ifObtainsAvailableSubtitlesForSingleFile(self):
        """
        Brief:

        This test checks if napi is able to download subtitles for a single
        media files provided directly in the command line.

        Procedure:
        1. Prepare sandbox and media file
        2. Call napi with path to media file

        Expected Results:
        Subtitles file should exist after calling napi.
        """
        media = None
        with napi.sandbox.Sandbox() as sandbox:
            # generate a media file
            media = self.videoAssets.prepareRandomMedia(sandbox)

            # program napiprojekt mock
            self.napiMock.programXmlRequest(
                    media,
                    napi.subtitles.CompressedSubtitles.fromString(
                        media['asset'], "test subtitles"))

            fs = napi.fs.Filesystem(media)

            # call napi
            self.napiScan(os.path.join(sandbox.path, media['name']))

            # check assertions
            req = self.napiMock.getRequest()
            self.assertEquals(req.method, "POST")
            self.assertEquals(req.url, '/api/api-napiprojekt3.php')
            self.assertTrue(self.output.stdoutContains(
                re.compile(r'napisy pobrano pomyslnie')))

            self.assertTrue(fs.subtitlesExists())
            self.assertFalse(fs.xmlExists())
예제 #8
0
    def test_ifFailsCorrectlyIfSubsUnavailable(self):
        """
        Brief:
        Verify if handles subs acquisition failure without any errors

        Procedure:
        1. Prepare media file
        2. Program napi mock to respond with no data and 404 HTTP Status
        3. Call napi.sh in legacy mode with id = pynapi

        Expected Results:
        No processing errors should be detected. Normal error response handling
        should be done. No files should be produced afterwards.

        """
        media = None
        with napi.sandbox.Sandbox() as sandbox:
            # generate a media file
            media = self.videoAssets.prepareRandomMedia(sandbox)

            # program napiprojekt mock
            self.napiMock.programPlainRequest()

            # call napi
            self.isStderrExpected = True
            self.napiScan('-i', 'pynapi', media['path'])
            fs = napi.fs.Filesystem(media)

            # check assertions
            req = self.napiMock.getRequest()
            self.assertEquals(req.method, "GET")
            self.assertTrue(re.match(r'/unit_napisy/dl\.php\?', req.url))

            self.assertTrue(self.output.hasErrors())
            self.assertTrue(self.output.stderrContains(
                re.compile(r'nie udalo sie pobrac napisow')))
            self.assertFalse(fs.subtitlesExists())
예제 #9
0
    def test_ifSkippingWorksWithFormatConversion(self):
        """
        Brief:
        Download subtitles with a custom extension specified, skip
        option enabled and format conversion request

        Procedure:
        1. Prepare a media and a subs file for napi mock
        2. Perform a request for programmed media
        3. Make a request again for the same media file but with format
        conversion specified additionally and a skip flag

        Expected Results:
        1. Original subtitles should not be downloaded twice
        2. The original subtitles should be converted to requested format
        3. After conversion both files should exist on the file system
        (original one with prefix prepended)
        """
        media = None
        fromFormat = 'microdvd'
        toFormat = 'subrip'
        extension = 'abcdef'

        with napi.sandbox.Sandbox() as sandbox:
            # generate a media file and subs
            media = self.videoAssets.prepareRandomMedia(sandbox)
            subs = self.subtitlesAssets.prepareRandomMedia(sandbox,
                    fromFormat)

            # program napiprojekt mock - it should be called only once
            self.napiMock.programXmlRequest(
                    media,
                    napi.subtitles.CompressedSubtitles.fromFile(
                        media['asset'],
                        subs['path']),
                    None,
                    None,
                    1)

            # get the subs
            self.napiScan('--stats', '-s', '-e', extension, media['path'])

            # check assertions
            req = self.napiMock.getRequest()
            self.assertTrue(req)
            self.assertEquals(req.method, "POST")
            self.assertEquals(req.url, '/api/api-napiprojekt3.php')
            self.assertTrue(self.output.stdoutContains(
                re.compile(r'napisy pobrano pomyslnie')))

            # check statistics and the file itself
            stats = self.output.parseNapiStats()
            fs = napi.fs.Filesystem(media)
            self.assertEquals(1, stats['ok'])
            self.assertEquals(1, stats['total'])
            self.assertEquals(0, stats['unav'])
            self.assertTrue(fs.subtitlesExists(None, extension))

            # Make another request, this time with conversion.
            # Original unconverted file should be reused without having to
            # resort to making a HTTP request
            self.napiScan('--stats', '-s',
                    '-e', extension,
                    '-f', toFormat,
                    media['path'])

            # check the stats again
            stats = self.output.parseNapiStats()
            self.assertEquals(1, stats['skip'])
            self.assertEquals(1, stats['conv'])
            self.assertEquals(0, stats['unav'])

            self.assertTrue(fs.subtitlesExists(None, 'srt'))
            self.assertTrue(fs.subtitlesExists('ORIG'))
예제 #10
0
    def test_ifSkippingWorksWithFormatConversion(self):
        """
        Brief:
        Download subtitles with a custom extension specified, skip
        option enabled and format conversion request

        Procedure:
        1. Prepare a media and a subs file for napi mock
        2. Perform a request for programmed media
        3. Make a request again for the same media file but with format
        conversion specified additionally and a skip flag

        Expected Results:
        1. Original subtitles should not be downloaded twice
        2. The original subtitles should be converted to requested format
        3. After conversion both files should exist on the file system
        (original one with prefix prepended)
        """
        media = None
        fromFormat = 'microdvd'
        toFormat = 'subrip'
        extension = 'abcdef'

        with napi.sandbox.Sandbox() as sandbox:
            # generate a media file and subs
            media = self.videoAssets.prepareRandomMedia(sandbox)
            subs = self.subtitlesAssets.prepareRandomMedia(sandbox, fromFormat)

            # program napiprojekt mock - it should be called only once
            self.napiMock.programXmlRequest(
                media,
                napi.subtitles.CompressedSubtitles.fromFile(
                    media['asset'], subs['path']), None, None, 1)

            # get the subs
            self.napiScan('--stats', '-s', '-e', extension, media['path'])

            # check assertions
            req = self.napiMock.getRequest()
            self.assertTrue(req)
            self.assertEquals(req.method, "POST")
            self.assertEquals(req.url, '/api/api-napiprojekt3.php')
            self.assertTrue(
                self.output.stdoutContains(
                    re.compile(r'napisy pobrano pomyslnie')))

            # check statistics and the file itself
            stats = self.output.parseNapiStats()
            fs = napi.fs.Filesystem(media)
            self.assertEquals(1, stats['ok'])
            self.assertEquals(1, stats['total'])
            self.assertEquals(0, stats['unav'])
            self.assertTrue(fs.subtitlesExists(None, extension))

            # Make another request, this time with conversion.
            # Original unconverted file should be reused without having to
            # resort to making a HTTP request
            self.napiScan('--stats', '-s', '-e', extension, '-f', toFormat,
                          media['path'])

            # check the stats again
            stats = self.output.parseNapiStats()
            self.assertEquals(1, stats['skip'])
            self.assertEquals(1, stats['conv'])
            self.assertEquals(0, stats['unav'])

            self.assertTrue(fs.subtitlesExists(None, 'srt'))
            self.assertTrue(fs.subtitlesExists('ORIG'))