예제 #1
0
    def test_upload_archive_to_bucket(self, mock_upload):
        source = "test"

        test_archive_bucket_path = self.storage_util.get_archive_file_bucket_path(source)
        self.storage_util.upload_archive_to_bucket(source)

        mock_upload.assert_called_with(self.storage_config['bucket'], archives_path.replace("<source>", source),
                                       test_archive_bucket_path)
예제 #2
0
    def test_retrieve_archive_from_local_if_not_exists(self):
        source = "test"
        archive_path = archives_path.replace('<source>', source)

        if os.path.exists(archive_path):
            os.system('rm -rf ' + archive_path)

        self.assertEqual([], self.storage_util.retrieve_archive_from_local(source))
예제 #3
0
    def test_retrieve_archive_from_local_if_exists(self):
        source = "test"
        url = "http://gc/a.mp4"
        archive_path = archives_path.replace('<source>', source)

        if not os.path.exists(archives_base_path):
            os.system('mkdir ' + archives_base_path)
        if not os.path.exists(archives_base_path + source + "/"):
            os.system('mkdir {0}/{1}'.format(archives_base_path, source))
        if not os.path.exists(archive_path):
            os.system('echo ' + url + '>' + archive_path)

        self.assertEqual([url], self.storage_util.retrieve_archive_from_local(source))

        os.system('rm -rf ' + archives_base_path)
예제 #4
0
    def test_retrieve_archive_from_bucket_if_exists(self, mock_download_blob, mock_check_blob):
        mock_check_blob.return_value = True
        if os.path.exists(archives_base_path):
            os.system('rm -rf ' + archives_base_path)
        source = "test"
        language = "tamil"
        archive_bucket_path = self.storage_util.get_archive_file_bucket_path(source, language)

        def side_effect(bucket, source_file, destination):
            os.system("touch {0}".format(destination))

        mock_download_blob.side_effect = side_effect

        self.storage_util.retrieve_archive_from_bucket(source, language)

        self.assertTrue(os.path.exists(archives_base_path))
        self.assertTrue(os.path.exists(archives_base_path + source))
        self.assertTrue(os.path.exists(archives_path.replace("<source>", source)))
        mock_check_blob.assert_called_once_with(self.storage_config['bucket'],
                                                archive_bucket_path)
        mock_download_blob.assert_called_once_with(self.storage_config['bucket'], archive_bucket_path,
                                                   archives_path.replace("<source>", source))
        if os.path.exists(archives_base_path):
            os.system('rm -rf ' + archives_base_path)
예제 #5
0
    def test_retrieve_archive_from_bucket_if_not_exists(self, mock_download_blob, mock_check_blob):
        mock_check_blob.return_value = False
        if os.path.exists(archives_base_path):
            os.system('rm -rf ' + archives_base_path)
        source = "test"
        language = "tamil"
        archive_bucket_path = self.storage_util.get_archive_file_bucket_path(source, language)

        self.storage_util.retrieve_archive_from_bucket(source, language)

        self.assertTrue(os.path.exists(archives_base_path))
        self.assertTrue(os.path.exists(archives_base_path + source))
        self.assertTrue(os.path.exists(archives_path.replace("<source>", source)))
        mock_check_blob.assert_called_once_with(self.storage_config['bucket'],
                                                archive_bucket_path)
        mock_download_blob.assert_not_called()

        os.system('rm -rf ' + archives_base_path)