Beispiel #1
0
 def test_get_attempt_invalid_package_missing_xml(self):
     """
     There are more than one article registered with same article title
     """
     pkg = self._make_test_archive([('texto.txt', b'bla bla')])
     safe_package = package.SafePackage(pkg.name, '/tmp/')
     self.assertRaises(ValueError, checkin.get_attempt, safe_package)
Beispiel #2
0
 def test_get_attempt_invalid_package_missing_issn_and_article_title(self):
     """
     Package is invalid because there is no ISSN and article_title
     """
     pkg = self._make_test_archive([('texto.xml', b'<root/>')])
     safe_package = package.SafePackage(pkg.name, '/tmp/')
     self.assertRaises(ValueError,
                       lambda: checkin.get_attempt(safe_package))
Beispiel #3
0
    def test_primary_path(self):
        # mocks
        mock_shutil = self.mocker.replace('shutil')
        mock_uuid4 = self.mocker.replace('uuid.uuid4')

        mock_shutil.copy2(mocker.ANY, mocker.ANY)
        self.mocker.result(None)

        mock_uuid4().hex
        self.mocker.result('e7d0213c44ba4ed5adcde9e3fdf62963')

        self.mocker.replay()

        safe_pkg = package.SafePackage(SAMPLE_PACKAGE, '/tmp/')

        self.assertEqual(safe_pkg.primary_path, SAMPLE_PACKAGE)
Beispiel #4
0
    def test_gen_safe_path(self):
        # mocks
        mock_shutil = self.mocker.replace('shutil')
        mock_uuid4 = self.mocker.replace('uuid.uuid4')

        mock_shutil.copy2(mocker.ANY, mocker.ANY)
        self.mocker.result(None)

        mock_uuid4().hex
        self.mocker.result('e7d0213c44ba4ed5adcde9e3fdf62963')
        self.mocker.count(
            2)  # 2 times cause we are calling the function directly.

        self.mocker.replay()

        safe_pkg = package.SafePackage(SAMPLE_PACKAGE, '/tmp/')

        self.assertEqual(safe_pkg._gen_safe_path(),
                         '/tmp/e7d0213c44ba4ed5adcde9e3fdf62963.zip')
Beispiel #5
0
    def test_mark_as_duplicated_not_silenced_by_default(self):
        # mocks
        mock_shutil = self.mocker.replace('shutil')
        mock_uuid4 = self.mocker.replace('uuid.uuid4')
        mock_utils = self.mocker.replace('balaio.utils')

        mock_shutil.copy2(mocker.ANY, mocker.ANY)
        self.mocker.result(None)

        mock_uuid4().hex
        self.mocker.result('e7d0213c44ba4ed5adcde9e3fdf62963')

        mock_utils.mark_as_duplicated(mocker.ANY)
        self.mocker.throw(OSError)

        self.mocker.replay()

        safe_pkg = package.SafePackage(SAMPLE_PACKAGE, '/tmp/')

        self.assertRaises(OSError, lambda: safe_pkg.mark_as_duplicated())
Beispiel #6
0
    def test_mark_as_failed_can_be_silenced(self):
        # mocks
        mock_shutil = self.mocker.replace('shutil')
        mock_uuid4 = self.mocker.replace('uuid.uuid4')
        mock_utils = self.mocker.replace('balaio.utils')

        mock_shutil.copy2(mocker.ANY, mocker.ANY)
        self.mocker.result(None)

        mock_uuid4().hex
        self.mocker.result('e7d0213c44ba4ed5adcde9e3fdf62963')

        mock_utils.mark_as_failed(mocker.ANY)
        self.mocker.throw(OSError)

        self.mocker.replay()

        safe_pkg = package.SafePackage(SAMPLE_PACKAGE, '/tmp/')

        self.assertIsNone(safe_pkg.mark_as_failed(silence=True))
Beispiel #7
0
    def test_analyzer_context(self):
        # mocks
        mock_shutil = self.mocker.replace('shutil')
        mock_uuid4 = self.mocker.replace('uuid.uuid4')
        mock_panalyzer = self.mocker.replace(package.PackageAnalyzer)

        mock_shutil.copy2(mocker.ANY, mocker.ANY)
        self.mocker.result(None)

        mock_uuid4().hex
        self.mocker.result('e7d0213c44ba4ed5adcde9e3fdf62963')

        mock_panalyzer(mocker.ANY)
        self.mocker.result(doubles.PackageAnalyzerStub())

        self.mocker.replay()

        safe_pkg = package.SafePackage(SAMPLE_PACKAGE, '/tmp/')
        with safe_pkg.analyzer as safe_context:
            self.assertEqual(safe_context.checksum,
                             '5a74db5db860f2f8e3c6a5c64acdbf04')